World model is now operational

This commit is contained in:
2021-01-16 01:24:33 -05:00
parent d7d633bd96
commit 313e78067a
11 changed files with 313 additions and 188 deletions

View File

@@ -64,7 +64,7 @@ static void load_builtin(lua_State *L, const char *name, lua_CFunction func) {
lua_call(L, 1, 0);
}
LuaDefine(source_install_builtins, "") {
static void source_install_builtins(lua_State *L) {
LuaStack LS(L);
load_builtin(L, "base", luaopen_base);
load_builtin(L, "table", luaopen_table);
@@ -72,11 +72,10 @@ LuaDefine(source_install_builtins, "") {
load_builtin(L, "math", luaopen_math);
load_builtin(L, "bit", luaopen_math);
load_builtin(L, "debug", luaopen_debug);
// Do not load: package, io, os, debug, jit
return 0;
}
LuaDefine(source_install_and_snapshot_builtins, "") {
void SourceDB::initialize(lua_State *L) {
lua_state_ = L;
LuaVar key, value, skey, svalue, snapshot, ssnapshot;
LuaStack LS(L, snapshot, key, value, skey, svalue, ssnapshot);
@@ -99,10 +98,10 @@ LuaDefine(source_install_and_snapshot_builtins, "") {
}
}
LS.setfield(LuaRegistry, "source_snapshot_builtins", snapshot);
return LS.result();
LS.result();
}
LuaDefine(source_updatefile, "") {
static int source_updatefile(lua_State *L) {
LuaArg source, fn;
LuaRet info;
LuaVar fingerprint, null;
@@ -127,7 +126,7 @@ LuaDefine(source_updatefile, "") {
if (LS.isstring(fingerprint)) {
old_fingerprint = LS.ckstring(fingerprint);
}
std::cerr << "Probing " << cfn << std::endl;
// std::cerr << "Probing " << cfn << std::endl;
std::string new_fingerprint = util::get_file_fingerprint("syslua/" + cfn);
LS.set(null, LuaNil);
if ((old_fingerprint == "") || (old_fingerprint != new_fingerprint)) {
@@ -147,7 +146,8 @@ LuaDefine(source_updatefile, "") {
return LS.result();
}
LuaDefine(source_update, "c") {
void SourceDB::update() {
lua_State *L = lua_state_;
LuaVar sourcedb, newdb, info, fn, seq;
LuaStack LS(L, newdb, sourcedb, info, fn, seq);
@@ -180,13 +180,13 @@ LuaDefine(source_update, "c") {
// Store the new source db.
LS.setfield(LuaRegistry, "sourcedb", newdb);
return LS.result();
LS.result();
}
// Delete everything from the global environment except
// the class tables and the class action tables.
//
LuaDefine(source_clear_globals, "") {
static void source_clear_globals(lua_State *L) {
LuaVar classname, classtab, action, key;
LuaStack LS(L, classname, classtab, action, key);
@@ -209,12 +209,12 @@ LuaDefine(source_clear_globals, "") {
}
}
LS.setfield(LuaGlobals, "_G", LuaGlobals);
return LS.result();
LS.result();
}
// Restore the lua builtins from the backup snapshot.
//
LuaDefine(source_restore_builtins, "") {
static void source_restore_builtins(lua_State *L) {
LuaVar snapshot, key, value, skey, svalue, subglobal;
LuaStack LS(L, snapshot, key, value, skey, svalue, subglobal);
@@ -229,12 +229,12 @@ LuaDefine(source_restore_builtins, "") {
LS.rawset(subglobal, skey, svalue);
}
}
return LS.result();
LS.result();
}
// Load all the 'LuaDefine' C functions into the lua state.
//
LuaDefine(source_load_cfunctions, "") {
static void source_load_cfunctions(lua_State *L) {
auto regs = LuaFunctionReg::all();
for (const LuaFunctionReg *r : regs) {
const std::string &name = r->get_name();
@@ -260,12 +260,11 @@ LuaDefine(source_load_cfunctions, "") {
lua_setglobal(L, funcname.c_str());
}
}
return 0;
}
// Run all the closures from the source database.
//
LuaDefine(source_load_lfunctions, "") {
static void source_load_lfunctions(lua_State *L) {
LuaRet errors;
LuaVar sourcedb, key, info, seq, closure, err;
LuaStack LS(L, sourcedb, errors, key, info, seq, closure, err);
@@ -305,10 +304,11 @@ LuaDefine(source_load_lfunctions, "") {
}
}
LS.set(errors, errss.str());
return LS.result();
LS.result();
}
LuaDefine(source_rebuild, "c") {
void SourceDB::rebuild() {
lua_State *L = lua_state_;
LuaVar errs;
LuaStack LS(L, errs);
source_clear_globals(L);
@@ -318,13 +318,13 @@ LuaDefine(source_rebuild, "c") {
lua_replace(L, errs.index());
std::string errstr = LS.ckstring(errs);
std::cerr << errstr;
return LS.result();
LS.result();
}
LuaDefine(source_run_unittests, "c") {
void SourceDB::run_unittests() {
lua_State *L = lua_state_;
LuaVar unittests, name, func, err;
LuaRet rescode;
LuaStack LS(L, unittests, name, func, err, rescode);
LuaStack LS(L, unittests, name, func, err);
LS.getfield(unittests, LuaGlobals, "unittests");
@@ -351,8 +351,9 @@ LuaDefine(source_run_unittests, "c") {
}
}
// Return 1 if any errors.
LS.set(rescode, any ? 1 : 0);
return LS.result();
if (any) {
exit(1);
}
LS.result();
}