-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
LuaRuntime.table_from method #34
Conversation
py_to_lua(self, L, arg) | ||
lua.lua_rawseti(L, -2, i+1) | ||
for obj in args: | ||
if isinstance(obj, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyMapping_Check()
doesn't work as expected in Python 3.x, see http://bugs.python.org/issue5945. I've used isinstance(obj, dict)
- is there a better way to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, good call. Then checking for dicts is ok. It's easy enough to convert a non-dict mapping to a dict.
We could also make it configurable by accepting keyword arguments "mapping_types" and "sequence_types" that would default to dict
and (tuple, list)
respectively, and then do an isinstance() check with them (unless it's None). First check for the sequence types and only failing that, check for the mapping types. That way you can pass None
for any of them to disable the conversion completely, or object
to enable a specific conversion for all types, or any of the ABC classes, or whatever users want to come up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or why not go for ABCs directly? The type check on the each item isn't performance critical - any non-empty sequence or mapping will require way more time to copy than that.
Do you think |
Good idea. Then we should remove the generic support for **kwargs and I also think that the "_LuaTable" wrapper class should get an "update()" |
Python 2.5 doesn't have abc module, and both Python 2.5 and Python 3.1 don't work with recent Cython.
At first I haven't used abc because for some reason I though it is not available in Python 2.6. It is a bit slower with collections.Mapping, maybe because the iteration code is less efficient.
I've removed **kwargs so that we can add |
I have troubles with wrapped Lua tables; |
Ah, yes, I can imaging that it gets the Lua stack corrupted when both https://stackoverflow.com/questions/4535152/cloning-a-lua-table-in-lua-c-api |
I've added support for _LuaTable, but not for _LuaIter. |
There is some protection for _LuaIter, but |
Looks good (enough) to me, I'll merge it. Fixing support for LuaIter requires some cleanup in various places that currently assume that clearing the stack is sufficient when they are done with their work. Instead, they should pop the right number of elements to properly support nesting. |
Thanks for your work. |
Thanks for a great wrapper! Lua C API is quite interesting to learn, I haven't used stack-based language APIs before. |
I've fixed most places but not all of them here: bf1c644 The remaining ones need some thought, especially the function calls, where the number of elements on the stack is the actual number of arguments and keeping things around on the stack will screw it up. |
Great, it seems this made special-casing of _LuaIter unnecessary: #40 |
Implementation of #31.