[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: access to _G
- From: Rob Hoelz <rob@...>
- Date: Mon, 11 Mar 2013 18:17:20 +0100
On Mon, 11 Mar 2013 15:15:02 +0100
Philipp Kraus <philipp.kraus@flashpixx.de> wrote:
> Hello,
>
> I have got a LUA function like
>
> function myload(s)
> _G[s]={}
> return assert(loadfile(s..".lua","bt",_G[s]))()
> end
>
> How can I do this with the C API? In my case, how can I get access to
> the _G variable? Can I use equal calls for a variable? I would like
> also change the loadfile to luaL_loadstring, can I do this?
>
> Thanks
>
> Phil
Hi Phil,
Depending on your version of Lua, you can use LUA_GLOBALSINDEX (5.1) or
the registry (5.2, see http://www.lua.org/manual/5.2/manual.html#4.5).
You can then use lua_gettable/lua_settable/lua_getfield/lua_setfield to
manipulate it. Alternatively, there is also
lua_getglobal/lua_setglobal.
Also, it's Lua, not LUA. ;)
-Rob
Attachment:
signature.asc
Description: PGP signature