More work on console I/O and minor fixes

This commit is contained in:
2021-10-25 14:47:37 -04:00
parent b5d62d3991
commit 9a02f408b0
13 changed files with 122 additions and 78 deletions

View File

@@ -128,14 +128,23 @@ LuaDefine(table_count, "c") {
return 1;
}
void table_clear(LuaStack &LS0, LuaSlot table) {
LS0.cleartable(table);
}
LuaDefine(table_clear, "c") {
LuaArg tab;
LuaStack LS(L, tab);
table_clear(LS, tab);
LuaArg tab, clearmeta;
LuaVar metatable, metafield;
LuaStack LS(L, tab, clearmeta, metatable, metafield);
if (LS.ckboolean(clearmeta)) {
LS.getmetatable(metatable, tab);
if (LS.istable(metatable)) {
LS.rawget(metafield, metatable, "__metatable");
if (!LS.isnil(metafield)) {
luaL_error(L, "Cannot clear metatable.");
return LS.result();
}
}
LS.cleartable(tab, true);
} else {
LS.cleartable(tab, false);
}
return LS.result();
}