[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Calling Lua function from C
- From: Max Ischenko <max@...>
- Date: Fri, 20 Jun 2003 16:50:55 +0300
> >I'm trying to call the foobar from C and to save returned value (to be
> >able to call it later).
> >Is there a way to store a Lua function as C object (and call it) or I
> >should be using some other way?
> A Lua function can be stored in the Registry just like any other Lua
> value.
> /* take func from top of stack and store it in the Registry */
> int func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
> /* now store func_ref some place safe in C */
> Later on, you can get it back and call it.
> lua_rawgeti(L, LUA_REGISTRYINDEX, func_ref);
> lua_pcall(L, 0, 0, 0);
That's works perfectly, thanks!
But then another issue arises -- for each function returned
I have to have a duplicate entry in the Registry. While I'm going to
have hundreds of such refs this could become a problem. May be I just
could setup some hash table in Lua with integer indicies and return it
instead of function...
--
Regards, max.