I'm using Irrlicht(C++) for a 3D engine, and it has a built in GUI system. The GUI events are something like this:
switch(eventtype)
case button_pressed:
stuff
case editbox_edited:
stuff
So far I have begun writing a system that allows me to create the GUIs with Lua scripts. It was very easy to make it so it creates the GUI controls from Lua, but I can not think of a good way to define what should happen when control events occur from Lua too. Here's an example of what I have so far:
Lua:
local button = create_button("button label",10,10,100,50)
toggle_control(button,false)
C++:
static int CreateButton(lua_State* L)
{
int n = lua_gettop(L);
core::stringw label = lua_tostring(L,1);
core::stringw tt((n>=5?lua_tostring(L,6):""));
int x = lua_tonumber(L,2);
int y = lua_tonumber(L,3);
int w = lua_tonumber(L,4);
int h = lua_tonumber(L,5);
core::rect r(x,y,x+w,y+h);
unsigned int id = NextID();
if(r.isValid())
{
gui::IGUIButton* b = device->getGUIEnvironment()->addButton(r,0,0,label.c_str(),tt.c_str());
cl.insert(ControlPair(id,b));
lua_pushnumber(L,id);
}
else
lua_pushnumber(L,-1);
return 1;
}
Please ignore the security issues with the code (it is a very early version). So my question is this: What are some good ways of defining the control events from a script interpreter in C++?