lunatic-python
lunatic-python copied to clipboard
pass python dictionary to lua is a userdata format, how to use it?
To use methods in a dict object from lua you need to access it as attributes. The two ways of doing that:
-
use
asattr, for example:local py = require 'python' local dict = py.builtins().dict local d = dict{foo = 1, bar = 2} local d_attr = py.asattr(d) print(d_attr.items()) d.baz = 5 print(d_attr.items()) -
use
python.builtins().getattr():-- continuing from above local getattr = py.builtins().getattr print(getattr(d, 'items')())