lupa
lupa copied to clipboard
nested dict to lua dictionary
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...
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".
Wait https://github.com/scoder/lupa/pull/208
Is there a way to convert a Lua table with circular references into a Python dictionary?
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.