I am trying to create bindings for a library (raylib), and I'm having trouble 
with one of the type declarations in the C header file. I've created a simple 
bare-bones example of the issue.

struct_test.c: 
    
    
    #include <stdio.h>
    
    typedef struct MyStruct {
        unsigned int id;
        int width;
        int height;
        int mipmaps;
        int format;
    } MyStruct;
    
    void PrintStructValues(MyStruct testStruct)
    {
      printf("from c:   testStruct.width %d\n", testStruct.width);
      printf("from c:   testStruct.height %d\n", testStruct.height);
    }
    

struct_test.nim: 
    
    
    type
      MyStruct* = object
        id*: cuint
        width*: cint
        height*: cint
        mipmaps*: cint
        format*: cint
    
    
    proc PrintStructValues*(testStruct: MyStruct)
      {.cdecl, importc, dynlib: "./struct_test.so".}
    
    
    var testStruct = MyStruct(
      id: 1,
      width: 2,
      height: 3,
      mipmaps: 4,
      format: 5
    )
    
    echo "from nim: testStruct.width ", testStruct.width
    echo "from nim: testStruct.height ", testStruct.height
    
    PrintStructValues(testStruct)
    

This prints: 
    
    
    from nim: testStruct.width 2
    from nim: testStruct.height 3
    from c:   testStruct.width 32752
    from c:   testStruct.height 782344336
    

Can anyone point out where I'm going wrong?

Reply via email to