You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The standard Lua architecture enforces key uniqueness in table entries. NodeMCU adds compile-time constant table implementation know as ROTables which can be statically compiled into Lua modules as vector structures and stored in Flash Memory rather than RAM. Because the Lua next() exploits this uniqueness by finding the previous entry and then chaining to the next field, if the ROTable contains duplicated entries then the enumeration algo goes into an infinite loop.
luac.cross also generates a ROTable index to the functions in a compiled LFS, but it currently does not do a uniqueness check on module names.
Proposed Changes
My thought is that we shouldn't try to add runtime detection of duplicate keys, but rather document that keys in declared ROTable must be unique.
luac.cross should also check for repeated module names within an LFS and raise an error on detection of a duplicate, so that module entries are unique.
Possible future issue
At the moment the module name is based on the basename of the lua file name, so for example lua_examples/luaOTA/_init.lua creates the module _init which can be executed by require "_init" or LFS._init(). With the increased use of LFS modules, the chance of name clash increases. Perhaps we need to think about a convention for namespace separation.
The text was updated successfully, but these errors were encountered:
The uniqueness constraint on ROTable keys is, presumably, post-linker? That is, it's fine for two modules to declare "foo" keys so long as the C strings are commoned up in the .rodata section, yes?
Current Behaviour
The standard Lua architecture enforces key uniqueness in table entries. NodeMCU adds compile-time constant table implementation know as ROTables which can be statically compiled into Lua modules as vector structures and stored in Flash Memory rather than RAM. Because the Lua
next()
exploits this uniqueness by finding the previous entry and then chaining to the next field, if the ROTable contains duplicated entries then the enumeration algo goes into an infinite loop.luac.cross
also generates a ROTable index to the functions in a compiled LFS, but it currently does not do a uniqueness check on module names.Proposed Changes
My thought is that we shouldn't try to add runtime detection of duplicate keys, but rather document that keys in declared ROTable must be unique.
luac.cross
should also check for repeated module names within an LFS and raise an error on detection of a duplicate, so that module entries are unique.Possible future issue
At the moment the module name is based on the basename of the lua file name, so for example
lua_examples/luaOTA/_init.lua
creates the module_init
which can be executed byrequire "_init"
orLFS._init()
. With the increased use of LFS modules, the chance of name clash increases. Perhaps we need to think about a convention for namespace separation.The text was updated successfully, but these errors were encountered: