[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: newbie: parameterised scripts?
- From: tomas@...
- Date: Mon, 06 Apr 1998 14:30:43 -0300
Hi Paul
you can load the script with all your functions at the very beginning
of your application (just after the initialization of Lua libraries). After
that you have to associate each event to a C function that will call the
corresponding Lua function.
For example, this function can be associated to the "mouse click" event:
int mouse_click_event (int x, int y, int buttons)
{
lua_pushnumber (x);
lua_pushnumber (y);
lua_pushnumber (buttons);
lua_callfunction (lua_getglobal ("mouse_click"));
return lua_getnumber (lua_getresult (1));
}
The corresponding Lua function will be called:
function mouse_click (x, y, buttons)
local obj = objects_list:pick_object (x, y)
if obj then
return obj:mouse_click (buttons)
else
return 0 -- The C function expects an integer
end
end
Which will call another Lua function...
Tomas