lua-users home
lua-l archive

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


plug: can't find the earlier part of this thread to see if you are using c++ but if you are, the lua-icxx library (http://www.sf.net/projects/lua-icxx) makes this (and a lot more) trivial. 
oliver

On Fri, Aug 12, 2011 at 9:10 AM, Jose Marin <jose_marin2@yahoo.com.br> wrote:
I´ve just read the manual section about luaL_ref and _unref, and seems the way to go.

Thank you!

Jose


--- Em sex, 12/8/11, Rob Kendrick <rjek@rjek.com> escreveu:

> De: Rob Kendrick <rjek@rjek.com>
> Assunto: Re: Store reference to a function to be called later
> Para: "Lua mailing list" <lua-l@lists.lua.org>
> Data: Sexta-feira, 12 de Agosto de 2011, 9:43
> On Fri, Aug 12, 2011 at 04:57:08AM
> -0700, Jose Marin wrote:
>
> > I wouldn´t like to store the string "OnPlay", and
> make a search on the register for the function, would like
> to store the reference to the fucntion itself, to be
> directly called when the button is pressed.
> >
> > Any suggestions?
>
> You can't take the actual reference to the function, as
> this would
> defeat the garbage collector, as Lua won't know when your C
> code is done
> with it.
>
> Look at luaL_ref and _unref.  These will give you an
> integer "handle" to
> a Lua value that you can then store and easily lookup when
> you need to.
>
> B.
>
>