lua-users home
lua-l archive

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

Xavier Wang <> writes:
> I'm wonder how to change _ENV's value, or rebuild a new _ENV locals in
> C function. the only idea I make out is using a wrapping lua code:
> lua_newtable(L);
> lua_pushcfunction(L, myfunc);
> luaL_loadstring(L, "local _ENV,func = ... return func()");
> lua_call(L, 2, 0);
> Is there any other method to change _ENV in a C function using a pure C API?

I'm not totally sure what you want to do ...

To load a Lua source string with a different _ENV, you just use the
Lua function "load" ("luaB_load" in C), since "load" replaced
loadstring in 5.2 ... e.g. "load (MYSTRING, nil, nil, MYENV)".


Pray, v. To ask that the laws of the universe be annulled in behalf of a
single petitioner confessedly unworthy.