I would like to convert the following C++ struct to nim.
# foo.h
struct foo
{
void (*bar)(int &fuz);
};
c2nim does not seem to support this construct
$ c2nim foo.h
foo.h(3, 21) Error: ')' expected
$ c2nim --cpp foo.h
foo.h(3, 11) Error: identifier expected, but found '*'
What is the correct way to convert this manually, or get reasonably close?
This is going to be plumbing code to interface with an existing C-Style ++ codebase.
Edit: Corrected, it's C++ not C
Isn't it
// foo.h
struct foo
{
void (*bar)(int *fuz);
};
or is it a c++ header ?
Anyway, you can try something like this
type
foo {.importc:"foo", header:"foo.h"} = object
bar: proc(fuz: var cint) {.cdecl.}
Yes, a C++ header, not C! Corrected.
Compiles fine!
I don't understand why this works though- the struct would normally go into nimcache/foo.cpp- does nim give precedence to identifiers in header files?
If you include the header in the top of the generated file, wouldn't you have two structs, causing a "redefinition of 'struct Foo'" error?
--- begin of file --- #foo.h code struct foo... # original from header
#generated code struct foo... # generated from type statement