lua-users home
lua-l archive

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


"jose_marin2 " wrote:
> 
> Hi!
> 
> Is there some way of do this?
> Later, I will call the function inside the method "doDomething". How
> to store the function to call it later? I know how to do using
> lua_ref, but how to do this with tolua "classes"?

In lua, functions are first-class values. You can store 
them in variables just like other values. So just say:

function theClass:SetFunc(someFunc)
self.myfunc = someFunc
end


function theClass:doDomething()
  if self.myfunc then
  self.myfunc()  
  end
end

And you're all set. ^_^


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be