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 of a table on the stack as the second. It expects the top of the stack to be the meta table and will pop it off the stack. If it can assign the meta table, the function will return 1. Otherwise, if an error occurs, the function will return 0.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.129.194