Get rid of getfield/setfield
This commit is contained in:
@@ -91,15 +91,15 @@ void SourceDB::initialize(lua_State *L) {
|
||||
}
|
||||
}
|
||||
}
|
||||
LS.setfield(LuaRegistry, "source_snapshot_builtins", snapshot);
|
||||
LS.rawset(LuaRegistry, "source_snapshot_builtins", snapshot);
|
||||
LS.result();
|
||||
}
|
||||
|
||||
static int source_updatefile(lua_State *L) {
|
||||
LuaArg source, fn;
|
||||
LuaRet info;
|
||||
LuaVar fingerprint, null;
|
||||
LuaStack LS(L, source, fn, info, fingerprint, null);
|
||||
LuaVar fingerprint, null, loadresult;
|
||||
LuaStack LS(L, source, fn, info, fingerprint, null, loadresult);
|
||||
|
||||
// Get the existing info table from the source DB.
|
||||
if (LS.istable(source)) {
|
||||
@@ -115,7 +115,7 @@ static int source_updatefile(lua_State *L) {
|
||||
// these fields: code, fingerprint, closure, error
|
||||
// Otherwise, update nothing.
|
||||
std::string cfn = LS.ckstring(fn);
|
||||
LS.getfield(fingerprint, info, "fingerprint");
|
||||
LS.rawget(fingerprint, info, "fingerprint");
|
||||
std::string old_fingerprint;
|
||||
if (LS.isstring(fingerprint)) {
|
||||
old_fingerprint = LS.ckstring(fingerprint);
|
||||
@@ -126,15 +126,16 @@ static int source_updatefile(lua_State *L) {
|
||||
if ((old_fingerprint == "") || (old_fingerprint != new_fingerprint)) {
|
||||
std::cerr << "Rereading " << cfn << std::endl;
|
||||
std::string ccode = util::get_file_contents("lua/" + cfn);
|
||||
LS.setfield(info, "name", fn);
|
||||
LS.setfield(info, "fingerprint", new_fingerprint);
|
||||
LS.setfield(info, "code", ccode);
|
||||
LS.rawset(info, "name", fn);
|
||||
LS.rawset(info, "fingerprint", new_fingerprint);
|
||||
LS.rawset(info, "code", ccode);
|
||||
if ((new_fingerprint == "")||(ccode == "")) {
|
||||
LS.setfield(info, "loadresult", "cannot read source file");
|
||||
LS.rawset(info, "loadresult", "cannot read source file");
|
||||
} else {
|
||||
std::string chunk = "=" + cfn;
|
||||
luaL_loadbuffer(L, ccode.c_str(), ccode.size(), chunk.c_str());
|
||||
lua_setfield(L, info.index(), "loadresult");
|
||||
lua_replace(L, loadresult.index());
|
||||
LS.rawset(info, "loadresult", loadresult);
|
||||
}
|
||||
}
|
||||
return LS.result();
|
||||
@@ -146,7 +147,7 @@ void SourceDB::update() {
|
||||
LuaStack LS(L, newdb, sourcedb, info, fn, seq);
|
||||
|
||||
// Get the (old) source database.
|
||||
LS.getfield(sourcedb, LuaRegistry, "sourcedb");
|
||||
LS.rawget(sourcedb, LuaRegistry, "sourcedb");
|
||||
if (!LS.istable(sourcedb)) {
|
||||
LS.newtable(sourcedb);
|
||||
}
|
||||
@@ -167,12 +168,12 @@ void SourceDB::update() {
|
||||
|
||||
// Insert the sequence number and put finalized info into the new database.
|
||||
LS.set(seq, i + 1);
|
||||
LS.setfield(info, "sequence", seq);
|
||||
LS.rawset(info, "sequence", seq);
|
||||
LS.rawset(newdb, fn, info);
|
||||
}
|
||||
|
||||
// Store the new source db.
|
||||
LS.setfield(LuaRegistry, "sourcedb", newdb);
|
||||
LS.rawset(LuaRegistry, "sourcedb", newdb);
|
||||
LS.result();
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ static void source_clear_globals(lua_State *L) {
|
||||
LuaVar classname, classtab, key;
|
||||
LuaStack LS(L, classname, classtab, key);
|
||||
|
||||
LS.setfield(LuaGlobals, "_G", LuaNil);
|
||||
LS.rawset(LuaGlobals, "_G", LuaNil);
|
||||
LS.set(classname, LuaNil);
|
||||
while (LS.next(LuaGlobals, classname, classtab) != 0) {
|
||||
if (LS.istable(classtab)) {
|
||||
@@ -192,7 +193,7 @@ static void source_clear_globals(lua_State *L) {
|
||||
LS.rawset(LuaGlobals, classname, LuaNil);
|
||||
}
|
||||
}
|
||||
LS.setfield(LuaGlobals, "_G", LuaGlobals);
|
||||
LS.rawset(LuaGlobals, "_G", LuaGlobals);
|
||||
LS.result();
|
||||
}
|
||||
|
||||
@@ -202,8 +203,8 @@ static void source_restore_builtins(lua_State *L) {
|
||||
LuaVar snapshot, key, value, skey, svalue, target;
|
||||
LuaStack LS(L, snapshot, key, value, skey, svalue, target);
|
||||
|
||||
LS.getfield(snapshot, LuaRegistry, "source_snapshot_builtins");
|
||||
LS.setfield(LuaGlobals, "_G", LuaGlobals);
|
||||
LS.rawget(snapshot, LuaRegistry, "source_snapshot_builtins");
|
||||
LS.rawset(LuaGlobals, "_G", LuaGlobals);
|
||||
LS.set(key, LuaNil);
|
||||
while (LS.next(snapshot, key, value) != 0) {
|
||||
LS.checktable(value);
|
||||
@@ -258,17 +259,17 @@ static void source_load_lfunctions(lua_State *L) {
|
||||
LuaStack LS(L, sourcedb, errors, key, info, seq, closure, err);
|
||||
|
||||
// Get the source database.
|
||||
LS.getfield(sourcedb, LuaRegistry, "sourcedb");
|
||||
LS.rawget(sourcedb, LuaRegistry, "sourcedb");
|
||||
if (LS.type(sourcedb) != LUA_TTABLE) {
|
||||
LS.newtable(sourcedb);
|
||||
LS.setfield(LuaRegistry, "sourcedb", sourcedb);
|
||||
LS.rawset(LuaRegistry, "sourcedb", sourcedb);
|
||||
}
|
||||
|
||||
// Sort the keys by sequence number.
|
||||
std::map<int, std::string> indices;
|
||||
LS.set(key, LuaNil);
|
||||
while (LS.next(sourcedb, key, info) != 0) {
|
||||
LS.getfield(seq, info, "sequence");
|
||||
LS.rawget(seq, info, "sequence");
|
||||
indices[LS.ckinteger(seq)] = LS.ckstring(key);
|
||||
}
|
||||
|
||||
@@ -276,7 +277,7 @@ static void source_load_lfunctions(lua_State *L) {
|
||||
std::stringstream errss;
|
||||
for (const auto &p : indices) {
|
||||
LS.rawget(info, sourcedb, p.second);
|
||||
LS.getfield(closure, info, "loadresult");
|
||||
LS.rawget(closure, info, "loadresult");
|
||||
|
||||
// If there's already an error in the sourcedb, collect it.
|
||||
if (!LS.isfunction(closure)) {
|
||||
@@ -314,7 +315,7 @@ void SourceDB::run_unittests() {
|
||||
LuaVar unittests, name, func, err;
|
||||
LuaStack LS(L, unittests, name, func, err);
|
||||
|
||||
LS.getfield(unittests, LuaGlobals, "unittests");
|
||||
LS.rawget(unittests, LuaGlobals, "unittests");
|
||||
|
||||
// Sort the unit test names.
|
||||
std::set<std::string> names;
|
||||
|
||||
Reference in New Issue
Block a user