lupa icon indicating copy to clipboard operation
lupa copied to clipboard

nested dict to lua dictionary

Open jappoz opened this issue 3 years ago • 2 comments

Hello, Is there any way to use table_from method given a nested dictionary to produce the corresponding lua table? What I would like to achieve is something like this:

#python
main_dict = {}
main_dict_core = {}
main_dict_core['A'] = True
main_dict_core['B'] = [{4,6}, {7.7, 8}]
main_dict['MAIN'] = main_dict_core
out_table = lua.table_from(main_dict)

# lua
MAIN = {
  A = true,
  B = {
    {4, 6},
    {7.7, 8}
  },
}

and then convert out_table to string and save it as lua file.

I have seen in #34 that a recursive=True arg could be used but it does not seem to be implemented so far...

jappoz avatar Dec 13 '21 12:12 jappoz

I have seen in #34 that a recursive=True arg could be used but it does not seem to be implemented so far...

Seems worth implementing then. PR welcome.

See https://github.com/scoder/lupa/blob/7fe8768bd2bc3fbba776099a384519a549972cb2/lupa/_lupa.pyx#L430

The tests are in lupa/tests/test.py, Look for "table_from".

scoder avatar Dec 14 '21 11:12 scoder

Wait https://github.com/scoder/lupa/pull/208

synodriver avatar Apr 02 '22 05:04 synodriver

Is there a way to convert a Lua table with circular references into a Python dictionary?

kebab-mai-haddi avatar Mar 01 '23 23:03 kebab-mai-haddi

Is there a way to convert a Lua table with circular references into a Python dictionary?

Detecting circular references data structures is really annoying in this case, we'd better limit the depth in some way.

synodriver avatar Dec 17 '23 06:12 synodriver