pkulchenko / wxlua

wxlua: Lua bindings for wxWidgets cross-platform GUI toolkit; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and wxWidgets 3.x
306 stars 59 forks source link

wxArtProvider don't work because wxLuaBindString error #87

Closed starwing closed 3 years ago

starwing commented 3 years ago

hi,

I build the wx.dll on Windows, but in every Lua samples, the icons are all disappear. After some study it seems that to solve this may much difficult than I think :-(

It's all because the wxART_XXX macro returns a wxString! which is a temporary object, and assign to the c_string/wxchar_string field of wxLuaBindString, and all string content that pushed into Lua become rubbish.

Haven't any idea about how to solve this ...

pkulchenko commented 3 years ago

@starwing, you'll have to provide a bit more information, as I'm building wxlua on Windows regularly as well, but haven't seen this issue with icons. What version of wxlua and wxwidgets are you using? What's the command line for cmake? What specific application did you test and can you attach a screenshot with missing icons?

The icons are usually loaded with something like wx.wxArtProvider.GetBitmap(wx.wxART_NEW, wx.wxART_TOOLBAR), where wx.wxART_NEW contains a string "wxART_NEW" and wx.wxART_TOOLBAR contains a string "wxART_TOOLBAR_C". GetBitmap call should return wxBitmap object. I don't see any issue so far, as it does return that object for me.

starwing commented 3 years ago

I use wxWidgets 3.1.4, before this commit.

First I'm trying to use GitHub head of wxWidgets, but it fails with link error with wxPlatfrom::GetArchName(), so I turned used the 3.1.4 version release package.

I'll try the git HEAD again, after re-generate the new bindings...

starwing commented 3 years ago

Update: I have been OK with the git HEAD of wxWidgets! after some changes to bindings. It seems not the fault of bindings, wxWidgets head missing wxPlatformInfo::GetArchName() routine, so I commented out the binding line:

https://github.com/pkulchenko/wxlua/blob/c42cd091948bb1248f9a3352c1ea0df7e5f34ea2/wxLua/modules/wxbind/src/wxbase_base.cpp#L288

With:

    wxString returns = ""; // (wxPlatformInfo::GetArchName(arch));

and it just works!

starwing commented 3 years ago

After some research I found that because wxWidgets 3.1.5 deprecate the GetArchName routine.

This is the patch to fix this:

diff --git a/wxLua/bindings/wxwidgets/wxbase_base.i b/wxLua/bindings/wxwidgets/wxbase_base.i
index c09f59b..1f295fd 100644
--- a/wxLua/bindings/wxwidgets/wxbase_base.i
+++ b/wxLua/bindings/wxwidgets/wxbase_base.i
@@ -209,6 +209,16 @@ enum wxPortId
     wxPORT_DFB           // wxDFB, using wxUniversal
 };

+%wxchkver_3_1_5 enum wxBitness
+{
+    wxBITNESS_INVALID = -1,        //!< returned on error
+
+    wxBITNESS_32,                  //!< 32 bit
+    wxBITNESS_64,                  //!< 64 bit
+
+    wxBITNESS_MAX
+};
+
 enum wxArchitecture
 {
     wxARCH_INVALID,         // returned on error
@@ -252,7 +262,8 @@ class wxPlatformInfo
     static wxString GetPortIdName(wxPortId port, bool usingUniversal);
     static wxString GetPortIdShortName(wxPortId port, bool usingUniversal);

-    static wxString GetArchName(wxArchitecture arch);
+    !%wxchkver_3_1_5 static wxString GetArchName(wxArchitecture arch);
+    %wxchkver_3_1_5 static wxString GetBitnessName(wxBitness bitness);
     static wxString GetEndiannessName(wxEndianness end);

     int GetOSMajorVersion() const;
@@ -275,7 +286,8 @@ class wxPlatformInfo
     wxString GetOperatingSystemIdName() const;
     wxString GetPortIdName() const;
     wxString GetPortIdShortName() const;
-    wxString GetArchName() const;
+    !%wxchkver_3_1_5 wxString GetArchName() const;
+    %wxchkver_3_1_5 wxString GetBitnessName() const;
     wxString GetEndiannessName() const;

     void SetOSVersion(int major, int minor);
pkulchenko commented 3 years ago

Thanks! Should be fixed now.