lua-users home
lua-l archive

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


I am really hoping someone could help me with this question please as I am totally stuck on it for now.
 
I am trying to implement a userdata via the C API,  to give me this type of functionality
 
btn1 = graphics.newButton(x,y,width,ht, "pressMe")
btn1:setText("Different Text")
btn1:setFont("Arial")
 
That's OK I think I have got that figured out and largely working, but the next thing I want to do is call a user defined Lua action function on the button instance. For example
 
In Lua
 
function btn1:action(someArbitrayParamBackFromC)
     print("ouch someone just poked btn1")
end
 
How can I call that Lua button instance function from C when I have detected the key is pressed ?
 
I have done something vaguely similar in the past when I have created a custom timer on the Lua side, but the difference was I had a timer create function in Lua such as
 
myNewTimer = createTimer( period, luaFunctionCallback)
 
So I was passed the callback function into the C code which meant I could stash it away in the registry and then when the timer elapsed on the C side, I did this
 
 // push function indexed by registryRef from the registry back onto the stack
// the lua callback function in this case
lua_rawgeti(local_L, LUA_REGISTRYINDEX, registryRef);
/* the first function argument is the timerID */
lua_pushinteger(local_L, myTimerID);
/* call the function with 1 argument, return 0 result */
pcallResult = lua_pcall(local_L,1,0,0);    // pops 2 params from stack

I am guessing the solution is somewhat similar but cant figure it out.
 
Many thanks for any assistance
 
   Geoff