Murga-Projects Forums
Fluid to lua converter - Printable Version

+- Murga-Projects Forums (http://www.murga-projects.com/forum)
+-- Forum: Project Forums (/forumdisplay.php?fid=1)
+--- Forum: MurgaLua - General (/forumdisplay.php?fid=2)
+--- Thread: Fluid to lua converter (/showthread.php?tid=258)


Fluid to lua converter - Tobi - 12-19-2007 07:55 AM

Hey folks,

I thought you might be interested in this little fluid file (.fl) to Lua script (.lua) converter I made.
You can download it here: http://www.igame3d.de/fluid_parser.zip

Build and run instructions are included.

The advantage is that you won't need to export .cxx and .h files from fluid anymore and don't have to use the cxx to murga converter script. It's just one step less but worth it.

Please post your comments Wink

Tobi


RE: Fluid to lua converter - iGame3D - 12-19-2007 12:33 PM

There's a bug with textcolor at the moment
May be other bugs where the translator doesn't write the file


RE: Fluid to lua converter - Tobi - 12-20-2007 01:38 AM

Ok, added textcolor, selection_color and labelfont.

When the parser does not recognize an attribute, it will put that a comment in the lua file and might break at that point.

New parser online at same link

iGame3D Wrote:
There's a bug with textcolor at the  moment
May be other bugs where the translator doesn't write the file




RE: Fluid to lua converter - xleitex - 12-24-2007 07:06 AM

Hi...

Im trying to compile but...i got some errors

Code:
C:\>cd f2l

C:\f2l>gcc lex.yy.c -o fluidtolua.exe
In file included from fluid.l:20:
y.tab.c:6: error: syntax error before string constant
y.tab.c:6: warning: data definition has no type or storage class

C:\f2l>


if i coment the line 6 on y.tab.c it compile but when i execute it gime errors...
its the line

Code:
3 | #if 0
4 | static char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
5 | #else
6 | //__IDSTRING(yyrcsid, "$NetBSD: skeleton.c,v 1.14 1997/10/20 03:41:16 lukem Exp $");
7 | #endif


curiously, my GCC compiler doesnt have the cdefs.h header on its include folder
so i copy one where i found on koders site
i dont know what to do...its my first C compilation ! Smile

Some stuffs...
Win xp sp2, mingw 5.1.3, GCC 3.4.5

Thx in advanced...sorry for my poor inglish


RE: Fluid to lua converter - iGame3D - 12-26-2007 11:16 AM

Tobi will try to provide a binary, there's probably an issue between mac and pc gcc.
Or he might come up with a fix. Be patient.

If you really can't wait, try checking iGame3D out from SVN.
In theory you should be able to drag and drop to convert fluids to lua
Instructions for Checkout

If drag and drop doesn't work, open the app, hit control T to get the console, and dofile with the path to the fluid, that should get you where you need to be.


RE: Fluid to lua converter - Tobi - 12-27-2007 09:52 PM

OK, I tried compiling it on another windows machine with MSYS and got the same erros, dunno why it worked on that other machine but whatever, it's now fixed.

The source is updated now and a windows executable is now shipping with it as well.

You can find the fluid to lua converter here:

http://www.igame3d.de/fluid_parser.zip

Greetings,

Tobi


RE: Fluid to lua converter - Tobi - 01-29-2008 08:14 AM

There's a new version with windows and mac binary.
It now handles groups correctly!
Link is still: http://www.igame3d.de/fluid_parser.zip

Tobi


Fluid to lua converter update - iGame3D - 02-06-2008 09:33 AM

Jan. 05 2008
Labelcolor support in the parser is fixed.
Free C Source Code Updated.

http://www.igame3d.de/fluid_parser.zip


RE: Fluid to lua converter - JohnMurga - 02-06-2008 08:15 PM

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.

The same is true for images, which fluid embeds by default, and can now be mime encoded and then decoded for use in FL_Image creation.

Also, why does fluidtolua define so many variables at the start ?

Anyway, what would be REALLY cool would be to be able to integrate this into murgaLua in a way that you could do something like :

Code:
-- Loads .fl file, converts to lua and runs it (without the show/run)
  murgaLua.loadFluidGUI("test.fl")
  -- Assign callbacks to be used
  myFirstButton:callback(something) -- myFirstButton is name from .fl file.
  window:show()
  Fl:run()


Then, when developing an app you could just change the layout of your window without having to change your code ... Separating presentation from application logic :-)

What do you think ?

Cheers
JohnM


RE: Fluid to lua converter - Tobi - 02-08-2008 01:50 AM

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.

Quote:
The same is true for images, which fluid embeds by default, and can now be mime encoded and then decoded for use in FL_Image creation.

Also, why does fluidtolua define so many variables at the start ?


I haven't tried images yet, but it should be quite simple to put in as well.
All those variables in the start are used because fluid saves symbolic names of widget and property types to the .fl files that need to be mapped to integer constants to use in fltk or murgalua. The .cxx export handles the mapping but when we work on .fl files directly we need to take care of that ourselves. These variables do this mapping. In future versions we could as well get rid of the variables and do the symbol to integer resolution in the parser itself.

Quote:
Anyway, what would be REALLY cool would be to be able to integrate this into murgaLua in a way that you could do something like :

Code:
  -- Loads .fl file, converts to lua and runs it (without the show/run)
  murgaLua.loadFluidGUI("test.fl")
  -- Assign callbacks to be used
  myFirstButton:callback(something) -- myFirstButton is name from .fl file.
  window:show()
  Fl:run()


Then, when developing an app you could just change the layout of your window without having to change your code ... Separating presentation from application logic :-)

What do you think ?

Cheers
JohnM



Sounds really cool! It's also easy for the parser to remember the windows in a fluid file and show them after creation. Adding Fl:run() is trivial Wink

There's quite some exams stress at the moment, I think we can take care of that after February, 17th Big Grin

Keep up the good work,

Tobi


RE: Fluid to lua converter - Juergen - 02-08-2008 03:40 AM

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


RE: Fluid to lua converter - mikshaw - 02-08-2008 07:23 AM

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


RE: Fluid to lua converter - Juergen - 02-08-2008 09:15 AM

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


RE: Fluid to lua converter - mikshaw - 02-08-2008 10:55 AM

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.


RE: Fluid to lua converter - iGame3D - 02-15-2008 02:30 PM

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?


RE: Fluid to lua converter - Tobi - 04-23-2008 04:35 AM

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