News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
MurgaLua full release
Author Message
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #1
RE: MurgaLua full release

JohnMurga Wrote:

Juergen Wrote:
Yes it is ;-)
I overlooked that. Although there is a small misunderstanding.
menu:find_item(first_item) and menu:menu(0) is exactly the same, but for the latter you don't have to know what the first item is. If you check if there are 0 arguments supplied to the menu() function and then execute the same code that menu(0) does, it would be nearer to the fltk documentation.


Yes ... And ... No ...

The FLTK version would return a pointer that you could increment to get the next item. I cannot sensibly reproduce that in Lua, so I rather just have a slightly different method.

I think there is still a misunderstanding. I was talking purely about syntax not semantics!
As long as there is no complete documentation for MurgaLua, users have to refer to the fltk documentation. Therefore it isn't a good idea to unnecessarily differ from the FLTK behavior, especially when it is such a small difference.

The expected behavior can be restored if you do the following change:

Code:
int lua_call1_Fl_Menu___menu(lua_State * __S__)
{
   int nparam = lua_gettop(__S__);
   int __ERROR__ = 0;
-  if (nparam < 1) goto error;
+  if (nparam < 1) lua_pushnumber(__S__,0);
   {
      class Fl_Menu_ * __self__;
    
     __self__ = ( class Fl_Menu_ * )lua_to_Fl_Menu_(__S__, 1, &__ERROR__);


Which is a trivial change.

Also the userdata with the metatable isn't that different from the C++ behavior. If you want, you can add the __add meta method to get the increment behavior.


JohnMurga Wrote:
Right now ... You cannot ... In normal use the only instance I can see you wanting a reference to the menu would be if you want to change it from a menu item ... If so, there are several ways for you to hold a reference to the menu (I'll knock up and example).

I do not like the way FLTK handles it, as menu items are second class citizens (being low level structs). In murgaLua it's different, although I'll address your usage pattern and find a way to get it to make sense.

In some applications there are more then one menu. There may be multiple menu bars (sometimes there are multiple windows, like a small text editor for example), there could be multiple menu buttons or context menus. They can of course share the menu_item class/structure. For some functionality it is necessary to change the menu or access the parent widget or window.

The Fl_Menu_Item class is nothing more than a helper class to manipulate the Fl_Menu_Item structure. There is no functionality in the Fl_Menu_Item methods (except for do_callback) that you couldn't get by directly manipulating the Menu_Item structure. They are purely for convenience and compatibility. There are also the add, replace and methods in Fl_Menu_ that can be used to manipulate the menu.

Therefore the Menu_Item callback is just the same as the Menu callback but finer grained. It doesn't really make sense to provide a pointer to the menu_item to the callback.


JohnMurga Wrote:

Juergen Wrote:
Is there an example somewhere that doesn't throw an error message or a segmentation fault?


The previous menu example worked, although you (rightly) complained about it :-)

I'll code some more, although what I'd REALLY like to see are examples that DO cause error messages or segfaults, as that way I can either address the bug or explain what's wrong with the example.


I always get segmentation faults or a message that Lua can't index a nil value.

I didn't look into the code, but when I saw the double quotes in the original example it looked like you are compiling a binary chunk and calling it later.

I have an alternative suggestion. A few weeks ago I did a small user_data replacement implementation in pure Lua:

Code:
Fl_Button.udata={}


Fl_Button.user_data_old=Fl_Button.user_data

function Fl_Button:user_data(...)
local arg={...}
if #arg<1 then return self.udata[self]
   else self.udata[self]=arg[1]
end
end


It is simple, works with all values (also functions or tables). I guess it isn't hard to do it in C++ with some metatable magic and hide the table somewhere.

Juergen

02-13-2008 12:29 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
MurgaLua full release - JohnMurga - 01-29-2008, 12:32 AM
RE: MurgaLua full release - Juergen - 01-29-2008, 01:53 AM
RE: MurgaLua full release - iGame3D - 01-29-2008, 03:31 AM
RE: MurgaLua full release - JohnMurga - 01-29-2008, 08:47 AM
RE: MurgaLua full release - JohnMurga - 02-11-2008, 10:02 AM
RE: MurgaLua full release - JohnMurga - 02-12-2008, 09:54 AM
RE: MurgaLua full release - Juergen - 02-11-2008, 10:41 AM
RE: MurgaLua full release - JohnMurga - 02-11-2008, 11:09 AM
RE: MurgaLua full release - Juergen - 02-11-2008, 11:30 AM
RE: MurgaLua full release - JohnMurga - 02-12-2008, 09:47 AM
RE: MurgaLua full release - JohnMurga - 02-13-2008, 10:16 AM
RE: MurgaLua full release - Juergen - 02-13-2008 12:29 PM
RE: MurgaLua full release - JohnMurga - 02-14-2008, 11:46 PM
RE: MurgaLua full release - Juergen - 02-18-2008, 08:55 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: