lua-users home
lua-l archive

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


Ok, thanks to all for your replies.

I'll make some tests with the provided information and will post the result (if it can help someone else).

Thanks

Laurent----
The misspelling master is on the Web.
  _________ 100 % Dictionnary Free !
/               /(
/ Dico       / / Pleins d'autres fautes sur
/________/ /
(#######( / http://destroyedlolo.info
Quoi, des fautes d'orthographe! Pas possible ;-D.



Le Mercredi 3 juin 2015 14h19, Roberto Ierusalimschy <roberto@inf.puc-rio.br> a écrit :


>  Another way is to store a reference in the Lua Registry:

>      int myfuncref;
>     
>      static int foo(lua_State *L)
>      {
>       
>        luaL_checktype(L,1,LUA_TFUNCTION);
>        myfuncref = luaL_ref(L,LUA_REGISTRYINDEX);
>        lua_pushinteger(L,myfuncref);
>        lua_pushvalue(L,1);
>        lua_settable(L,LUA_REGISTRYINDEX);
>        return 0;
>      }

luaL_ref does all the work (see the manual). This function should be
like this:

      static int foo(lua_State *L) {
          luaL_checktype(L,1,LUA_TFUNCTION);
          myfuncref = luaL_ref(L,LUA_REGISTRYINDEX);
          return 0;
        }


>  And to call that:

>      static int bar(lua_State *L)
>      {
>        lua_pushinteger(L,myfuncref);
>        lua_gettable(L,LUA_REGISTRYINDEX);
>        lua_call(L,0,0);
>        return 0;
>      }

(It is simpler to use 'lua_rawgeti'...)

-- Roberto