@Stefan_Salewski, @mashingan: thank you both, your suggestions were great. I 
was under the misapprehension that the Nim primitives were C-like. So now, 
using _cstring_ instead of _string_ means the test_string function works 
smoothly! For the array function I am now returning a ptr, which I can access 
on the other (Ruby) side without errors, but when I de-reference it I get a 
list of meaningless numbers
    
    
    proc test_arr(): ptr array[3, int] {.cdecl, exportc} =
      let
        a: int = 3
        b: int = 4
        c: int = 5
      
      var list = [a, b, c]
      return addr list
    

I have tried packaging the list items using different representations (int32, 
uint16, etc) and matching these when I read the array on the receiving side, 
but still keep getting random numbers. I suspect this time the problem is in 
the way I unpack the array on the client side, so I need to look a bit more 
into that.

PS Stefan, yes, as soon as I get this going I intend to write a blog post about 
it. As per the GC, as long as I'm using ptrs I shouldn't need to worry about it 
as ptrs are not tracked so I can just release the memory from the Ruby side 
when I'm done. Thanks though, as I hadn't considered the Nim GC impact before, 
so that's definitely something to think about. 

Reply via email to