That's easy just rename your destroy to:
    
    
    proc `=destroy`(rand: var CRand) =
    
    
    Run

See complete example (with mock library):
    
    
    type CRand* = object # <= Nim container
      state: pointer # <= pointer used by C
    
    proc `=destroy`(rand: var CRand) =
      echo "rand.state.gsl_rng_free"
    
    proc newCRand(seed = 0): CRand =
      CRand(state: cast[pointer](seed))
    
    proc get(rand: var CRand): float =
      echo "rand.state.gsl_rng_uniform"
    
    var r = newCRand()
    echo r.get()
    
    # will be called by GC:
    # r.`=destroy`()
    
    
    Run

This works with both default gc and the new `--gc:arc`.

Reply via email to