Compiles with 5.2, but doesn't work.
This commit is contained in:
@@ -70,16 +70,21 @@ static void source_install_builtins(lua_State *L) {
|
||||
|
||||
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);
|
||||
LuaVar key, value, skey, svalue, snapshot, ssnapshot, globtab;
|
||||
LuaStack LS(L, snapshot, key, value, skey, svalue, ssnapshot, globtab);
|
||||
|
||||
// Install the builtins.
|
||||
source_install_builtins(L);
|
||||
|
||||
// Get the global environment.
|
||||
LS.rawget(globtab, LuaRegistry, LUA_RIDX_GLOBALS);
|
||||
|
||||
// Note: the global environment contains _G. This routine
|
||||
// perceives this as a subtable, so it backs up the top level
|
||||
// as well.
|
||||
source_install_builtins(L);
|
||||
LS.newtable(snapshot);
|
||||
LS.set(key, LuaNil);
|
||||
while (LS.next(LuaGlobals, key, value) != 0) {
|
||||
while (LS.next(globtab, key, value) != 0) {
|
||||
if (LS.istable(value)) {
|
||||
LS.newtable(ssnapshot);
|
||||
LS.rawset(snapshot, key, ssnapshot);
|
||||
@@ -181,35 +186,41 @@ void SourceDB::update() {
|
||||
// the class tables.
|
||||
//
|
||||
static void source_clear_globals(lua_State *L) {
|
||||
LuaVar classname, classtab, key;
|
||||
LuaStack LS(L, classname, classtab, key);
|
||||
LuaVar classname, classtab, key, globtab;
|
||||
LuaStack LS(L, classname, classtab, key, globtab);
|
||||
|
||||
LS.rawset(LuaGlobals, "_G", LuaNil);
|
||||
// Get the global environment.
|
||||
LS.rawget(globtab, LuaRegistry, LUA_RIDX_GLOBALS);
|
||||
|
||||
LS.rawset(globtab, "_G", LuaNil);
|
||||
LS.set(classname, LuaNil);
|
||||
while (LS.next(LuaGlobals, classname, classtab) != 0) {
|
||||
while (LS.next(globtab, classname, classtab) != 0) {
|
||||
if (LS.istable(classtab)) {
|
||||
LS.call(table_clear, classtab);
|
||||
} else {
|
||||
LS.rawset(LuaGlobals, classname, LuaNil);
|
||||
LS.rawset(globtab, classname, LuaNil);
|
||||
}
|
||||
}
|
||||
LS.rawset(LuaGlobals, "_G", LuaGlobals);
|
||||
LS.rawset(globtab, "_G", globtab);
|
||||
LS.result();
|
||||
}
|
||||
|
||||
// Restore the lua builtins from the backup snapshot.
|
||||
//
|
||||
static void source_restore_builtins(lua_State *L) {
|
||||
LuaVar snapshot, key, value, skey, svalue, target;
|
||||
LuaStack LS(L, snapshot, key, value, skey, svalue, target);
|
||||
LuaVar snapshot, key, value, skey, svalue, target, globtab;
|
||||
LuaStack LS(L, snapshot, key, value, skey, svalue, target, globtab);
|
||||
|
||||
// Get the global environment table.
|
||||
LS.rawget(globtab, LuaRegistry, LUA_RIDX_GLOBALS);
|
||||
|
||||
LS.rawget(snapshot, LuaRegistry, "source_snapshot_builtins");
|
||||
LS.rawset(LuaGlobals, "_G", LuaGlobals);
|
||||
LS.rawset(globtab, "_G", globtab);
|
||||
LS.set(key, LuaNil);
|
||||
while (LS.next(snapshot, key, value) != 0) {
|
||||
LS.checktable(value);
|
||||
if (LS.equal(key, "_G")) {
|
||||
LS.set(target, LuaGlobals);
|
||||
if (LS.rawequal(key, "_G")) {
|
||||
LS.set(target, globtab);
|
||||
} else {
|
||||
LS.makeclass(target, key);
|
||||
}
|
||||
@@ -312,10 +323,11 @@ void SourceDB::rebuild() {
|
||||
|
||||
void SourceDB::run_unittests() {
|
||||
lua_State *L = lua_state_;
|
||||
LuaVar unittests, name, func, err;
|
||||
LuaStack LS(L, unittests, name, func, err);
|
||||
LuaVar unittests, name, func, err, globtab;
|
||||
LuaStack LS(L, unittests, name, func, err, globtab);
|
||||
|
||||
LS.rawget(unittests, LuaGlobals, "unittests");
|
||||
LS.rawget(globtab, LuaRegistry, LUA_RIDX_GLOBALS);
|
||||
LS.rawget(unittests, globtab, "unittests");
|
||||
|
||||
// Sort the unit test names.
|
||||
std::set<std::string> names;
|
||||
|
||||
Reference in New Issue
Block a user