Added two new stack disciplines to LuaStack

This commit is contained in:
2023-04-06 20:12:03 -04:00
parent b8df2bbc89
commit 7f000bc0fd
26 changed files with 401 additions and 271 deletions

View File

@@ -5,9 +5,9 @@
#include <cmath>
#include <iostream>
static void tangible_getall(LuaStack &LS0, LuaSlot list, const util::IdVector &idv) {
static void tangible_getall(LuaCoreStack &LS0, LuaSlot list, const util::IdVector &idv) {
LuaVar tangibles, tan;
LuaStack LS(LS0.state(), tangibles, tan);
LuaOldStack LS(LS0.state(), tangibles, tan);
LS.rawget(tangibles, LuaRegistry, "tangibles");
assert(LS.istable(tangibles));
LS.set(list, LuaNewTable);
@@ -25,7 +25,7 @@ LuaDefine(tangible_animstate, "tan",
"|Returns six values: graphic,plane,x,y,z,facing.") {
LuaArg tanobj;
LuaRet graphic, plane, x, y, z, facing;
LuaStack LS(L, tanobj, graphic, plane, x, y, z, facing);
LuaOldStack 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 +43,7 @@ LuaDefine(tangible_xyz, "tan",
"|Returns three values: x, y, z") {
LuaArg tanobj;
LuaRet x, y, z;
LuaStack LS(L, tanobj, x, y, z);
LuaOldStack 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 +58,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;
LuaStack LS(L, tanobj, config);
LuaOldStack 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 +81,7 @@ LuaDefine(tangible_setclass, "tan,class",
"|given an __index metamethod that points at the class table.") {
LuaArg tanobj, classname;
LuaVar classtab, mt;
LuaStack LS(L, tanobj, classname, classtab, mt);
LuaOldStack 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 +100,7 @@ LuaDefine(tangible_getclass, "tan",
LuaArg tanobj;
LuaVar mt, classtab;
LuaRet classname;
LuaStack LS(L, tanobj, mt, classtab, classname);
LuaOldStack 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 +119,7 @@ LuaDefine(tangible_delete, "tan",
"|This cannot be used to delete player tangibles,"
"|To delete a player, use tangible.redirect") {
LuaArg tanobj;
LuaStack LS(L, tanobj);
LuaOldStack LS(L, tanobj);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj, true);
if (tan == nullptr) {
@@ -140,7 +140,7 @@ LuaDefine(tangible_build, "config",
LuaArg config;
LuaVar classname, classtab, mt;
LuaRet database;
LuaStack LS(L, config, classname, classtab, database, mt);
LuaOldStack LS(L, config, classname, classtab, database, mt);
LuaKeywordParser kp(LS, config);
// Get the class of the new tangible.
@@ -192,7 +192,7 @@ LuaDefine(tangible_get, "id",
LuaArg id;
LuaVar tangibles;
LuaRet database;
LuaStack LS(L, id, tangibles, database);
LuaOldStack LS(L, id, tangibles, database);
int64_t nid = LS.ckinteger(id);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(database, tangibles, id);
@@ -205,7 +205,7 @@ LuaDefine(tangible_get, "id",
LuaDefine(tangible_redirect, "tan1,tan2,bulldozetan1",
"|Redirect is not working yet") {
LuaArg actor1, actor2, bldz;
LuaStack LS(L, actor1, actor2, bldz);
LuaOldStack 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 +231,7 @@ LuaDefine(tangible_id, "tan",
"|in the released version.") {
LuaArg tanobj;
LuaRet id;
LuaStack LS(L, tanobj, id);
LuaOldStack LS(L, tanobj, id);
int64_t tid = LS.tanid(tanobj);
if (tid == 0) {
luaL_error(L, "Not a tangible");
@@ -244,7 +244,7 @@ LuaDefine(tangible_actor, "",
"|Return the current actor.") {
LuaRet actor;
LuaVar tangibles;
LuaStack LS(L, tangibles, actor);
LuaOldStack 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 +255,7 @@ LuaDefine(tangible_place, "",
"|Return the current place.") {
LuaRet place;
LuaVar tangibles;
LuaStack LS(L, tangibles, place);
LuaOldStack 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 +269,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;
LuaStack LS(L, ltan, lradius, lomit_nowhere, lomit_self, list);
LuaOldStack 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 +293,7 @@ LuaDefine(tangible_scan, "plane,x,y,radius,omit_nowhere",
"|the scan returns empty.") {
LuaArg lplane, lx, ly, lradius, lomit_nowhere;
LuaRet list;
LuaStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list);
LuaOldStack LS(L, lplane, lx, ly, lradius, lomit_nowhere, list);
World *w = World::fetch_global_pointer(L);
PlaneScan scan;
@@ -367,7 +367,7 @@ LuaDefine(tangible_find, "config",
"|") {
LuaArg config;
LuaRet result;
LuaStack LS(L, config, result);
LuaOldStack LS(L, config, result);
LuaKeywordParser kw(LS, config);
PlaneScan scan;
scan.configure(kw);
@@ -446,7 +446,7 @@ LuaDefine(tangible_start, "tangible,function,arg1,arg2...",
w->guard_blockable(L, "tangible.start");
LuaVar mt, classtab, plthreads, thread, thinfo, func, tanlist;
LuaStack LS(L, mt, classtab, plthreads, thread, thinfo, func, tanlist);
LuaOldStack LS(L, mt, classtab, plthreads, thread, thinfo, func, tanlist);
LuaSpecial place(1);
LuaSpecial fname(2);
@@ -537,7 +537,7 @@ LuaDefine(wait, "nticks",
// Parse the argument.
LuaArg seconds;
LuaStack LS(L, seconds);
LuaOldStack 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 +603,7 @@ LuaDefine(math_random, "(args...)",
highf = std::floor(lua_tonumber(L, arg));
arg += 1;
}
if ((lowf < -LuaStack::MAXINT) || (highf > LuaStack::MAXINT)) {
if ((lowf < -LuaOldStack::MAXINT) || (highf > LuaOldStack::MAXINT)) {
luaL_error(L, "math.random range exceeds MAXINT");
return 0;
}
@@ -636,8 +636,8 @@ LuaDefine(math_random, "(args...)",
}
double dseed = lua_tonumber(L, -2);
double dcount = lua_tonumber(L, -1);
seed = uint64_t(dseed) & LuaStack::MAXINT;
count = uint64_t(dcount) & LuaStack::MAXINT;
seed = uint64_t(dseed) & LuaOldStack::MAXINT;
count = uint64_t(dcount) & LuaOldStack::MAXINT;
if (dseed < 0) {
salt = 0x35c9a6082a097ade;
} else {
@@ -645,7 +645,7 @@ LuaDefine(math_random, "(args...)",
}
lua_pop(L, 2);
lua_pushstring(L, "count");
lua_pushnumber(L, double((count + 1) & LuaStack::MAXINT));
lua_pushnumber(L, double((count + 1) & LuaOldStack::MAXINT));
lua_rawset(L, 1);
} else {
World *w = World::fetch_global_pointer(L);
@@ -692,7 +692,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() & LuaStack::MAXINT) + 1;
int64_t iseed = (w->id_global_pool_.get_seqno() & LuaOldStack::MAXINT) + 1;
seed = -iseed;
} else if (lua_gettop(L) == 1) {
if (lua_type(L, 1) != LUA_TNUMBER) {
@@ -700,7 +700,7 @@ LuaDefine(math_randomstate, "seed",
return 0;
}
seed = lua_tonumber(L, 1);
if ((seed < 0.0) || (seed > LuaStack::MAXINT) || (std::floor(seed) != seed)) {
if ((seed < 0.0) || (seed > LuaOldStack::MAXINT) || (std::floor(seed) != seed)) {
luaL_error(L, "math.randomstate seed must be an integer 0-MAXINT");
return 0;
}
@@ -732,7 +732,7 @@ LuaDefine(pprint, "obj1, obj2, ...",
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
int n = lua_gettop(L);
LuaStack LS(L);
LuaOldStack LS(L);
for (int i = 1; i <= n; i++) {
LuaSpecial root(i);
pprint(LS, root, PrettyPrintOptions(), ostream);
@@ -763,7 +763,7 @@ LuaDefine(pprintx, "options",
std::ostream *ostream = w->lthread_print_stream();
LuaArg loptions;
LuaVar value;
LuaStack LS(L, loptions, value);
LuaOldStack LS(L, loptions, value);
PrettyPrintOptions options;
LuaKeywordParser kp(LS, loptions);
options.parse(kp);
@@ -779,7 +779,7 @@ LuaDefine(print, "obj1, obj2, ...",
"|Print object or objects.") {
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
LuaStack LS(L);
LuaOldStack LS(L);
int n = lua_gettop(L);
for (int i = 1; i <= n; i++) {
LuaSpecial root(i);
@@ -795,7 +795,7 @@ LuaDefine(doc, "function",
World *w = World::fetch_global_pointer(L);
std::ostream *ostream = w->lthread_print_stream();
LuaArg func;
LuaStack LS(L, func);
LuaOldStack LS(L, func);
eng::string doc = SourceDB::function_docs(LS, func);
if (doc == "") {
(*ostream) << "no doc found" << std::endl;
@@ -810,7 +810,7 @@ int lfn_http_request(lua_State *L, const char *method) {
LuaArg request;
LuaRet response;
LuaStack LS(L, request, response);
LuaOldStack LS(L, request, response);
LuaKeywordParser kp(LS, request);
HttpClientRequest req;
@@ -856,11 +856,11 @@ LuaDefine(http_post, "request",
return lfn_http_request(L, "POST");
}
void global_set(LuaStack &LS0, const eng::string &gvar, LuaSlot value) {
void global_set(LuaCoreStack &LS0, const eng::string &gvar, LuaSlot value) {
lua_State *L = LS0.state();
World *w = World::fetch_global_pointer(L);
LuaVar globaldb, copy;
LuaStack LS(L, globaldb, copy);
LuaOldStack LS(L, globaldb, copy);
// Serialize then deserialize the data, to produce a copy.
StreamBuffer sb;
@@ -936,7 +936,7 @@ LuaDefine(global_set, "varname, value",
"|") {
LuaArg varname;
LuaArg value;
LuaStack LS(L, varname, value);
LuaOldStack LS(L, varname, value);
// Check the varname argument.
eng::string gvar = LS.ckstring(varname);
@@ -961,7 +961,7 @@ LuaDefine(global_get, "varname",
LuaArg varname;
LuaRet value;
LuaVar globaldb;
LuaStack LS(L, varname, value, globaldb);
LuaOldStack LS(L, varname, value, globaldb);
LS.rawget(globaldb, LuaRegistry, "globaldb");
LS.rawget(value, globaldb, varname);
return LS.result();
@@ -977,7 +977,7 @@ LuaDefine(global_once, "varname",
LuaArg varname;
LuaRet result;
LuaVar globaldb, flag;
LuaStack LS(L, varname, flag, result, globaldb);
LuaOldStack LS(L, varname, flag, result, globaldb);
// Check the varname argument.
eng::string gvar = LS.ckstring(varname);
@@ -1009,7 +1009,7 @@ LuaDefine(global_clearonce, "varname",
"|") {
LuaArg varname;
LuaVar null;
LuaStack LS(L, varname, null);
LuaOldStack LS(L, varname, null);
// Check the varname argument.
eng::string gvar = LS.ckstring(varname);