Murga-Projects Forums

Full Version: Fluid to lua converter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

Tobi Wrote:

JohnMurga Wrote:
Hi,

I was playing with the fluid_parser and I was wondering how easy it would be to change it so that it is able to cope with menu entries, as murgaLua 0.6 can now has all the same functionality as FLTK.


Oh, it's easy to do that. I thought it already works, but now it turns out that Fluid does widgets of type "MenuItem" which the fluid converter tries to build. There is no widget type MenuItem though, menu items need to be done with menu:add()...
Should be quite straightforward to fix.


I'm not completely sure, but I guess you mean arrays of the struct Fl_Menu_Item, because there is no "type" "MenuItem".

Yes the Fl_Menu_Bar:copy() and Fl_Menu_Bar:menu() methods don't work as expected (At least I think so).

But the Fl_Menu_Bar:copy() method can easily be emulated from Lua:

Code:
function Fl_Menu_Bar:copy(MI_table)
for _,j ipairs(MI_table) do self:add(j[1],j[2],j[3],j[4],j[5],j[6]) end
end

menu_table={{"File/close",0,nil},{"File/test",0,nil}}

menu_bar=fltk.Fl_Menu_Bar(0,0,w1:w(),30)
menu_bar:copy(menu_table)


Of course this is quite a hack, but it works surprisingly well.

Juergen

Quote:
function Fl_Menu_Bar:copy(MI_table)

Holy crap. I had never considered the possibility that you could define methods like this. That's really sweet!

Quote:
Fl_Menu_Bar:copy() and Fl_Menu_Bar:menu() methods don't work as expected

I've played with menu() a little bit, but not in the typical way. I created a menu bar and used pointers to parts of it to populate other menus with my_new_menu:menu(pointer). It was actually pretty confusing t keep track of so I didn't take it very far, but it seemed to be the only way to create multiple menu bars without using FL_Menu_Item

mikshaw Wrote:

Quote:
function Fl_Menu_Bar:copy(MI_table)

Holy crap. I had never considered the possibility that you could define methods like this. That's really sweet!

Fl_Menu_Bar is just a table. When the __index metafunction for the userdata basically gives back all entries of the original Fl_... table.

mikshaw Wrote:

Quote:
Fl_Menu_Bar:copy() and Fl_Menu_Bar:menu() methods don't work as expected

I've played with menu() a little bit, but not in the typical way. I created a menu bar and used pointers to parts of it to populate other menus with my_new_menu:menu(pointer). It was actually pretty confusing t keep track of so I didn't take it very far, but it seemed to be the only way to create multiple menu bars without using FL_Menu_Item

I guess you are talking about C++ experiments?
You can create multiple menu_bars and use hide() and show().

Juergen

Quote:
I guess you are talking about C++ experiments?

No, I'm not yet what I consider a programmer. I learned limited scripting in various languages out of necessity...initially for job security and then from need to have control of my operating system. That has spilled into using Lua for fun and education, but I still have much to learn about the fundamentals of programming in general.
Anyway...when I mentioned pointers I was talking about the find_item() method.

This is the sort of thing I was talking about:

Code:
function menu_callback()
if menu2:text()=="&disable item3" then toggle_item:deactivate()
elseif menu2:text()=="&enable item3" then toggle_item:activate()
end
menu1:redraw()
end

window = fltk:Fl_Window(400, 200, "menu test")
main_menu=fltk:Fl_Menu_Button(0,0,0,0)
menu1=fltk:Fl_Menu_Bar(0,0,400,30)
menu2=fltk:Fl_Menu_Bar(0,40,400,30)

main_menu:add("menu1/item1")
main_menu:add("menu1/item2")
main_menu:add("menu1/&item3/item3a")
main_menu:add("menu1/&item3/item3b")
main_menu:add("menu1/item4")
main_menu:add("menu2/&File/item5")
main_menu:add("menu2/&File/item6")
main_menu:add("menu2/&File/item7")
main_menu:add("menu2/&File/&enable item3")
main_menu:add("menu2/&File/&disable item3")

menu1menu=main_menu:find_item("menu1/item1")
menu2menu=main_menu:find_item("menu2/&File")
menu1:menu(menu1menu)
menu2:menu(menu2menu)
toggle_item=menu1:find_item("&item3")
menu2:callback(menu_callback)
window:show()
Fl:run()

When using add() to multiple menu bars, they basically all stopped responding.

Found another bug in Fluid to Lua.
It doesn't handle the browsers properly.
Setting its w:type to FLUID_Select.

Which is obviously not right.
I tried plugging everything into that type value but nothing makes
the browser work correctly.

Until, I used the cxx to lua script which revealed the type value should be (1).

Where do we keep these enumerations?
There is a new version of the Fluid parser available here.

1. It now automatically adds instructions for showing windows and also puts in Fl:run()

2. There is basic support of menu bars. See the test.fl as an example. The shortcuts for menu items don't work right just yet.

3. The huge amount of constants at the start of generated .lua files is now gone.

4. It ships with a Makefile for easier building as well as Mac and Windows executables

Have fun with this!
Big Grin
Tobi
Pages: 1 2
Reference URL's