-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lua events not propagating to event handlers outside of the wxLuaState itself #127
Comments
@Zekkers, thank you for the report; this is interesting. I'm not sure why it would behave this way, as there is definitely diff --git a/wxLua/modules/wxlua/wxlstate.h b/wxLua/modules/wxlua/wxlstate.h
index eff8a51..405edba 100644
--- a/wxLua/modules/wxlua/wxlstate.h
+++ b/wxLua/modules/wxlua/wxlstate.h
@@ -792,18 +792,6 @@ public:
lua_Debug *m_lua_Debug;
};
-#if wxCHECK_VERSION(3,0,0)
-wxDEFINE_EVENT(wxEVT_LUA_CREATION, wxLuaEvent);
-wxDEFINE_EVENT(wxEVT_LUA_PRINT, wxLuaEvent);
-wxDEFINE_EVENT(wxEVT_LUA_ERROR, wxLuaEvent);
-wxDEFINE_EVENT(wxEVT_LUA_DEBUG_HOOK, wxLuaEvent);
-#else
-DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_CREATION)
-DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_PRINT)
-DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_ERROR)
-DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_DEBUG_HOOK)
-#endif
-
#if wxCHECK_VERSION(3,0,0)
// A wxLuaState is being created, sent at the end of
// wxLuaState(wxEvtHandler, win id) or Create(wxEvtHandler, win id)
@@ -843,4 +831,16 @@ typedef void (wxEvtHandler::*wxLuaEventFunction)(wxLuaEvent&);
#define EVT_LUA_ERROR(id, fn) wx__DECLARE_WXLUAEVT(wxEVT_LUA_ERROR, id, fn)
#define EVT_LUA_DEBUG_HOOK(id, fn) wx__DECLARE_WXLUAEVT(wxEVT_LUA_DEBUG_HOOK, id, fn)
+#if wxCHECK_VERSION(3,0,0)
+wxDEFINE_EVENT(wxEVT_LUA_CREATION, wxLuaEvent);
+wxDEFINE_EVENT(wxEVT_LUA_PRINT, wxLuaEvent);
+wxDEFINE_EVENT(wxEVT_LUA_ERROR, wxLuaEvent);
+wxDEFINE_EVENT(wxEVT_LUA_DEBUG_HOOK, wxLuaEvent);
+#else
+DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_CREATION)
+DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_PRINT)
+DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_ERROR)
+DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUA_DEBUG_HOOK)
+#endif
+
#endif // _WXLSTATE_H_ |
@Zekkers, BTW, do you have a code sample to test this (when it's working or not working)? |
@Zekkers, do you have any update on this or a sample I can use to test this? Thanks! |
Sorry. I'll try and put something together tomorrow. Completely forgot about this! |
So, under MSVC, trying to move the definitions to the end of the wxlstate.h file results in linker warnings for libraries, and errors for binaries. For library linking, it comes back with warnings:
and for binary linking, comes back with:
Even though the definitions are in an include guard, including the file still implies that you're using the contents. So the compiler will still 'do' what was in there. It just doesn't have to re-parse. So, because wxDEFINE_EVENT generates a public variable I recompiled with the definitions before the declarations, and checked the map file. It shows multiple initialisers, apparently one for each translation unit:
So, to the best of my knowledge, events created in different translation units do not match the ones in the interested party. |
This commit: bde906e breaks static linking and must be reverted. Definitions (wxDEFINE_EVENT) must be in cpp files -> object files -> static archives. |
I recently merged up to the latest wxLua and noticed that I was no longer getting events like wxEVT_LUA_ERROR which I capture to log and display.
I checked the diff of the merge and noticed the changes from commit bde906e39b19f5179c66c44c9b681f40bf4475e0 . I reverted just that commit in my own repo, and the events started working again.
The frame in question is largely based on the wxLuaStandaloneApp with respect to the event handling.
Looks like wxDEFINE_EVENT calls in wxlstate.h could be executed multiple times if included by different modules, so the event IDs are not matching.
The text was updated successfully, but these errors were encountered: