|
Michael Flad wrote:
Hi, the most simple way is int KeyHandlerRef; int SetKeyFunc( lua_State* l ) { KeyHandlerRef = lua_ref( l, 1 ); } void CallKeyHandler( lua_State* l, int key ) { lua_getref( l, KeyHandlerRef ); //push func on stack lua_pushnumber( l, key ); // push key param lua_call( l, 1, 0 ); // call lua_pop( l, 1 ); // pop func from stack }
I think lua_call does pop the func from the stack automatically, so no lua_pop is needed. An other thing is that I would recommend using lua_pcall instead of lua_call. (Otherwise I agree on using references for the task) Eero