[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 creating globals with userdata (retry)
- From: Coda Highland <chighland@...>
- Date: Tue, 10 Apr 2012 16:27:43 -0500
> Can anyone provide an example of how to create global userdata objects in C code that are accessible from Lua 5.2 scripts?
I've not used 5.2, but in 5.1 it's a simple matter of creating the
userdata object as normal, leave it on the top of the stack, and then
use lua_setfield(L, LUA_GLOBALSINDEX, "variableName");
A quick look at the documentation indicates that in 5.2, instead of
using LUA_GLOBALSINDEX you'll want to grab the global environment out
of the registry (lua_getfield(L, LUA_REGISTRYINDEX,
LUA_RIDX_GLOBALS);) and then set your userdata as a field in the table
that returns.
/s/ Adam