Murga-Projects Forums

Full Version: Adding and Extending Widgets
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
After seeing Juergen's demonstration of extending widgets with new methods, and William's post about adding new widgets, I went back to the FLTK documentation about subclassing hoping I could translate this to murgaLua. Unfortunately I know nothing about C++ and not enough about Lua to do the translation, or even to learn if it's possible to do this with Lua.

Would anyone be willing to put forward a guess as to whether it's possible to use murgaLua to create a new subclass of Fl_Widget, maybe by putting together a collection of existing widgets?

mikshaw Wrote:
After seeing Juergen's demonstration of extending widgets with new methods, and William's post about adding new widgets, I went back to the FLTK documentation about subclassing hoping I could translate this to murgaLua. Unfortunately I know nothing about C++ and not enough about Lua to do the translation, or even to learn if it's possible to do this with Lua.

Would anyone be willing to put forward a guess as to whether it's possible to use murgaLua to create a new subclass of Fl_Widget, maybe by putting together a collection of existing widgets?


No you can't do the same as in C++ just by adding or changing a few functions/methods from within Lua. But you can of course do some pseudo OO programming with Lua and it would be possible with some metatable magic and a few proxy functions to define something like subclasses (although in a limited fashion).
For example:

Code:
Fl_Menu_Bar.callback_old=Fl_Menu_Bar.callback
function Fl_Menu_Bar:callback(cb) print("New callback!") self:callback_old(cb) end

You will see the message when you call menu:callback(my_cb) but not when you call menu:add("item",0,my_cb)

There are a lot of places and quirks that have to be insert to make subclassing in Lua useful.

Although it might be interesting to do some further research.

Juergen

Reference URL's