Meta tables
You can both test whether a table has a meta table and retrieve the said meta table with the int lua_getmetatable (lua_State*, int) function. The first argument to this function is the Lua state it affects, and the second argument is the index of a table on the stack. If the table at the specified index has no meta table, the lua_getmetatable function returns 0 and does not push anything onto the stack. If the table at the specified index does have a meta table, the lua_getmetatable function will return 1 and push the meta table onto the stack.
You can assign a meta table to an existing table with the int lua_setmetatable (lua_State*, int) function. This function takes the Lua state it affects as its first argument, and the index ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access