Closed marcelvanherk closed 7 years ago
The index vs attrib access could definitely use some refinement. You can take this further and just check that lua_type(L, 2) != LUA_TSTRING
. Since attributes are always strings in python, trying to do attribute access on a non-string key is nonsensical.
Hi, not sure that lua_type(L, 2) != LUA_TSTRING would help much over lua_isnumber; since apart from string and number, we do have some valid table indexes in lua such as function or userdata, but they are very rarely used I believe. But either modification would do.
Marcel
Yes, this change is just to make it a little more general. Someone else down the line might want to use esoteric lua types as keys and since we're changing this anyway might as well support it.
Like this does not work:
if (obj->asindx || !lua_isstring(L, 2))
Kept it as
if (obj->asindx || lua_isnumber(L, 2))
lua_isstring(L, 2)
does implicit conversion from a number to a string before performing the check. This is why I used lua_type
instead so this doesn't happen.
OK, fixed
Hi,
in this sample:
a[0]
is not defined. It only becomes defined after you sayI would there like to suggest the following change:
and
This would force every numerical access to be seen as an index access, which simplifies numpy data access from Lua a lot. Does that sound like a good idea?
Marcel