c2nim icon indicating copy to clipboard operation
c2nim copied to clipboard

Using --header:HEADER_FILE results in bad .nim code

Open genotrance opened this issue 8 years ago • 2 comments

Simple test.h file

int function(int param);

Processed with c2nim --header:test.h test.h results in bad .nim code - no quotes around the header file in the pragma.

proc function*(param: cint): cint {.importc: "function", header: test.h.}

Both --header:"test.h" or --header:\"test.h\" don't work either.

Processed with c2nim --header test.h without specifying HEADER_FILE works correctly but isn't useful for my purposes.

proc function*(param: cint): cint {.importc: "function", header: "test.h".}

genotrance avatar Nov 06 '17 21:11 genotrance

I think I understand the intent of this flag - it is similar to --dynlib where the value following the : is to be treated as a const that needs to be defined in the resulting file.

So if you have c2nim --header:headerfile test.h, you get:

const headerfile = "test.h"

proc function*(param: cint): cint {.importc: "function", header: headerfile.}

where the const was added manually, after the fact.

I'm thinking this should be left open to be either:

  • Fixed in documentation
  • Updated to allow entering a static string for both --header: and --dynlib: (if in quotes) in case you want to hard code a value and not require manual editing.

Or it could be closed as working as designed. I'll let you decide what's the appropriate approach.

genotrance avatar Nov 13 '17 00:11 genotrance

Both --header:"test.h" or --header:"test.h" don't work either.

That's because the shell interprets the double-quotes. To pass them through to c2nim you have to wrap them in single-quotes, which in most shells completely disables shell processing:

c2nim --header '"test.h"' test.h

This works for me in a bash script.

snej avatar Apr 22 '20 18:04 snej