Start refactoring LuaStack

This commit is contained in:
2023-04-07 12:58:05 -04:00
parent 7f000bc0fd
commit 44c5a56172
6 changed files with 52 additions and 53 deletions

View File

@@ -33,7 +33,7 @@ bool table_equal(LuaCoreStack &LS, LuaSlot t1, LuaSlot t2) {
LuaDefine(table_equal, "table1,table2", "return true if two tables contain the same keys and values") {
LuaArg t1, t2;
LuaRet eql;
LuaOldStack LS(L, t1, t2, eql);
LuaDefStack LS(L, t1, t2, eql);
LS.set(eql, table_equal(LS, t1, t2));
return LS.result();
}
@@ -121,7 +121,7 @@ LuaDefine(table_count, "table", "return the number of keys in table") {
LuaDefine(table_clear, "table,metaflag", "clear all keys, and optionally the metatable") {
LuaArg tab, clearmeta;
LuaVar metatable, metafield;
LuaOldStack LS(L, tab, clearmeta, metatable, metafield);
LuaDefStack LS(L, tab, clearmeta, metatable, metafield);
LS.checktable(tab, "table");
if (LS.ckboolean(clearmeta)) {
LS.getmetatable(metatable, tab);
@@ -142,7 +142,7 @@ LuaDefine(table_clear, "table,metaflag", "clear all keys, and optionally the met
LuaDefine(table_getflagbits, "table", "get the table's flag bits (debugging only)") {
LuaArg tab;
LuaRet bits;
LuaOldStack LS(L, tab, bits);
LuaDefStack LS(L, tab, bits);
uint16_t ubits = lua_getflagbits(L, tab.index());
LS.set(bits, ubits);
return LS.result();
@@ -150,7 +150,7 @@ LuaDefine(table_getflagbits, "table", "get the table's flag bits (debugging only
LuaDefine(table_setflagbits, "table,bits", "set the table's flag bits (debugging only)") {
LuaArg tab, bits;
LuaOldStack LS(L, tab, bits);
LuaDefStack LS(L, tab, bits);
uint16_t ubits = LS.ckinteger(bits);
lua_setflagbits(L, tab.index(), ubits);
return LS.result();
@@ -232,7 +232,7 @@ int deque_make_room(lua_State *L, int deque, int left, int fill, int max) {
LuaDefine(deque_create, "", "create a deque") {
LuaRet rdeque;
LuaVar classobj;
LuaOldStack LS(L, rdeque, classobj);
LuaDefStack LS(L, rdeque, classobj);
const int imax = 4;
eng::string err = LS.getclass(classobj, "deque");
if (err != "") {
@@ -251,7 +251,7 @@ LuaDefine(deque_create, "", "create a deque") {
LuaDefine(deque_pushl, "deque,value", "push onto the left end of a deque") {
LuaArg deque, elt;
LuaOldStack LS(L, deque, elt);
LuaDefStack LS(L, deque, elt);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
max = deque_make_room(L, deque.index(), left, fill, max);
@@ -265,7 +265,7 @@ LuaDefine(deque_pushl, "deque,value", "push onto the left end of a deque") {
LuaDefine(deque_pushr, "deque,value", "push onto the right end of a deque") {
LuaArg deque, elt;
LuaOldStack LS(L, deque, elt);
LuaDefStack LS(L, deque, elt);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
max = deque_make_room(L, deque.index(), left, fill, max);
@@ -279,7 +279,7 @@ LuaDefine(deque_pushr, "deque,value", "push onto the right end of a deque") {
LuaDefine(deque_popl, "deque", "pop the left end of a deque") {
LuaArg deque;
LuaRet result;
LuaOldStack LS(L, deque, result);
LuaDefStack LS(L, deque, result);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
if (fill == 0) {
@@ -297,7 +297,7 @@ LuaDefine(deque_popl, "deque", "pop the left end of a deque") {
LuaDefine(deque_popr, "deque", "pop the right end of a deque") {
LuaArg deque;
LuaRet result;
LuaOldStack LS(L, deque, result);
LuaDefStack LS(L, deque, result);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
if (fill == 0) {
@@ -315,7 +315,7 @@ LuaDefine(deque_popr, "deque", "pop the right end of a deque") {
LuaDefine(deque_nthl, "deque,n", "return the nth item from the left end of a deque") {
LuaArg deque, nn;
LuaRet result;
LuaOldStack LS(L, deque, nn, result);
LuaDefStack LS(L, deque, nn, result);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
int n = LS.ckint(nn);
@@ -331,7 +331,7 @@ LuaDefine(deque_nthl, "deque,n", "return the nth item from the left end of a deq
LuaDefine(deque_nthr, "deque,n", "return the nth item from the right end of a deque") {
LuaArg deque, nn;
LuaRet result;
LuaOldStack LS(L, deque, nn, result);
LuaDefStack LS(L, deque, nn, result);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
int n = LS.ckint(nn);
@@ -346,7 +346,7 @@ LuaDefine(deque_nthr, "deque,n", "return the nth item from the right end of a de
LuaDefine(deque_setl, "deque,n,value", "set the nth item from the left end of a deque") {
LuaArg deque, nn, val;
LuaOldStack LS(L, deque, nn, val);
LuaDefStack LS(L, deque, nn, val);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
int n = LS.ckint(nn);
@@ -361,7 +361,7 @@ LuaDefine(deque_setl, "deque,n,value", "set the nth item from the left end of a
LuaDefine(deque_setr, "deque,n,value", "set the nth item from the right end of a deque") {
LuaArg deque, nn, val;
LuaOldStack LS(L, deque, nn, val);
LuaDefStack LS(L, deque, nn, val);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
int n = LS.ckint(nn);
@@ -378,7 +378,7 @@ LuaDefine(deque_findl, "deque,value", "find the first occurence of value in dequ
LuaArg deque, val;
LuaRet pos;
LuaVar check;
LuaOldStack LS(L, deque, val, pos, check);
LuaDefStack LS(L, deque, val, pos, check);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
for (int i = 0; i < fill; i++) {
@@ -397,7 +397,7 @@ LuaDefine(deque_findr, "deque,value", "find the first occurrence of value in deq
LuaArg deque, val;
LuaRet pos;
LuaVar check;
LuaOldStack LS(L, deque, val, pos, check);
LuaDefStack LS(L, deque, val, pos, check);
int left, fill, max;
deque_get_info(L, deque.index(), &left, &fill, &max);
int base = left + fill - 1;
@@ -416,7 +416,7 @@ LuaDefine(deque_findr, "deque,value", "find the first occurrence of value in deq
LuaDefine(deque_size, "deque", "return the number of items in the deque") {
LuaArg deque;
LuaRet size;
LuaOldStack LS(L, deque, size);
LuaDefStack LS(L, deque, size);
LS.checktable(deque, "deque");
LS.rawget(size, deque, DEQUE_FILL);
LS.checknumber(size, "deque size");
@@ -537,7 +537,7 @@ static void auxsort (lua_State *L, int tab, int l, int u) {
bool table_getpairs(LuaCoreStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort) {
lua_State *L = LS0.state();
LuaVar key, value;
LuaOldStack LS(L, key, value);
LuaExtStack LS(L, key, value);
bool sorted = true;
// Create the table, store the initial 1.
int total = lua_nkeys(L, tab.index());
@@ -558,7 +558,6 @@ bool table_getpairs(LuaCoreStack &LS0, LuaSlot tab, LuaSlot pairs, bool sort) {
if (sort) {
auxsort(L, pairs.index(), 1, total);
}
LS.result();
return sorted;
}
@@ -602,7 +601,7 @@ LuaDefine(table_sortedpairs, "table",
"|") {
LuaArg tab;
LuaRet closure, rtab, key;
LuaOldStack LS(L, tab, closure, rtab, key);
LuaDefStack LS(L, tab, closure, rtab, key);
bool sorted = table_getpairs(LS, tab, rtab, true);
if (!sorted) {
luaL_error(L, "Cannot sort the table keys");
@@ -625,7 +624,7 @@ LuaDefine(table_semisortedpairs, "table",
"|") {
LuaArg tab;
LuaRet closure, rtab, key;
LuaOldStack LS(L, tab, closure, rtab, key);
LuaDefStack LS(L, tab, closure, rtab, key);
table_getpairs(LS, tab, rtab, true);
LS.set(closure, lfn_table_nextsortedpair);
LS.set(key, LuaNil);
@@ -665,7 +664,7 @@ LuaDefine(genlt, "obj1,obj2",
"|") {
LuaArg o1,o2;
LuaRet lt;
LuaOldStack LS(L, o1, o2, lt);
LuaDefStack LS(L, o1, o2, lt);
int ltf = lua_genlt(L, o1.index(), o2.index());
LS.set(lt, ltf ? true:false);
return LS.result();