Example .nim file:
type HugeNum {.exportc: "HugeNum".} = tuple
isNotNeg : bool
num_seq : seq[cuint]
proc fib(a: cint): cint {.exportc.} =
if a <= 2:
result = 1
else:
result = fib(a - 1) + fib(a - 2)
return result
proc example() : seq[cuint] {.exportc.} =
var s : seq[cuint] = @[9'u32]
return s
proc get_seq() : HugeNum {.exportc.} =
var s : HugeNum
s = (isNotNeg : true
, num_seq : @[32'u32 , 12'u32]
)
return s
Run
Header file:
/* Generated by Nim Compiler v1.0.2 */
/* (c) 2017 Andreas Rumpf */
/* The generated code is subject to the original license. */
#ifndef __fib__
#define __fib__
#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
...
typedef struct tySequence__U48dCdy0noze9bNL2psZZGA
tySequence__U48dCdy0noze9bNL2psZZGA;
typedef struct TGenericSeq TGenericSeq;
typedef struct HugeNum HugeNum;
struct TGenericSeq {
NI len;
NI reserved;
};
struct tySequence__U48dCdy0noze9bNL2psZZGA {
TGenericSeq Sup;
unsigned int data[SEQ_DECL_SIZE];
};
N_NOCONV(void, signalHandler)(int sign);
N_NIMCALL(NI, getRefcount)(void* p);
N_NIMCALL(int, fib)(int a);
N_NIMCALL(tySequence__U48dCdy0noze9bNL2psZZGA*, get_seq2)(void);
N_NIMCALL(void, example)(HugeNum* Result);
N_CDECL(void, NimMain)(void);
#endif /* __fib__ */
Run