diff options
Diffstat (limited to 'src/client/lua_api/gui/iguiwindow.cpp')
| -rw-r--r-- | src/client/lua_api/gui/iguiwindow.cpp | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/src/client/lua_api/gui/iguiwindow.cpp b/src/client/lua_api/gui/iguiwindow.cpp index 9a42dff..14fba99 100644 --- a/src/client/lua_api/gui/iguiwindow.cpp +++ b/src/client/lua_api/gui/iguiwindow.cpp @@ -20,8 +20,6 @@ extern "C" { using namespace irr; using namespace gui; -//IrrlichtDevice* guidevice; - static LIGUIElement* checkiguiwindow(lua_State* L, int index){ void* ud = luaL_checkudata(L,index,"gui.iguiwindow"); luaL_argcheck(L,ud != NULL, index, "'gui.iguiwindow' expected"); @@ -33,49 +31,48 @@ static LIGUIElement* checkiguiwindow(lua_State* L){ } static bool iguiwindowevent(irr::SEvent e){ - IGUIElement* caller = (IGUIElement*)e.GUIEvent.Caller; - int ref = iguielements[caller]; - EGUI_EVENT_TYPE etype = e.GUIEvent.EventType; - printf("Detected window event\n"); - if(etype == EGET_ELEMENT_CLOSED){ - lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); - printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1)); - LIGUIElement* tbut = checkiguiwindow(tL,-1); - int hashmapresponse; - char* hashkey = (char*)"onclose"; - int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse); - if(terror == MAP_OK){ //Only call if we actually have that function. - printf("Looks like we have an onclose function, calling!\n"); - lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); //push the function - lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); //push the referance to iguielement - lua_call(tL,1,1); - //int b = lua_isnoneornil(tL,1); - int a = lua_toboolean(tL,-1); - printf("a:%d\n",a); - return a; - } - } - printf("Oh no! an iguiwindow generated an event!"); - return false; + printf("I got a guiwindow event on %p!\n",e.GUIEvent.Caller); + int ref = iguielements[e.GUIEvent.Caller]; + printf("Ref for this guielement is:%d\n",ref); + lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); + lua_getfield(tL,-1,"close"); + + int i = lua_isfunction(tL,-1); + printf("Is function: %d\n",i); + lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); + lua_call(tL,1,1); + + int shouldclose = lua_toboolean(tL,-1); + printf("Should close: %d\n",shouldclose); + return shouldclose == 1; + + return false; } -//new({width,height},{posx,posy},"title"[,parent]) +//window:close() +static int iguiwindowclose(lua_State* L){ + IGUIElement* self = (IGUIElement*)lua_touserdata(L,-1); + lua_pop(L,1); +} + +//new({posx,posy},{width,height},"title"[,parent]) static int newiguiwindow(lua_State* L){ printf("Creating window\n"); - + IGUIElement* parent = NULL; int numargs = lua_gettop(L); - - int parentid = lua_tointeger(L,-1); - lua_pop(L,1); + if(numargs == 4){ + parent = (IGUIElement*)lua_touserdata(L,-1); + lua_pop(L,1); + } const char* title_c = lua_tostring(L,-1); const wchar_t* title_w = irr::core::stringw(title_c).c_str(); lua_pop(L,1); //Frame position long x,y,w,h; - popvector2i(L,&x,&y); popvector2i(L,&w,&h); + popvector2i(L,&x,&y); printf("I want to make a frame at (%d,%d) size (%d,%d)\n",x,y,w,h); @@ -85,17 +82,23 @@ static int newiguiwindow(lua_State* L){ core::rect<s32>(x,y,x+w,y+h), false, title_w, - guielements[parentid], + parent, -1 ); - lua_newtable(L);//{} lua_pushlightuserdata(L,wi); - lua_setfield(L,-2,"element"); - - luaL_getmetatable(L,"gui.window"); - lua_setmetatable(L,-2); + lua_newtable(L);//{} + lua_pushlightuserdata(L,wi);//{},{ud_window} + lua_setfield(L,-2,"element");//{element=ud_window} + + luaL_getmetatable(L,"gui.window");//{element=ud_window},{m_gui.window} + lua_setmetatable(L,-2);//{element=ud_window, __meta=gui.window} + + int ref = luaL_ref(L,LUA_REGISTRYINDEX);//ref + lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//ref,{element=ud_window, __meta=gui.window} + iguielements[wi] = ref; + registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent); return 1; } @@ -105,6 +108,8 @@ static const luaL_reg iguiwindow_m[] = { {"settext", setiguitext}, {"remove", removeiguielement}, {"getid", guigetid}, +// bool :: iguiwindow:close() -- Called when window is closed, returning +// -- Anything but false or nil prevents close {0, 0}, }; |
