Hello
My fisrt attempt in order to learn Nim is here https://github.com/nodrygo/NimIUPDemo
I have try to wrote a stupid demo with IUP, Scintilla and canvas(CD)
the canvas part doesn't work probably because I have some trouble with .h convertion
I still have some problems to well understand pointers usage (if somebody can help .. welcome)
I have try only on my Linux! may be there is a problem with IUP on Linux ?
in .H
******
cdContext* cdContextIup(void);
#define CD_IUP cdContextIup()
# how must I convert CD_IUP ? try a LET but doesn't work
cdCanvas* cdCreateCanvas(cdContext *context, void *data);
call in in .C
************
cnvs = IupCanvas( NULL );
cdcanvas = cdCreateCanvas( CD_IUP, cnvs );
template CD_IUP(): expr = cdContextIup()
proc cdCreateCanvas(context: ptr cdContext; data: pointer) {.importc, cdecl, dynlib: yourDynlib.}
cnvs = IupCanvas(nil)
cdcanvas = cdCreateCanvas(CD_IUP(), cnvs)
#define CD_IUP cdContextIup()
may be just an alias for a function call in C, so in early days I fixed it to
#define CD_IUP() cdContextIup()
to let c2nim generate a template as Araq shows us.
But currently I prefer to have a simple proc const in Nim:
const CD_IUP* = cdContextIup
I generate that by a script -- for me it looks cleaner, but I guess template will generate the same code? Of course the question is if we want to have the alias at all in our wrapper. And, one disadvantage of the proc const: It has to appear after proc declaration! I have not already testet with the latest c2nim release (0.10.3), maybe it is even smarter now.
But currently I prefer to have a simple proc const in Nim
Ha, so there is already proc aliasing in Nim. Nice! Nobody thought of using it this way so afaict you can claim you invented it! :D
#proc p1(x: float) =
# echo x
proc p1(i: int): int =
i + 1
const p1a = p1
echo p1(7)
echo p1a(7)
So alias like "const `color=` = set_color" can not be used in wrappers when we have multiple procs with same name but different parameters. So in GDK3 wrapper I duplicated the whole proc declaration for that cases. Another solution would have been using the deprecated list for these aliases, but I do not want to get warnings for that. Some people may really prefer the set_ and get_ prefix in proc names. (So I did not test using deprecated list for this case at all.)
unfortunatly none of the proposal works
in fact, nothing fail, the canvas appear but it is empty despite that I can see the event drawing callback
it is also possible I have a problem with my IUP/CD install on Linux. I must explore
but I won't spend to much time here
GTK3 seem more promising ;-)