lua-users home
lua-l archive

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


	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