lua-users home
lua-l archive

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


hi,

I changed my code and now string and math loaded before lua_newtable(...),
but it changed nothing, I get the following error message
"attempt to index global 'string' (a nil value)", i.e. module string is
invisible inside the module "extension.lua". What am I doing wrong?

Best regards,
Dmitriy Iassenev


> Hey watch your stack!
>
> -------------------------------------
> lua_newtable(luaVM);
>
> luaopen_string (luaVM);
> luaopen_math (luaVM);
>
> lua_pushstring(luaVM, "core");
> lua_pushvalue(luaVM, -2);
> lua_settable(luaVM, LUA_GLOBALSINDEX); /* register it with given name */
> lua_setfenv(luaVM, -2);
> -------------------------------------
>
> is vastly different from
>
> -------------------------------------
> luaopen_string (luaVM);
> luaopen_math (luaVM);
>
> lua_newtable(luaVM);
> lua_pushstring(luaVM, "core");
> lua_pushvalue(luaVM, -2);
> lua_settable(luaVM, LUA_GLOBALSINDEX); /* register it with given name */
> lua_setfenv(luaVM, -2);
> -------------------------------------