lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


lua_gettable looks up the __index metamethod or table when t is not a table or t is missing the property. It can be compared to writing ("")["sub"] in lua. Strings are not tables, however, they have a metatable with the "sub" function.

Am 17.02.2022 um 10:43 schrieb Flyer31 Test:
What do you mean by this? lua_gettable returns t[k] - how can t be NOT
a table in this case?

(sorry, I am newbe to Lua, I hope not too stupid question).

On Thu, Feb 17, 2022 at 9:01 AM Xmilia Hermit <xmilia.hermit@gmail.com> wrote:
The Lua C API functions lua_rawget and lua_rawset expect a table which
is used without any runtime check (except an API check)
(https://github.com/lua/lua/blob/5d708c3f9cae12820e415d4f89c9eacbe2ab964b/lapi.c#L736).
However, the manual
(https://www.lua.org/manual/5.4/manual.html#lua_rawget) states for these
functions that they are similar to lua_gettable which is not restricted
to tables.
Since this seems not very clear
(https://github.com/LuaJIT/LuaJIT/issues/810) it would be nice if the
manual would make it clear for these two functions that tables are expected.

Regards,
Xmilia