This commit is contained in:
2020-11-15 16:49:42 -05:00
parent a784f12aed
commit f690fb147b
12 changed files with 431 additions and 168 deletions

View File

@@ -2,7 +2,9 @@
// Clear the table. Removes metatable and all key-value pairs.
int lpx_table_clear(lua_State *L) {
const int tab = lua_gettop(L);
LpxArg tab;
LpxStackManager LSM(L, tab);
luaL_checktype(L, tab, LUA_TTABLE);
// Clear the metatable.
@@ -17,10 +19,8 @@ int lpx_table_clear(lua_State *L) {
lua_pushnil(L); // Push the new value.
lua_settable(L, tab);
}
// Remove the arguments and return nothing.
lua_remove(L, tab);
return 0;
return LSM.retval();
}
int lpx_table_coerce(lua_State *L) {
@@ -31,13 +31,7 @@ int lpx_table_coerce(lua_State *L) {
return 1;
}
static const struct luaL_Reg lpx_table_lib [] = {
{"clear", lpx_table_clear},
{"coerce", lpx_table_coerce},
{NULL, NULL} /* sentinel */
};
int luaopen_lpx_table (lua_State *L) {
luaL_openlib(L, "table", lpx_table_lib, 0);
return 1;
void luaopen_lpx_table (lua_State *L) {
LpxStackManager::reg(L, "table", "clear", LpxArgCheck<1, lpx_table_clear>);
LpxStackManager::reg(L, "table", "coerce", LpxArgCheck<1, lpx_table_coerce>);
}