how to callback a lua function from a c function
- by pierr
Hi,
I have a c function test_callback accepting a point to a function as the parameter and It will "callback" that function.
//typedef int(*data_callback_t)(int i);
int test_callback(data_callback_t f)
{
f(3);
}
int datacallback(int a )
{
printf("called back %d\n",a);
return 0;
}
//example
test_callback(datacallback); // print : called back 3
Now, I want to wrap test_callback so that they can be called from lua, suppose the name is lua_test_callback ;and also the input parameter to it would be a lua function. How should I achieve this goal?
function lua_datacallback (a )
print "hey , this is callback in lua" ..a
end
lua_test_callback(lua_datacallback) //expect to get "hey this is callback in lua 3 "