At this point, most functions have been LuaStack refactored

This commit is contained in:
2023-04-07 14:20:45 -04:00
parent 44c5a56172
commit 4f0713c9cb
9 changed files with 240 additions and 161 deletions

View File

@@ -7,7 +7,7 @@
static void tangible_getall(LuaCoreStack &LS0, LuaSlot list, const util::IdVector &idv) {
LuaVar tangibles, tan;
LuaOldStack LS(LS0.state(), tangibles, tan);
LuaExtStack LS(LS0.state(), tangibles, tan);
LS.rawget(tangibles, LuaRegistry, "tangibles");
assert(LS.istable(tangibles));
LS.set(list, LuaNewTable);
@@ -17,7 +17,6 @@ static void tangible_getall(LuaCoreStack &LS0, LuaSlot list, const util::IdVecto
assert(LS.istable(tan));
LS.rawset(list, index++, tan);
}
LS.result();
}
LuaDefine(tangible_animstate, "tan",
@@ -25,7 +24,7 @@ LuaDefine(tangible_animstate, "tan",
"|Returns six values: graphic,plane,x,y,z,facing.") {
LuaArg tanobj;
LuaRet graphic, plane, x, y, z, facing;
LuaOldStack LS(L, tanobj, graphic, plane, x, y, z, facing);
LuaDefStack LS(L, tanobj, graphic, plane, x, y, z, facing);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, false);
const AnimStep &aqback = tan->anim_queue_.back();
@@ -43,7 +42,7 @@ LuaDefine(tangible_xyz, "tan",
"|Returns three values: x, y, z") {
LuaArg tanobj;
LuaRet x, y, z;
LuaOldStack LS(L, tanobj, x, y, z);
LuaDefStack LS(L, tanobj, x, y, z);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, false);
const AnimStep &aqback = tan->anim_queue_.back();
@@ -58,7 +57,7 @@ LuaDefine(tangible_animate, "tan,configtable",
"|The configtable is a table containing any of the following:"
"|action,graphic,plane,x,y,z,facing") {
LuaArg tanobj, config;
LuaOldStack LS(L, tanobj, config);
LuaDefStack LS(L, tanobj, config);
LuaKeywordParser kp(LS, config);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, false);
@@ -81,7 +80,7 @@ LuaDefine(tangible_setclass, "tan,class",
"|given an __index metamethod that points at the class table.") {
LuaArg tanobj, classname;
LuaVar classtab, mt;
LuaOldStack LS(L, tanobj, classname, classtab, mt);
LuaDefStack LS(L, tanobj, classname, classtab, mt);
World *w = World::fetch_global_pointer(L);
w->tangible_get(LS, tanobj, false);
eng::string err = LS.getclass(classtab, classname);
@@ -100,7 +99,7 @@ LuaDefine(tangible_getclass, "tan",
LuaArg tanobj;
LuaVar mt, classtab;
LuaRet classname;
LuaOldStack LS(L, tanobj, mt, classtab, classname);
LuaDefStack LS(L, tanobj, mt, classtab, classname);
World *w = World::fetch_global_pointer(L);
w->tangible_get(LS, tanobj, false);
LS.getmetatable(mt, tanobj);
@@ -119,7 +118,7 @@ LuaDefine(tangible_delete, "tan",
"|This cannot be used to delete player tangibles,"
"|To delete a player, use tangible.redirect") {
LuaArg tanobj;
LuaOldStack LS(L, tanobj);
LuaDefStack LS(L, tanobj);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, true);
if (tan == nullptr) {
@@ -140,7 +139,7 @@ LuaDefine(tangible_build, "config",
LuaArg config;
LuaVar classname, classtab, mt;
LuaRet database;
LuaOldStack LS(L, config, classname, classtab, database, mt);
LuaDefStack LS(L, config, classname, classtab, database, mt);
LuaKeywordParser kp(LS, config);
// Get the class of the new tangible.
@@ -192,7 +191,7 @@ LuaDefine(tangible_get, "id",
LuaArg id;
LuaVar tangibles;
LuaRet database;
LuaOldStack LS(L, id, tangibles, database);
LuaDefStack LS(L, id, tangibles, database);
int64_t nid = LS.ckinteger(id);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(database, tangibles, id);
@@ -205,7 +204,7 @@ LuaDefine(tangible_get, "id",
LuaDefine(tangible_redirect, "tan1,tan2,bulldozetan1",
"|Redirect is not working yet") {
LuaArg actor1, actor2, bldz;
LuaOldStack LS(L, actor1, actor2, bldz);
LuaDefStack LS(L, actor1, actor2, bldz);
World *w = World::fetch_global_pointer(L);
bool bulldoze = LS.ckboolean(bldz);
Tangible *tan1 = w->tangible_get(LS, actor1, false);
@@ -231,7 +230,7 @@ LuaDefine(tangible_id, "tan",
"|in the released version.") {
LuaArg tanobj;
LuaRet id;
LuaOldStack LS(L, tanobj, id);
LuaDefStack LS(L, tanobj, id);
int64_t tid = LS.tanid(tanobj);
if (tid == 0) {
luaL_error(L, "Not a tangible");
@@ -244,7 +243,7 @@ LuaDefine(tangible_actor, "",
"|Return the current actor.") {
LuaRet actor;
LuaVar tangibles;
LuaOldStack LS(L, tangibles, actor);
LuaDefStack LS(L, tangibles, actor);
World *w = World::fetch_global_pointer(L);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(actor, tangibles, w->lthread_actor_id_);
@@ -255,7 +254,7 @@ LuaDefine(tangible_place, "",
"|Return the current place.") {
LuaRet place;
LuaVar tangibles;
LuaOldStack LS(L, tangibles, place);
LuaDefStack LS(L, tangibles, place);
World *w = World::fetch_global_pointer(L);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, w->lthread_place_id_);
@@ -269,7 +268,7 @@ LuaDefine(tangible_near, "tan,radius,omit_nowhere,omit_self",
"|tangible passed in is omitted from the results.") {
LuaArg ltan, lradius, lomit_nowhere, lomit_self;
LuaRet list;
LuaOldStack LS(L, ltan, lradius, lomit_nowhere, lomit_self, list);
LuaDefStack LS(L, ltan, lradius, lomit_nowhere, lomit_self, list);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, ltan, false);
const AnimStep &aqback = tan->anim_queue_.back();
@@ -293,7 +292,7 @@ LuaDefine(tangible_scan, "plane,x,y,radius,omit_nowhere",
"|the scan returns empty.") {
LuaArg lplane, lx, ly, lradius, lomit_nowhere;
LuaRet list;
LuaOldStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list);
LuaDefStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list);
World *w = World::fetch_global_pointer(L);
PlaneScan scan;
@@ -367,7 +366,7 @@ LuaDefine(tangible_find, "config",
"|") {
LuaArg config;
LuaRet result;
LuaOldStack LS(L, config, result);
LuaDefStack LS(L, config, result);
LuaKeywordParser kw(LS, config);
PlaneScan scan;
scan.configure(kw);
@@ -446,7 +445,7 @@ LuaDefine(tangible_start, "tangible,function,arg1,arg2...",
w->guard_blockable(L, "tangible.start");
LuaVar mt, classtab, plthreads, thread, thinfo, func, tanlist;
LuaOldStack LS(L, mt, classtab, plthreads, thread, thinfo, func, tanlist);
LuaDefStack LS(L, mt, classtab, plthreads, thread, thinfo, func, tanlist);
LuaSpecial place(1);
LuaSpecial fname(2);
@@ -537,7 +536,7 @@ LuaDefine(wait, "nticks",
// Parse the argument.
LuaArg seconds;
LuaOldStack LS(L, seconds);
LuaDefStack LS(L, seconds);
int64_t n = LS.ckinteger(seconds);
if ((n < 0) || (n > 1000000)) {
luaL_error(L, "Argument to wait must be between 0 and 1000000");
@@ -603,7 +602,7 @@ LuaDefine(math_random, "(args...)",
highf = std::floor(lua_tonumber(L, arg));
arg += 1;
}
if ((lowf < -LuaOldStack::MAXINT) || (highf > LuaOldStack::MAXINT)) {
if ((lowf < -LuaCoreStack::MAXINT) || (highf > LuaCoreStack::MAXINT)) {
luaL_error(L, "math.random range exceeds MAXINT");
return 0;
}
@@ -636,8 +635,8 @@ LuaDefine(math_random, "(args...)",
}
double dseed = lua_tonumber(L, -2);
double dcount = lua_tonumber(L, -1);
seed = uint64_t(dseed) & LuaOldStack::MAXINT;
count = uint64_t(dcount) & LuaOldStack::MAXINT;
seed = uint64_t(dseed) & LuaCoreStack::MAXINT;
count = uint64_t(dcount) & LuaCoreStack::MAXINT;
if (dseed < 0) {
salt = 0x35c9a6082a097ade;
} else {
@@ -645,7 +644,7 @@ LuaDefine(math_random, "(args...)",
}
lua_pop(L, 2);
lua_pushstring(L, "count");
lua_pushnumber(L, double((count + 1) & LuaOldStack::MAXINT));
lua_pushnumber(L, double((count + 1) & LuaCoreStack::MAXINT));
lua_rawset(L, 1);
} else {
World *w = World::fetch_global_pointer(L);
@@ -692,7 +691,7 @@ LuaDefine(math_randomstate, "seed",
double seed;
if (lua_gettop(L) == 0) {
World *w = World::fetch_global_pointer(L);
int64_t iseed = (w->id_global_pool_.get_seqno() & LuaOldStack::MAXINT) + 1;
int64_t iseed = (w->id_global_pool_.get_seqno() & LuaCoreStack::MAXINT) + 1;
seed = -iseed;
} else if (lua_gettop(L) == 1) {
if (lua_type(L, 1) != LUA_TNUMBER) {
@@ -700,7 +699,7 @@ LuaDefine(math_randomstate, "seed",
return 0;
}
seed = lua_tonumber(L, 1);
if ((seed < 0.0) || (seed > LuaOldStack::MAXINT) || (std::floor(seed) != seed)) {
if ((seed < 0.0) || (seed > LuaCoreStack::MAXINT) || (std::floor(seed) != seed)) {
luaL_error(L, "math.randomstate seed must be an integer 0-MAXINT");
return 0;
}
@@ -732,7 +731,7 @@ LuaDefine(pprint, "obj1, obj2, ...",
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
int n = lua_gettop(L);
LuaOldStack LS(L);
LuaDefStack LS(L);
for (int i = 1; i <= n; i++) {
LuaSpecial root(i);
pprint(LS, root, PrettyPrintOptions(), ostream);
@@ -763,7 +762,7 @@ LuaDefine(pprintx, "options",
std::ostream *ostream = w->lthread_print_stream();
LuaArg loptions;
LuaVar value;
LuaOldStack LS(L, loptions, value);
LuaDefStack LS(L, loptions, value);
PrettyPrintOptions options;
LuaKeywordParser kp(LS, loptions);
options.parse(kp);
@@ -779,7 +778,7 @@ LuaDefine(print, "obj1, obj2, ...",
"|Print object or objects.") {
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
LuaOldStack LS(L);
LuaCoreStack LS(L);
int n = lua_gettop(L);
for (int i = 1; i <= n; i++) {
LuaSpecial root(i);
@@ -787,7 +786,7 @@ LuaDefine(print, "obj1, obj2, ...",
if (i < n) (*ostream) << " ";
}
(*ostream) << std::endl;
return LS.result();
return 0;
}
LuaDefine(doc, "function",
@@ -795,7 +794,7 @@ LuaDefine(doc, "function",
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
LuaArg func;
LuaOldStack LS(L, func);
LuaDefStack LS(L, func);
eng::string doc = SourceDB::function_docs(LS, func);
if (doc == "") {
(*ostream) << "no doc found" << std::endl;
@@ -936,7 +935,7 @@ LuaDefine(global_set, "varname, value",
"|") {
LuaArg varname;
LuaArg value;
LuaOldStack LS(L, varname, value);
LuaDefStack LS(L, varname, value);
// Check the varname argument.
eng::string gvar = LS.ckstring(varname);
@@ -961,7 +960,7 @@ LuaDefine(global_get, "varname",
LuaArg varname;
LuaRet value;
LuaVar globaldb;
LuaOldStack LS(L, varname, value, globaldb);
LuaDefStack LS(L, varname, value, globaldb);
LS.rawget(globaldb, LuaRegistry, "globaldb");
LS.rawget(value, globaldb, varname);
return LS.result();
@@ -977,7 +976,7 @@ LuaDefine(global_once, "varname",
LuaArg varname;
LuaRet result;
LuaVar globaldb, flag;
LuaOldStack LS(L, varname, flag, result, globaldb);
LuaDefStack LS(L, varname, flag, result, globaldb);
// Check the varname argument.
eng::string gvar = LS.ckstring(varname);
@@ -1009,7 +1008,7 @@ LuaDefine(global_clearonce, "varname",
"|") {
LuaArg varname;
LuaVar null;
LuaOldStack LS(L, varname, null);
LuaDefStack LS(L, varname, null);
// Check the varname argument.
eng::string gvar = LS.ckstring(varname);