--- CEGUILua.cpp	Sun Jan 25 18:32:57 2009
+++ CEGUILua.cpp	Thu Jan 29 10:24:44 2009
@@ -27,10 +27,6 @@
  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  *   OTHER DEALINGS IN THE SOFTWARE.
  ***************************************************************************/
-#ifdef HAVE_CONFIG_H
-#   include "config.h"
-#endif
-
 #include "CEGUI.h"
 #include "CEGUIConfig.h"
 #include "CEGUIPropertyHelper.h"
@@ -45,7 +41,7 @@
 #include "lauxlib.h"
 }
 
-#include "tolua++.h"
+#include "tolua/tolua++.h"
 
 // prototype for bindings initialisation function
 int tolua_CEGUI_open(lua_State* tolua_S);
@@ -59,9 +55,10 @@
 	Constructor (creates Lua state)
 *************************************************************************/
 LuaScriptModule::LuaScriptModule() :
-    d_errFuncIndex(LUA_NOREF)
+    d_errFuncIndex(LUA_NOREF),
+    d_activeErrFuncIndex(LUA_NOREF)
 {
-    #if CEGUI_LUA_VER >= 51
+    #if LUA_VERSION_NUM >= 501
         static const luaL_Reg lualibs[] = {
             {"", luaopen_base},
             {LUA_LOADLIBNAME, luaopen_package},
@@ -75,14 +72,14 @@
         #endif
             {0, 0}
         };
-    #endif /* CEGUI_LUA_VER >= 51 */
+    #endif /* LUA_VERSION_NUM >= 501 */
 
     // create a lua state
     d_ownsState = true;
     d_state = lua_open();
 
     // init all standard libraries
-    #if CEGUI_LUA_VER >= 51
+    #if LUA_VERSION_NUM >= 501
             const luaL_Reg *lib = lualibs;
             for (; lib->func; lib++)
             {
@@ -90,7 +87,7 @@
                 lua_pushstring(d_state, lib->name);
                 lua_call(d_state, 1, 0);
             }
-    #else /* CEGUI_LUA_VER >= 51 */
+    #else /* LUA_VERSION_NUM >= 501 */
         luaopen_base(d_state);
         luaopen_io(d_state);
         luaopen_string(d_state);
@@ -99,7 +96,7 @@
         #if defined(DEBUG) || defined (_DEBUG)
             luaopen_debug(d_state);
         #endif
-    #endif /* CEGUI_LUA_VER >= 51 */
+    #endif /* LUA_VERSION_NUM >= 501 */
 
     setModuleIdentifierString();
 }
@@ -108,7 +105,9 @@
 /*************************************************************************
 	Constructor (uses given Lua state)
 *************************************************************************/
-LuaScriptModule::LuaScriptModule(lua_State* state)
+LuaScriptModule::LuaScriptModule(lua_State* state) :
+    d_errFuncIndex(LUA_NOREF),
+    d_activeErrFuncIndex(LUA_NOREF)
 {
 	// just use the given state
 	d_ownsState = false;
--- CEGUILua.h	Sun Jan 25 18:32:57 2009
+++ CEGUILua.h	Thu Jan 29 10:17:42 2009
@@ -38,7 +38,11 @@
 #   ifdef CEGUILUA_EXPORTS
 #       define CEGUILUA_API __declspec(dllexport)
 #   else
-#       define CEGUILUA_API __declspec(dllimport)
+#       if defined( __MINGW32__ )
+#           define CEGUILUA_API
+#       else
+#           define CEGUILUA_API __declspec(dllimport)
+#       endif
 #   endif
 #else
 #   define CEGUILUA_API
--- CEGUILuaFunctor.cpp	Sun Jan 25 18:32:57 2009
+++ CEGUILuaFunctor.cpp	Thu Jan 29 10:25:48 2009
@@ -40,7 +40,7 @@
 #include "lauxlib.h"
 }
 
-#include "tolua++.h"
+#include "tolua/tolua++.h"
 
 // Start of CEGUI namespace section
 namespace CEGUI
@@ -199,6 +199,10 @@
     bool ret = lua_isboolean(L, -1) ? lua_toboolean(L, -1 ) : true;
     lua_pop(L, 1);
 
+    // remove error handler from stack
+    if (err_idx != 0)
+        lua_remove(L, err_idx);
+
 	if(helper)
 	{
 		delete helper;
