first, some questions about pointer
question 1
void Fl_Widget_TrackerDelete(Fl_Widget_Tracker* & wt);
c2nim says Error: token expected: )
question 2
void flFileChooserCallback(void(*cb)(const char* f));
c2nim says
proc flFileChooserCallback*(cb: proc (f: cstring))
but where the * before cb has gone?
question 3 how to judge a pointer points to NULL? currently I use
if ans == cast[pointer](0):
but I am not sure whether is this safe or not. And I don't really like to write this long code every time. In FreeBasic, it can be written as
if ans = 0 then ' in BASIC, one `=` can be used to comparison too
question 4 in many FreeBasic code, any ptr can be used like
sub TreeCB cdecl (byval wgt as Fl_Widget ptr,byval tree as any ptr) ' this is the callback function
dim as Fl_Tree_Item ptr item = Fl_TreeGetCallbackItem(tree)
do something
end sub
then
var tree = Fl_TreeNew(10,20,300,170,"Fl_Tree")
Fl_WidgetSetCallbackArg(tree,@TreeCB,tree) ' setup a callback for the treeview
What I do in nim:
proc TreeCB (self: ptr Fl_Widget, tree: ptr Fl_Tree){.cdecl.} =
var item = Fl_TreeGetCallbackItem(tree)
do something
var tree = Fl_TreeNew(10, 20, 300, 170, "Fl_Tree")
Fl_WidgetSetCallbackArg(tree, TreeCB, tree) # setup a callback for the treeview
var item = Fl_TreeGetCallbackItem(cast[ptr Fl_Tree](tree))
thanks
We are not in your head nor do we have the C (or Basic?) source code in front of us. So if you throw some code line at us without any context it'll be hard for us to help you. Also note that the intersection of Nim and Basic developers is probably very small (as opposed to Nim and C) so asking questions along the line "In Basic it's done like that. How in Nim?" will risk to severely limit the set of people willing and capable to help you.
As for your question 2: Nim knows that proc is obviously about an address.
Thanks
I don't mean to throw tons of code line, so I extract some typical ( at least I think) function declaration lines, even in C header files they looks the same. The other lines, which I did not enclose here, can be treated by c2nim or my newbie's brain.
As for the C header files, actually I already mentioned them in ([release]binding for FLTK C dynamic library)[https://forum.nim-lang.org/t/4561]
Moerm, I think FLTK is a C++ lib, so I would guess that the argument is a C++ reference to a pointer. So maybe it would be a proc Fl_Widget_TrackerDelete(wt: var ptr Fl_Widget_Tracker) in Nim. But I know not much of C++, and even for C guessing the real meaning of parameters is not always easy, it can be necessary to look at the API documentation. Unfortunately I know nothing about FLTK and Basic language.
oyster, for question 3. NULL is generally mapped to nil in Nim, so you can write if x.isNil or if x == nil.
Why do you think at all that you need bindings to FLTK? That lib is not that popular, and there are many other GUI libs available for Nim: nimx, libui and many more. Try nimble search or search on nimble.directory page.
however to be frankly I can compile FLTK, but don't know how to compile D.J.Peters's FLTK **C** for FreeBasic from source in Msys2+Mingw64 on Windows 7
All the above 1, 3, 4, 5, 6 have been mentioned in fact.
nimx offical image says "no, there is no table widget".
nimx is pure native Nim, so you should be able to create whatever widget you need.