lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I need to know: why does the following program print ones on
the first line, and not nils?

#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

int reset_globals(lua_State *L) {
    lua_newtable(L);
    lua_replace(L, LUA_GLOBALSINDEX);
    luaopen_base(L);
    return 0;
}

int main(int argc, char**argv) {
    lua_State *L = lua_open();
    luaopen_base(L);
    lua_register(L, "reset_globals",
        reset_globals);

    lua_dostring(L,
        "x=1\n"
        "reset_globals()\n"
        "y=x\n"
        "print(x,y)\n");

    lua_dostring(L, "print(x,y)");

    return 0;
}


Also, can I rely on this behavior, or is it a UFO?

Thanks,
Bruce