Added two new stack disciplines to LuaStack
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") {
|
||||
LuaArg classname;
|
||||
LuaRet classtab;
|
||||
LuaStack LS(L, classname, classtab);
|
||||
LuaOldStack LS(L, classname, classtab);
|
||||
if (!LS.isstring(classname)) {
|
||||
luaL_error(L, "class name must be a string");
|
||||
}
|
||||
@@ -35,7 +35,7 @@ LuaDefine(makeclass, "classname", "create a class if it doesn't already exist")
|
||||
LuaDefine(getclass, "classname", "get the classtab with the specified name") {
|
||||
LuaArg classname;
|
||||
LuaRet classtab;
|
||||
LuaStack LS(L, classname, classtab);
|
||||
LuaOldStack LS(L, classname, classtab);
|
||||
eng::string err = LS.getclass(classtab, classname);
|
||||
if (err != "") {
|
||||
luaL_error(L, "%s", err.c_str());
|
||||
@@ -46,7 +46,7 @@ LuaDefine(getclass, "classname", "get the classtab with the specified name") {
|
||||
LuaDefine(classname, "classtable", "get the class name from a class table") {
|
||||
LuaArg table;
|
||||
LuaRet result;
|
||||
LuaStack LS(L, table, result);
|
||||
LuaOldStack LS(L, table, result);
|
||||
eng::string rstr = LS.classname(table);
|
||||
if (rstr == "") {
|
||||
LS.set(result, LuaNil);
|
||||
@@ -67,7 +67,7 @@ static void get_reg_name(std::string_view name, std::string_view &classname, std
|
||||
}
|
||||
}
|
||||
|
||||
static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const eng::string &fn) {
|
||||
static void get_info_table(LuaCoreStack &LS, LuaSlot db, LuaSlot info, const eng::string &fn) {
|
||||
LS.rawget(info, db, fn);
|
||||
if (!LS.istable(info)) {
|
||||
LS.set(info, LuaNewTable);
|
||||
@@ -76,9 +76,9 @@ static void get_info_table(LuaStack &LS, LuaSlot db, LuaSlot info, const eng::st
|
||||
LS.rawset(info, "name", fn);
|
||||
}
|
||||
|
||||
static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const eng::string &fn, const eng::string &code) {
|
||||
static void calculate_loadresult(LuaCoreStack &LS0, LuaSlot info, const eng::string &fn, const eng::string &code) {
|
||||
LuaVar loadresult;
|
||||
LuaStack LS(LS0.state(), loadresult);
|
||||
LuaOldStack LS(LS0.state(), loadresult);
|
||||
if (code == "") {
|
||||
LS.rawset(info, "loadresult", "missing or empty source file");
|
||||
} else {
|
||||
@@ -93,8 +93,8 @@ static void calculate_loadresult(LuaStack &LS0, LuaSlot info, const eng::string
|
||||
void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
|
||||
LuaVar sdb, sfn, sinfo, shash, sseq;
|
||||
LuaVar mdb, mfn, minfo, mhash, mseq, mcode;
|
||||
LuaStack SLS(lua_state_, sdb, sfn, sinfo, shash, sseq);
|
||||
LuaStack MLS(auth.lua_state_, mdb, mfn, minfo, mhash, mseq, mcode);
|
||||
LuaOldStack SLS(lua_state_, sdb, sfn, sinfo, shash, sseq);
|
||||
LuaOldStack MLS(auth.lua_state_, mdb, mfn, minfo, mhash, mseq, mcode);
|
||||
sb->write_int32(0);
|
||||
int wc_after = sb->total_writes();
|
||||
int nupdates = 0;
|
||||
@@ -152,7 +152,7 @@ void SourceDB::diff(const SourceDB &auth, StreamBuffer *sb) {
|
||||
bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar db, info;
|
||||
LuaStack LS(L, db, info);
|
||||
LuaOldStack LS(L, db, info);
|
||||
LS.rawget(db, LuaRegistry, "sourcedb");
|
||||
int nupdates = sb->read_int32();
|
||||
for (int i = 0; i < nupdates; i++) {
|
||||
@@ -179,7 +179,7 @@ bool SourceDB::patch(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence) {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar db, info;
|
||||
LuaStack LS(L, db, info);
|
||||
LuaOldStack LS(L, db, info);
|
||||
LS.rawget(db, LuaRegistry, "sourcedb");
|
||||
get_info_table(LS, db, info, fn);
|
||||
LS.rawset(info, "sequence", sequence);
|
||||
@@ -193,7 +193,7 @@ void SourceDB::set(const eng::string &fn, const eng::string &code, int sequence)
|
||||
eng::string SourceDB::get(const eng::string &fn) {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar db, info, code, sequence, loadresult;
|
||||
LuaStack LS(L, db, info, code, sequence, loadresult);
|
||||
LuaOldStack LS(L, db, info, code, sequence, loadresult);
|
||||
LS.rawget(db, LuaRegistry, "sourcedb");
|
||||
LS.rawget(info, db, fn);
|
||||
if (!LS.istable(info)) {
|
||||
@@ -220,7 +220,7 @@ eng::string SourceDB::get(const eng::string &fn) {
|
||||
void SourceDB::update(const util::LuaSourceVec &source) {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar sourcedb, info;
|
||||
LuaStack LS(L, sourcedb, info);
|
||||
LuaOldStack LS(L, sourcedb, info);
|
||||
|
||||
// Get and clear the source database.
|
||||
LS.rawget(sourcedb, LuaRegistry, "sourcedb");
|
||||
@@ -250,7 +250,7 @@ void SourceDB::update(const util::LuaSourceVec &source) {
|
||||
//
|
||||
static void source_clear_globals(lua_State *L) {
|
||||
LuaVar classname, classtab, key, globtab, classes;
|
||||
LuaStack LS(L, classname, classtab, key, globtab, classes);
|
||||
LuaOldStack LS(L, classname, classtab, key, globtab, classes);
|
||||
|
||||
LS.getglobaltable(globtab);
|
||||
LS.cleartable(globtab, true);
|
||||
@@ -271,7 +271,7 @@ static void source_clear_globals(lua_State *L) {
|
||||
//
|
||||
static void source_load_cfunctions(lua_State *L) {
|
||||
LuaVar classobj;
|
||||
LuaStack LS(L, classobj);
|
||||
LuaOldStack LS(L, classobj);
|
||||
for (auto r = LuaFunctionReg::All; r != nullptr; r=r->next()) {
|
||||
lua_CFunction func = r->get_func();
|
||||
if ((func != nullptr) && (!r->get_sandbox())) {
|
||||
@@ -294,7 +294,7 @@ static void source_load_cfunctions(lua_State *L) {
|
||||
//
|
||||
static void source_load_cconstants(lua_State *L) {
|
||||
LuaVar classobj, value;
|
||||
LuaStack LS(L, classobj, value);
|
||||
LuaOldStack LS(L, classobj, value);
|
||||
for (auto r = LuaConstantReg::All; r != nullptr; r=r->next()) {
|
||||
if (r->get_tokenvalue().empty()) {
|
||||
LS.set(value, r->get_numbervalue());
|
||||
@@ -319,7 +319,7 @@ static void source_load_cconstants(lua_State *L) {
|
||||
//
|
||||
static eng::string source_load_lfunctions(lua_State *L) {
|
||||
LuaVar sourcedb, key, info, seq, closure, err;
|
||||
LuaStack LS(L, sourcedb, key, info, seq, closure, err);
|
||||
LuaOldStack LS(L, sourcedb, key, info, seq, closure, err);
|
||||
|
||||
// Get the source database.
|
||||
LS.rawget(sourcedb, LuaRegistry, "sourcedb");
|
||||
@@ -364,7 +364,7 @@ static eng::string source_load_lfunctions(lua_State *L) {
|
||||
eng::string SourceDB::rebuild() {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar mathclass, httpclass, jsonnull;
|
||||
LuaStack LS(L, mathclass, httpclass, jsonnull);
|
||||
LuaOldStack LS(L, mathclass, httpclass, jsonnull);
|
||||
source_clear_globals(L);
|
||||
source_load_cfunctions(L);
|
||||
source_load_cconstants(L);
|
||||
@@ -376,7 +376,7 @@ eng::string SourceDB::rebuild() {
|
||||
void SourceDB::run_unittests() {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar unittests, name, func, err, globtab;
|
||||
LuaStack LS(L, unittests, name, func, err, globtab);
|
||||
LuaOldStack LS(L, unittests, name, func, err, globtab);
|
||||
|
||||
LS.getglobaltable(globtab);
|
||||
LS.rawget(unittests, globtab, "unittests");
|
||||
@@ -414,7 +414,7 @@ void SourceDB::run_unittests() {
|
||||
void SourceDB::init(lua_State *L) {
|
||||
lua_state_ = L;
|
||||
LuaVar globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring;
|
||||
LuaStack LS(L, globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring);
|
||||
LuaOldStack LS(L, globtab, persist, unpersist, classname, classtab, funcname, funcp, rawfunc, nullstring);
|
||||
LS.getglobaltable(globtab);
|
||||
LS.rawset(LuaRegistry, "sourcedb", LuaNewTable);
|
||||
|
||||
@@ -470,10 +470,10 @@ void SourceDB::deserialize_source(util::LuaSourceVec *sv, StreamBuffer *sb) {
|
||||
|
||||
// This function should not touch the dlmalloc heap.
|
||||
void SourceDB::register_lua_builtins() {
|
||||
lua_State *L = LuaStack::newstate(nullptr);
|
||||
lua_State *L = LuaOldStack::newstate(nullptr);
|
||||
luaL_openlibs(L);
|
||||
LuaVar globals, lclassname, lfuncname, classtab, func;
|
||||
LuaStack LS(L, globals, lclassname, lfuncname, classtab, func);
|
||||
LuaOldStack LS(L, globals, lclassname, lfuncname, classtab, func);
|
||||
LS.getglobaltable(globals);
|
||||
|
||||
// Iterate over the function registry, copying function pointers from
|
||||
@@ -527,10 +527,10 @@ void SourceDB::register_lua_builtins() {
|
||||
}
|
||||
|
||||
|
||||
eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
|
||||
eng::string SourceDB::function_docs(const LuaCoreStack &LS0, LuaSlot fn) {
|
||||
lua_State *L = LS0.state();
|
||||
LuaVar sourcedb, fname, finfo, code;
|
||||
LuaStack LS(L, sourcedb, fname, finfo, code);
|
||||
LuaOldStack LS(L, sourcedb, fname, finfo, code);
|
||||
|
||||
if (LS.iscfunction(fn)) {
|
||||
lua_CFunction cfn = lua_tocfunction(L, fn.index());
|
||||
@@ -607,7 +607,7 @@ eng::string SourceDB::function_docs(const LuaStack &LS0, LuaSlot fn) {
|
||||
// These should go away eventually. They're for debugging.
|
||||
LuaDefine(coroutine_setnextid, "thread,id", "set the next id of a thread (debugging only)") {
|
||||
LuaArg co, lid;
|
||||
LuaStack LS(L, co, lid);
|
||||
LuaOldStack LS(L, co, lid);
|
||||
lua_State *CO = LS.ckthread(co);
|
||||
lua_Number id = LS.ckinteger(lid);
|
||||
lua_setnextid(CO, id);
|
||||
@@ -617,7 +617,7 @@ LuaDefine(coroutine_setnextid, "thread,id", "set the next id of a thread (debugg
|
||||
LuaDefine(coroutine_getnextid, "thread", "get the next id of a thread (debugging only)") {
|
||||
LuaArg co;
|
||||
LuaRet lid;
|
||||
LuaStack LS(L, co, lid);
|
||||
LuaOldStack LS(L, co, lid);
|
||||
lua_State *CO = LS.ckthread(co);
|
||||
LS.set(lid, lua_getnextid(CO));
|
||||
return LS.result();
|
||||
@@ -766,7 +766,7 @@ LuaSandboxBuiltin(math_log10, "", "");
|
||||
LuaNumberConstant(math_pi, M_PI, "");
|
||||
LuaNumberConstant(math_huge, HUGE_VAL, "");
|
||||
LuaNumberConstant(math_nan, NAN, "");
|
||||
LuaNumberConstant(math_maxint, LuaStack::MAXINT, "");
|
||||
LuaNumberConstant(math_maxint, LuaOldStack::MAXINT, "");
|
||||
|
||||
// math.random and math.randomseed are in world-accessor.cpp, because
|
||||
// generating random numbers must manipulate global state which is
|
||||
|
||||
Reference in New Issue
Block a user