Get rid of several instances of LuaOldStack
This commit is contained in:
@@ -235,7 +235,7 @@ eng::string LuaCoreStack::classname(LuaSlot tab) const {
|
||||
eng::string result;
|
||||
if ((istable(tab)) && (gettabletype(tab) == LUA_TT_CLASS)) {
|
||||
LuaVar classes, name, dup;
|
||||
LuaOldStack LS(L_, classes, name, dup);
|
||||
LuaExtStack LS(L_, classes, name, dup);
|
||||
// Get the classes table from the registry.
|
||||
LS.rawget(classes, LuaRegistry, "classes");
|
||||
|
||||
@@ -245,9 +245,7 @@ eng::string LuaCoreStack::classname(LuaSlot tab) const {
|
||||
if (LS.isstring(name)) {
|
||||
LS.rawget(dup, classes, name);
|
||||
if (LS.rawequal(dup, tab)) {
|
||||
result = LS.ckstring(name);
|
||||
LS.result();
|
||||
return result;
|
||||
return LS.ckstring(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,9 +253,7 @@ eng::string LuaCoreStack::classname(LuaSlot tab) const {
|
||||
LS.set(name, LuaNil);
|
||||
while (LS.next(classes, name, dup)) {
|
||||
if (LS.rawequal(dup, tab)) {
|
||||
result = LS.ckstring(name);
|
||||
LS.result();
|
||||
return result;
|
||||
return LS.ckstring(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,52 +263,43 @@ eng::string LuaCoreStack::classname(LuaSlot tab) const {
|
||||
eng::string LuaCoreStack::getclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
lua_checkstack(L_, 20);
|
||||
LuaVar globtab, cname;
|
||||
LuaOldStack LS(L_, globtab, cname);
|
||||
LuaExtStack LS(L_, globtab, cname);
|
||||
LS.getglobaltable(globtab);
|
||||
|
||||
if (LS.isstring(classname)) {
|
||||
if (!validclassname(LS.ckstring(classname))) {
|
||||
eng::string err = "invalid class name: " + LS.ckstring(classname);
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
LS.rawget(classtab, globtab, classname);
|
||||
if (!LS.istable(classtab)) {
|
||||
eng::string err = "not a class: " + LS.ckstring(classname);
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
LS.rawget(cname, classtab, "__class");
|
||||
if (!LS.rawequal(cname, classname)) {
|
||||
eng::string err = "not a valid class: " + LS.ckstring(classname);
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
LS.result();
|
||||
return "";
|
||||
} else if (LS.istable(classname)) {
|
||||
LS.rawget(cname, classname, "__class");
|
||||
if (!LS.isstring(cname)) {
|
||||
eng::string err = "table is not a class.";
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
if (!validclassname(LS.ckstring(cname))) {
|
||||
eng::string err = "invalid class name: " + LS.ckstring(cname);
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
LS.rawget(classtab, globtab, cname);
|
||||
if (!LS.rawequal(classtab, classname)) {
|
||||
eng::string err = "not a valid class: " + LS.ckstring(cname);
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
LS.result();
|
||||
return "";
|
||||
} else {
|
||||
eng::string err = "getclass expects a string or a classtab";
|
||||
LS.result();
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -326,9 +313,8 @@ eng::string LuaCoreStack::getclass(LuaSlot tab, std::string_view name) const {
|
||||
}
|
||||
|
||||
void LuaCoreStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
lua_checkstack(L_, 20);
|
||||
LuaVar classes, globtab, cname;
|
||||
LuaOldStack LS(L_, classes, globtab, cname);
|
||||
LuaExtStack LS(L_, classes, globtab, cname);
|
||||
|
||||
// Validate the class name.
|
||||
assert(LS.validclassname(classname));
|
||||
@@ -356,9 +342,6 @@ void LuaCoreStack::makeclass(LuaSlot classtab, LuaSlot classname) const {
|
||||
LS.settabletype(classtab, LUA_TT_CLASS);
|
||||
LS.rawset(classtab, "__class", classname);
|
||||
LS.rawset(classtab, "__index", classtab);
|
||||
|
||||
// Put the stack back.
|
||||
LS.result();
|
||||
}
|
||||
|
||||
void LuaCoreStack::makeclass(LuaSlot tab, std::string_view name) const {
|
||||
@@ -370,7 +353,7 @@ void LuaCoreStack::makeclass(LuaSlot tab, std::string_view name) const {
|
||||
|
||||
void LuaCoreStack::maketan(LuaSlot tab, int64_t id) const {
|
||||
LuaVar tangibles, metatab;
|
||||
LuaOldStack LS(L_, tangibles, metatab);
|
||||
LuaExtStack LS(L_, tangibles, metatab);
|
||||
|
||||
// Try to get the existing tangible.
|
||||
LS.rawget(tangibles, LuaRegistry, "tangibles");
|
||||
@@ -378,7 +361,6 @@ void LuaCoreStack::maketan(LuaSlot tab, int64_t id) const {
|
||||
|
||||
// If we succeeded, return it.
|
||||
if (LS.istable(tab)) {
|
||||
LS.result();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -397,8 +379,6 @@ void LuaCoreStack::maketan(LuaSlot tab, int64_t id) const {
|
||||
|
||||
// Store the database into the tangibles table.
|
||||
LS.rawset(tangibles, id, tab);
|
||||
|
||||
LS.result();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user