From 0d3b868de79c90d7f4c226927d620a569e7d0b75 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 9 Sep 2008 11:04:56 +0000 Subject: [PATCH] * After calling the Lua event handler function make sure to pop the return value from the stack * If the Lua event handler function didn't return a value, assume it was successful (and leave the stack as is) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5978 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/betawidget/betawidget.i | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/betawidget/betawidget.i b/lib/betawidget/betawidget.i index 4613cb583..bbccc216a 100644 --- a/lib/betawidget/betawidget.i +++ b/lib/betawidget/betawidget.i @@ -25,6 +25,9 @@ typedef struct static bool callbackHandler(widget* const self, const event* const evt, int const handlerId, lua_widget_callback const * const callbackRef) { + const int stack_top = lua_gettop(callbackRef->L); + bool result; + assert(self == callbackRef->self); assert(evt->type == callbackRef->type); assert(handlerId == callbackRef->handlerId); @@ -50,7 +53,14 @@ static bool callbackHandler(widget* const self, const event* const evt, int cons // return callback(self, evt, handlerId) if (lua_pcall(callbackRef->L, 3, 1, 0) != 0) return false; - return lua_toboolean(callbackRef->L, 1); + if (lua_gettop(callbackRef->L) != (stack_top + 1)) + // If no value got returned assume the event handler was succesfull + return true; + + // Pop the result from the stack and return it + result = lua_toboolean(callbackRef->L, -1); + lua_pop(callbackRef->L, 1); + return result; } static bool callbackDestructor(widget* const self, const event* const evt, int const handlerId, lua_widget_callback* const callbackRef)