pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.61k stars 519 forks source link

How do you pass xpm data into `wxStyledTextCtrl MarkerDefinePixmap` call? #1186

Open greatwolf opened 2 weeks ago

greatwolf commented 2 weeks ago

I'm not sure whether to ask this on here or on wxLua. I'm trying to change the way the breakpoint icon looks on the left margin gutter of the editor and it looks like SCI_MARKERDEFINEPIXMAP is what I'm after.

The corresponding wxlua binding is here https://github.com/pkulchenko/wxlua/blob/4d83c8d44eeccf88683ca0146a13b16d0b0d4264/wxLua/bindings/wxwidgets/wxstc_override.hpp#L86.

What's unclear to me is how to actually pass in that xpm data as const char ** from the lua side. Been banging my head against the wall trying to figure this out. I looked at https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/binding.md and https://github.com/pkulchenko/wxlua/blob/master/wxLua/docs/wxlua.md. Closest thing I could find is this section:

userdata : A pointer to a C/C++ object.

A metatable (see Lua documentation) may be assigned to it to allow it to act as a table or be called as a function, among other things. wxLua uses userdata types to wrap the wxWidgets C++ objects to make them useable in a Lua program.

I also looked at some of the wxlua samples like https://github.com/pkulchenko/wxlua/blob/4d83c8d44eeccf88683ca0146a13b16d0b0d4264/wxLua/samples/calculator.wx.lua#L242 and https://github.com/pkulchenko/wxlua/blob/4d83c8d44eeccf88683ca0146a13b16d0b0d4264/wxLua/samples/catch.lua#L601 hoping for some usage hints.

Those examples turn xpm, represented as a table from the lua side, into a wxBitmap and then wxIcon. But using wxBitmap and wxIcon is not a suitable userdata because MarkerDefinePixmap wants to turn it into a const char* const*. I've tried passing it in as a plain lua string, as a lua table, wxBitmap, wxIcon. None of it seems to work.

It feels like I'm missing something simple but what actually is the suitable userdata I should be using here?

pkulchenko commented 2 weeks ago

I suspect you may be right, as it looks like a direct translation of the API without a good way to provide that parameter. In fact, other interface files have comments to the effect that wxlua doesn't handle const char* const* parameters.

Would using MarkerDefineRGBAImage or MarkerDefineBitmap work (the latter is not available with wxwidgets 3.1.3+)?

I think it will be better to change MarkerDefinePixmap(int markerNumber, const char* const* xpmData); to MarkerDefinePixmap(int markerNumber, const char* xpmData); to allow passing a string with xpmData content.

greatwolf commented 2 weeks ago

I'll have to take a look at MarkerDefineRGBAImage and MarkerDefineBitmap -- those could probably work. I was looking at MarkerDefinePixmap because scintilla provides some icons https://www.scintilla.org/Icons.html and they're in xpm format.

That said, the current MarkerDefinePixmap does seem like a design defect if there isn't a convenient way to use it from lua side. Changing it to accept either a lua string or lua table seems to make sense to me.