Refactor code to make it easier to do 'nopredict' inside of any function without having a dependency on world model.

This commit is contained in:
2023-03-01 16:07:13 -05:00
parent aa77480fb5
commit 9ce34d950b
15 changed files with 86 additions and 49 deletions

View File

@@ -7,6 +7,8 @@ LuaDefine(global_once, "name", "for a given string, returns true exactly once")
LuaVar oncedb, val;
LuaStack LS(L, name, flag, oncedb, val);
LS.guard_nopredict("global.once");
// Get a pointer to the oncedb.
LS.rawget(oncedb, LuaRegistry, "oncedb");
if (!LS.istable(oncedb)) {
@@ -25,11 +27,14 @@ LuaDefine(global_once, "name", "for a given string, returns true exactly once")
return LS.result();
}
LuaDefine(global_clearonce, "name", "reset the specified once-flag") {
LuaArg name;
LuaVar oncedb;
LuaStack LS(L, name, oncedb);
LS.guard_nopredict("global.clearonce");
// Get a pointer to the oncedb.
LS.rawget(oncedb, LuaRegistry, "oncedb");
if (!LS.istable(oncedb)) {
@@ -50,11 +55,6 @@ LuaDefine(global_table, "globalname", "get a table where global data can be stor
// Get a pointer to the globaldb.
LS.rawget(globaldb, LuaRegistry, "globaldb");
// nopredict
if (lua_isyieldable(L) && (!LS.istable(globaldb))) {
return lua_yield(L, 0);
}
// Get the globaltab from the globaldb, sanity check it.
LS.rawget(globaltab, globaldb, globalname);
if (LS.istable(globaltab)) {