* Add enum spacerDirection and its contents to the Lua betawidget module
* Add method `destroy` to the Lua class `widget` and its children in the betawidget module * Add some code that demonstrates the usage of widget:destroy() and its current flaws (i.e. segfaults ''will'' occur when using widget after calling the destroy() method on it, garbage collection is included in "using") git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6008 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
c661cb9bc4
commit
ee7cfc1ac5
|
@ -83,6 +83,12 @@ int widgetGetTime(void);
|
|||
%newobject widgetGetClipboardText;
|
||||
%include "clipboard.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SPACER_DIRECTION_HORIZONTAL,
|
||||
SPACER_DIRECTION_VERTICAL
|
||||
} spacerDirection;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LEFT,
|
||||
|
@ -496,6 +502,38 @@ fail:
|
|||
return args;
|
||||
}
|
||||
|
||||
static int lua_widget_destroy(lua_State* const L)
|
||||
{
|
||||
int args = 0;
|
||||
_widget *self;
|
||||
swig_lua_userdata* usr;
|
||||
|
||||
SWIG_check_num_args("addChild", 1, 1);
|
||||
if (!SWIG_isptrtype(L, 1))
|
||||
SWIG_fail_arg("destroy", 1, "_widget *");
|
||||
|
||||
if (!SWIG_IsOK(SWIG_ConvertPtr(L, 1, (void**)&self, SWIGTYPE_p__widget,0)))
|
||||
{
|
||||
SWIG_fail_ptr("widget_destroy", 1, SWIGTYPE_p__widget);
|
||||
}
|
||||
|
||||
widgetDestroy(self);
|
||||
|
||||
/* FIXME: Setting SWIG's pointer to our widget to NULL. This is
|
||||
* currently required because widgetDestroy() frees the memory
|
||||
* at *self. This however causes *all* further operations (in
|
||||
* Lua) on the "self" variable/object to cause segfaults.
|
||||
*/
|
||||
usr = (swig_lua_userdata*)lua_touserdata(L, 1);
|
||||
usr->ptr = NULL;
|
||||
|
||||
return args;
|
||||
|
||||
fail:
|
||||
lua_error(L);
|
||||
return args;
|
||||
}
|
||||
|
||||
static bool lua_inherits_From(swig_lua_class const * const clss, swig_lua_class const * const from)
|
||||
{
|
||||
int i;
|
||||
|
@ -550,6 +588,7 @@ static void addLuaFuncToSwigBaseClass(lua_State* const L,
|
|||
{
|
||||
{ &_wrap_class__widget, "addEventHandler", lua_widget_addEventHandler },
|
||||
{ &_wrap_class__widget, "addTimerEventHandler", lua_widget_addTimerEventHandler },
|
||||
{ &_wrap_class__widget, "destroy", lua_widget_destroy },
|
||||
};
|
||||
|
||||
int i;
|
||||
|
|
|
@ -19,14 +19,6 @@ wnd:addEventHandler(betawidget.EVT_MOUSE_CLICK,
|
|||
end
|
||||
end)()
|
||||
)
|
||||
wnd:addTimerEventHandler(betawidget.EVT_TIMER_PERSISTENT, 1000,
|
||||
(function ()
|
||||
local starttime = betawidget.getTime()
|
||||
return function (self, evt, handlerId)
|
||||
print(string.format("%f seconds passed", (betawidget.getTime() - starttime) / 1000))
|
||||
end
|
||||
end)()
|
||||
)
|
||||
wnd:addEventHandler(betawidget.EVT_KEY_DOWN,
|
||||
function (self, evt, handlerId)
|
||||
print("Key down")
|
||||
|
@ -62,5 +54,27 @@ wnd:addTimerEventHandler(betawidget.EVT_TIMER_SINGLE_SHOT, 5000,
|
|||
)
|
||||
end
|
||||
)
|
||||
|
||||
wnd3 = betawidget.window('test destroy window', 75, 37.5)
|
||||
wnd3:reposition(50, 50)
|
||||
wnd3:show()
|
||||
|
||||
wnd3:addTimerEventHandler(betawidget.EVT_TIMER_SINGLE_SHOT, 15000,
|
||||
function (self, evt, handlerId)
|
||||
print "destroying window 3"
|
||||
print "if you close this application now, you should experience a segfault"
|
||||
self:destroy()
|
||||
end
|
||||
)
|
||||
|
||||
wnd3:addTimerEventHandler(betawidget.EVT_TIMER_PERSISTENT, 1000,
|
||||
(function ()
|
||||
local starttime = betawidget.getTime()
|
||||
return function (self, evt, handlerId)
|
||||
print(string.format("%f seconds passed", (betawidget.getTime() - starttime) / 1000))
|
||||
end
|
||||
end)()
|
||||
)
|
||||
|
||||
wnd = nil
|
||||
wnd2 = nil
|
||||
|
|
Loading…
Reference in New Issue