Re: FFI: how to avoid naming arguments in C functions
https://github.com/nimterop/nimterop/issues/171#issuecomment-602387909
Re: FFI: how to avoid naming arguments in C functions
Thanks for that. I was looking about how that was called (enum offsets).
Re: FFI: how to avoid naming arguments in C functions
=> I filed it here: [https://github.com/nimterop/nimterop/issues/171](https://github.com/nimterop/nimterop/issues/171)
Re: FFI: how to avoid naming arguments in C functions
Nimterop has other issues (I should file it). For instance: toast -pnrk VapourSynth.h creates the following enums: pfRGB24* = (cmRGB + 10).VSPresetFormat pfRGB27* = 29.VSPresetFormat pfRGB30* = 30.VSPresetFormat pfRGB48* = 31.VSPresetFormat pfRGBH* = 32.VSPresetFormat pfRGBS* = 33.VSPresetFormat Run while **h2nim.py** creates: pfRGB24* = (210).VSPresetFormat pfRGB27* = (211).VSPresetFormat pfRGB30* = (212).VSPresetFormat pfRGB48* = (213).VSPresetFormat pfRGBH* = (214).VSPresetFormat pfRGBS* = (215).VSPresetFormat Run while the original content: cmRGB= 200 ... pfRGB24 = cmRGB + 10, pfRGB27, pfRGB30, pfRGB48, pfRGBH, pfRGBS, Run
Re: FFI: how to avoid naming arguments in C functions
@akavel no problem and I understand (I can imagine). @shashlick thanks for that. Very useful. I have left my spaguetty code [here](https://github.com/mantielero/h2nim.py) (I called it **h2nim.py** ). It uses [pyclibrary](https://pyclibrary.readthedocs.io/en/latest/) under the hood. It is far from perfect (it is not aiming to), but it is under 500LOC, so it is easy to tweak to particular needs. It might help others wrapping easy libraries. It helped me with VapourSynth because of this [issue](https://github.com/nimterop/nimterop/issues/137) I filed in nimterop and with GR.
Re: FFI: how to avoid naming arguments in C functions
Read this section [https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst#def-directive](https://github.com/nim-lang/c2nim/blob/master/doc/c2nim.rst#def-directive) but the introduction also tries to explain it.
Re: FFI: how to avoid naming arguments in C functions
To get you started, [here's](http://ix.io/2dTc/nim) the wrapper output from: toast -pnrk gr.h Run Toast is the c2nim equivalent from nimterop.
Re: FFI: how to avoid naming arguments in C functions
Please try to not take offence with Araq's occasional snappy replies; I can only assume he sometimes gets tired with the maintainer role & responsibilities, which indeed can be exhausting at times; I know I myself am sometimes less polite than I'd like to be when I'm overly tired, even to people I most love, unfortunately. But rest assured he's the good guy, and generally absolutely tries to be practically helpful; personally, I found that when I patiently persist with discussing the important matter and kindly choose to overlook any rare irrelevant remarks, the conversation tends to quickly get back on track. (Or, sometimes, quietly dies alone in the corner, but that's just your usual rollercoaster of all online communities everywhere!) Take care!
Re: FFI: how to avoid naming arguments in C functions
I will take a look to ggplotnim. Looks interesting. I have played with both nimterop and c2nim before. Thanks a lot.
Re: FFI: how to avoid naming arguments in C functions
Also related to your C library wrapping project, have a look at [https://github.com/nimterop/nimterop](https://github.com/nimterop/nimterop). Using that, I have successfully wrapped quite a few C libraries, and this is coming from someone who has never coded in C (of course, some learning curve is involved, but the community and the nimterop developer shashlick/genotrance was very helpful as I was learning to use nimterop).
Re: FFI: how to avoid naming arguments in C functions
Related to your plotting application, also have a look at ggplotnim: [https://github.com/Vindaar/ggplotnim](https://github.com/Vindaar/ggplotnim) . It helps me make things like:
Re: FFI: how to avoid naming arguments in C functions
Thanks for the clarification.
Re: FFI: how to avoid naming arguments in C functions
$ c2nim --header gr.h gr.h(27, 25) Error: token expected: ; Run AFAIK, c2nim cannot read something with c custom macro. You can edit the header temporarily to remove that custom macro. In this case it's the `DLLEXPORT`.
Re: FFI: how to avoid naming arguments in C functions
Or alternative, you can point me in the right direction if you actually know what is the problem. I read the documentation, despite neither [here](https://github.com/nim-lang/c2nim) nor [here
Re: FFI: how to avoid naming arguments in C functions
Well alternatively you can read c2nim's documentation.
Re: FFI: how to avoid naming arguments in C functions
When I try to use c2nim, it tends to fail while parsing stuff (vapoursynth and gr). Por example, with [gr.h](https://github.com/sciapp/gr/blob/master/lib/gr/gr.h): $ c2nim --header gr.h gr.h(27, 25) Error: token expected: ; $ c2nim --dynlib /usr/gr/lib/libGR.so /usr/gr/lib/libGR.so(1, 1) Error: invalid token (\127) so probably I am not using it well. I write some spaguetty code in python to create the wrapper.
Re: FFI: how to avoid naming arguments in C functions
> where I have to add a, b, c just to make it work. Yeah, well you do have to do that. c2nim automates it for you.
Re: FFI: how to avoid naming arguments in C functions
By the way, I am just playing with [gr framework](https://gr-framework.org/). #import gr_wrapper const libName = "/usr/gr/lib/libGR.so" proc gr_initgr*(){.importc,dynlib: libName.} proc gr_polyline*(a:cint, b:ptr cdouble, c:ptr cdouble) {.importc,dynlib: libName.} proc gr_axes*(a:cdouble, b:cdouble, c:cdouble, d:cdouble, e:cint, f:cint, g:cdouble){.importc,dynlib: libName.} proc gr_tick*(a:cdouble, b:cdouble):cdouble{.importc,dynlib: libName.} proc gr_beginprint*(a:cstring){.importc,dynlib: libName.} proc gr_endprint*(){.importc,dynlib: libName.} when isMainModule: let x = @[0.0, 0.2, 0.4, 0.6, 0.8, 1.0] let y = @[0.3, 0.5, 0.4, 0.2, 0.6, 0.7] let px = cast[ptr cdouble](unsafeAddr(x[0])) let py = cast[ptr cdouble](unsafeAddr(y[0])) gr_beginprint("salida.png".cstring) gr_polyline(x.len.cint, px, py) gr_axes(gr_tick(0, 1), gr_tick(0, 1), 0, 0, 1, 1, -0.01) gr_endprint() #discard readChar(stdin) Run gives me: (a big milestone for somebody like me)
FFI: how to avoid naming arguments in C functions
Is it possible to avoid giving names to arguments in the functions? I have the following in the C header: DLLEXPORT void gr_polyline(int, double *, double *); Run and in order to make it work, I have to do: proc gr_polyline*(a:cint, b:ptr cdouble, c:ptr cdouble) {.importc,dynlib: libName.} Run where I have to add a, b, c just to make it work.