Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested dict to lua dictionary #199

Closed
jappoz opened this issue Dec 13, 2021 · 4 comments · Fixed by #208
Closed

nested dict to lua dictionary #199

jappoz opened this issue Dec 13, 2021 · 4 comments · Fixed by #208
Milestone

Comments

@jappoz
Copy link

jappoz commented Dec 13, 2021

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...

@scoder
Copy link
Owner

scoder commented Dec 14, 2021

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

for obj in args:

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

@synodriver
Copy link
Contributor

Wait #208

@kebab-mai-haddi
Copy link

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

@synodriver
Copy link
Contributor

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.

@scoder scoder added this to the 2.1 milestone Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants