lua-users home
lua-l archive

Re: lua globals and C code

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


Hi!
We use our own dynamic package system (luax).
GAA> poslib = {}
GAA> local f, e = loadlib("lposlib.dll", "lua_poslibopen")
GAA> if not f then
GAA> error(e)
GAA> end
GAA> setglobals(f, poslib) -- (this does not work)
GAA> f()
GAA> But, I cannot set the globals table for a C function
May by you try this may:
poslib = {}
local f, e = loadlib("lposlib.dll", "lua_poslibopen")
assert(f, e)
f(poslib)
and in your C code:
static int poslib_globals_ref = 0;
static int lua_poslibopen(lua_Stack *L) {
 poslib_globals_ref = lua_ref(L, 1);
 ...
 return 0
}
And in other functions you may use this reference.
--Denq

AltStyle によって変換されたページ (->オリジナル) /