Beispiel #1
0
    function testListOfGlobalVars()
    {
        $sandbox = new Lua();
        $globals = array();
        $sandbox->registerCallback('phpCallback', function ($key) use(&$globals) {
            $globals[] = $key;
        });
        $sandbox->eval(<<<CODE
    local cb = phpCallback
    _G.phpCallback = nil
\tfor n,v in pairs(_G) do
        cb(n)
\tend
CODE
);
        sort($globals);
        $this->assertEquals(LuaGlobals::getGlobals(), $globals);
    }
Beispiel #2
0
    function testUnset()
    {
        $unsetKeys = array('dofile', 'loadfile', 'module', 'require', 'coroutine', 'debug', 'file', 'io', 'os', 'package');
        $this->obj->unsetVar($unsetKeys);
        $globals = $this->obj->run(<<<CODE
local names = {}
for name, val in pairs(_G) do
    table.insert(names, name)
end
table.sort(names)
return names
CODE
);
        $luaGlobals = LuaGlobals::getGlobals();
        $luaGlobals = array_flip($luaGlobals);
        foreach ($luaGlobals as $key => $i) {
            $luaGlobals[$key] = !in_array($key, $unsetKeys);
        }
        $luaGlobals = array_filter($luaGlobals);
        $luaGlobals = array_keys($luaGlobals);
        $this->assertEquals($luaGlobals, array_values($globals));
    }