1. The Big Project I was working on

Hello,

I was recently working a big project. A wrapper if you will. It was a wrapper of FTLK. I had found a C port of FLTK. I had used that as a basis for the project. However after finding some issues with it, I'm unsure if I'm able to continue with it. A lot of functions have been wrapped and there are many more that need to be wrapped.

The C port of FLTK was based on this. https://github.com/MoAlyousef/cfltk

It is not very well documented. In fact the github repo says you can follow along with the official CPlusPlus FLTK Docs. This is possible, but it is also harder to read and adjust for a more pure C code approach. Also, according to the DLL, there are over 9,000 functions.

--Snippet of some Wrapper Code 
public constant xFl_Window_new = define_c_func(fltk,"+Fl_Window_new",{C_INT,C_INT,C_INT,C_INT,C_POINTER},C_POINTER) 
 
public function Fl_Window_new(atom x,atom y,atom w,atom h,sequence title) 
 
 atom str = allocate_wstring(title,1) 
  
 return c_func(xFl_Window_new,{x,y,w,h,str}) 
	 
end function 
 
public constant xFl_Window_end = define_c_proc(fltk,"+Fl_Window_end",{C_POINTER}) 
 
public procedure Fl_Window_end(atom w) 
 
 c_proc(xFl_Window_end,{w}) 
	 
end procedure 
 
public constant xFl_Window_show = define_c_proc(fltk,"+Fl_Window_show",{C_POINTER}) 
 
public procedure Fl_Window_show(atom w) 
 
 c_proc(xFl_Window_show,{w}) 
	 
end procedure 
 
public constant xFl_Button_new = define_c_func(fltk,"+Fl_Button_new",{C_INT,C_INT,C_INT,C_INT,C_POINTER},C_POINTER) 
 
public function Fl_Button_new(atom x,atom y,atom w,atom h,sequence title) 
 
 atom str = allocate_string(title,1) 
  
 return c_func(xFl_Button_new,{x,y,w,h,str}) 
	 
end function 
--Example program 
include std/machine.e 
include std/dll.e 
 
include EuFLTK.ew 
 
Fl_init_all() 
 
atom win = Fl_Window_new(100,100,600,400,"Example Win") 
atom bar = Fl_Box_new(0,0,600,60,"FTLK") 
 
atom btn = Fl_Button_new(600 - 100, 400 - 100, 100,20,"Hello") 
 
Fl_Box_set_box(bar,Fl_BoxType_FlatBox) 
 
Fl_Window_end(win) 
Fl_Window_show(win) 
 
Fl_background(255,255,255) 
 
public function Return_Fl() 
 
 return Fl_run() 
	 
end function 
 
Return_Fl() 

AS you can see that text does not display cleary. At this point it is stuck in limbo until I decide to try to finish or abandon it. I am curious to hear what you guys think.

https://i.ibb.co/PNHRyq6/fltk.png

new topic     » topic index » view message » categorize

2. Re: The Big Project I was working on

Always a difficult one isn't it. To tell someone that it's not worthwhile. It undoubtedly is worthwhile, to you and anyone that wants to use it. But I would ask myself the question how much work do you want to put in to something that you would use as a tool / how much you would use the toolkit in the future, and how much other people would actually benefit from it, and how much you would be distracted from other projects. So it's a cost : reward analysis. To me, with the Eu user base as it is, with the existing toolkits, with the likely use that it's going to have, sounds like a lot of work to me.

Having said that, if it's a mountain to you, to climb because it's there, then go for it. You have the skills to do so.

Not much help, but no one will have a 'right' answer for you.

Why don't you do a poll?

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

3. Re: The Big Project I was working on

It's a tremendous amount of work, even when the documentation is good.

That said, if you treat it as a learning experience and mental exercise, you will benefit by learning a lot about C and C++, as well as Eu.

The thing that would benefit the Euphoria community as a whole would be to write the next "killer app" that everyone must have, in Euphoria. Unfortunately, I don't know what that would be.

new topic     » goto parent     » topic index » view message » categorize

4. Re: The Big Project I was working on

Well with the text not being displayed correctly, it doesn't seem like it is worthwhile to continue working on it at this point. However if that can be fixed, then I might continue with it. I already have plenty of other projects I am working on and continue to update. As of now this project will be stuck on limbo.

Note the text does not display correctly on controls like buttons nor does it display correctly in window title bars.

new topic     » goto parent     » topic index » view message » categorize

5. Re: The Big Project I was working on

I looked at the 1.4 manual
There are 330 functions there. I am not a DLL wrapping person, but it seems strange that the DLL should have 9000 functions
I counted 330 as below
https://www.fltk.org/doc-1.4/modules.html

 Callback function typedefs 13
Windows handling functions 9
Events handling functions 37
Selection & Clipboard functions 9
Screen functions 18
Color & Font functions 34
Drawing functions 104
Multithreading support functions 5
Safe widget deletion support functions 5
Cairo Support Functions and Classes 7
Unicode and UTF-8 functions 47
Mac OS X-specific symbols 3
Common Dialogs classes and functions 24
File names and URI utility functions 14
Fl_string 1

Total functions 330

new topic     » goto parent     » topic index » view message » categorize

6. Re: The Big Project I was working on

Bhupen1277 said...

I looked at the 1.4 manual
There are 330 functions there. I am not a DLL wrapping person, but it seems strange that the DLL should have 9000 functions
I counted 330 as below
https://www.fltk.org/doc-1.4/modules.html

 Callback function typedefs 13
Windows handling functions 9
Events handling functions 37
Selection & Clipboard functions 9
Screen functions 18
Color & Font functions 34
Drawing functions 104
Multithreading support functions 5
Safe widget deletion support functions 5
Cairo Support Functions and Classes 7
Unicode and UTF-8 functions 47
Mac OS X-specific symbols 3
Common Dialogs classes and functions 24
File names and URI utility functions 14
Fl_string 1

Total functions 330

Keep in mind that FLTK is a CPlusPlus library. This is a C port of the library. So everything that was put into classes is now handled as a separate function. If that makes sense. Granted when I viewed the exported DLL functions, I noticed not everything in there needs to be wrapped. So its probably less than 9k, but it is still a ton.

new topic     » goto parent     » topic index » view message » categorize

7. Re: The Big Project I was working on

Icy_Viking said...

Keep in mind that FLTK is a CPlusPlus library. This is a C port of the library. So everything that was put into classes is now handled as a separate function. If that makes sense. Granted when I viewed the exported DLL functions, I noticed not everything in there needs to be wrapped. So its probably less than 9k, but it is still a ton.

There are 73 classes defined using the WIDGET_DECLARE macro in include/cfl_widget.h which itself declares 74 functions per widget, so that's at least 5,402 functions, plus whatever else is declared manually.

I usually search shared libraries using nm -D (for dynamic symbols) and then filter with grep " T " (for text-only symbols). In this case you'll want to exclude all of the C++ exports which are name-mangled with _Z... and just look for the Fl_... functions. Running this filter: nm -D bin/libcfltk.so.1.0.16 | grep -c " T Fl_" I get 7,805 functions. Oof.

Also, if you're looking to build a shared library for CFLTK, the author recently posted the full cmake command here: https://github.com/MoAlyousef/cfltk/issues/184#issuecomment-812943830

cmake -B bin -S . -DCMAKE_BUILD_TYPE=Release -DOPTION_USE_SYSTEM_LIBPNG=OFF -DOPTION_USE_SYSTEM_LIBJPEG=OFF -DOPTION_USE_SYSTEM_ZLIB=OFF -DOPTION_USE_GL=OFF -DFLTK_BUILD_EXAMPLES=OFF -DFLTK_BUILD_TEST=OFF -DOPTION_USE_THREADS=ON -DOPTION_LARGE_FILE=ON -DOPTION_BUILD_HTML_DOCUMENTATION=OFF -DOPTION_BUILD_PDF_DOCUMENTATION=OFF -DCFLTK_BUILD_SHARED=ON -DCFLTK_LINK_IMAGES=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DOPTION_BUILD_SHARED_LIBS=ON 

Since most of this is generated using macros, you should be able to create a wrapper script that does most of the work. I can help with this if you'd like. I've recently been fiddling with the one I made for IUP but then I was reminded if how I don't really like IUP.

-Greg

new topic     » goto parent     » topic index » view message » categorize

8. Re: The Big Project I was working on

Icy_Viking said...
--Snippet of some Wrapper Code 
public constant xFl_Window_new = define_c_func(fltk,"+Fl_Window_new",{C_INT,C_INT,C_INT,C_INT,C_POINTER},C_POINTER) 
 
public function Fl_Window_new(atom x,atom y,atom w,atom h,sequence title) 
 
 atom str = allocate_wstring(title,1) 
  
 return c_func(xFl_Window_new,{x,y,w,h,str}) 
	 
end function 

AS you can see that text does not display cleary. At this point it is stuck in limbo until I decide to try to finish or abandon it. I am curious to hear what you guys think.

It looks like the title parameter of Fl_Window_new() is declared as const char* so you need to use allocate_string() (for 8-bit chars) not allocate_wstring() (for 16-bit wchars).

#define WIDGET_DECLARE(widget)                                                                     \ 
    typedef struct widget widget;                                                                  \ 
    widget *widget##_new(int x, int y, int width, int height, const char *title);                  \ 
    int widget##_x(widget *);                                                                      \ 
    int widget##_y(widget *);                                                                      \ 
    int widget##_width(widget *);                                                                  \ 
    int widget##_height(widget *);                                                                 \ 
    const char *widget##_label(widget *);                                                          \ 
    ... 

-Greg

new topic     » goto parent     » topic index » view message » categorize

9. Re: The Big Project I was working on

ghaberek said...
Icy_Viking said...
--Snippet of some Wrapper Code 
public constant xFl_Window_new = define_c_func(fltk,"+Fl_Window_new",{C_INT,C_INT,C_INT,C_INT,C_POINTER},C_POINTER) 
 
public function Fl_Window_new(atom x,atom y,atom w,atom h,sequence title) 
 
 atom str = allocate_wstring(title,1) 
  
 return c_func(xFl_Window_new,{x,y,w,h,str}) 
	 
end function 

AS you can see that text does not display cleary. At this point it is stuck in limbo until I decide to try to finish or abandon it. I am curious to hear what you guys think.

It looks like the title parameter of Fl_Window_new() is declared as const char* so you need to use allocate_string() (for 8-bit chars) not allocate_wstring() (for 16-bit wchars).

#define WIDGET_DECLARE(widget)                                                                     \ 
    typedef struct widget widget;                                                                  \ 
    widget *widget##_new(int x, int y, int width, int height, const char *title);                  \ 
    int widget##_x(widget *);                                                                      \ 
    int widget##_y(widget *);                                                                      \ 
    int widget##_width(widget *);                                                                  \ 
    int widget##_height(widget *);                                                                 \ 
    const char *widget##_label(widget *);                                                          \ 
    ... 

-Greg

The text still doesn't display correctly. I've tried using allocate_string and allocate_wstring().

new topic     » goto parent     » topic index » view message » categorize

10. Re: The Big Project I was working on

Icy_Viking said...

The text still doesn't display correctly. I've tried using allocate_string and allocate_wstring().

It's possible that the library is not making a local copy of the string so it's just reading garbage from a dangling pointer.

Try removing the ,1 from allocate_string() so it won't auto-free the memory and see if that fixes it.

-Greg

new topic     » goto parent     » topic index » view message » categorize

11. Re: The Big Project I was working on

ghaberek said...
Icy_Viking said...

The text still doesn't display correctly. I've tried using allocate_string and allocate_wstring().

It's possible that the library is not making a local copy of the string so it's just reading garbage from a dangling pointer.

Try removing the ,1 from allocate_string() so it won't auto-free the memory and see if that fixes it.

-Greg

What do you know, that fixed it. Still this is still a massive project to take on. Should I still free the meomry using free()?

EDIT: I found using free doesn't make the text scrambled. So its fine to use.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu