#include "table.hpp" #include "source.hpp" // Clear the table. Removes metatable and all key-value pairs. LuaDefineGlobalMethod(table_clear) { LuaArg tab; LuaStack LS(L, tab); LS.checktype(tab, LUA_TTABLE); LS.clearmetatable(tab); lua_pushnil(L); while (lua_next(L, tab.index()) != 0) { lua_pop(L, 1); // Pop the old value. lua_pushvalue(L, -1); // Clone the key lua_pushnil(L); // Push the new value. lua_settable(L, tab.index()); } return LS.result(); } LuaDefineGlobalMethod(table_coerce) { if (!lua_istable(L, -1)) { lua_pop(L, 1); lua_newtable(L); } return 1; }