An unsafe but fast and clean way - just to cast your tuple to your object type:
    
    
    proc createRef(typeinfo: typedesc, data: tuple): auto =
        result = new(typeinfo)
        result[]=cast[typeinfo](data)
    

Be aware you should provide a tuple of values of needed types, or the same in 
size, and not just compatible:
    
    
    type
      O = object
        x: int
        y: float
        z: int8
        q: int8
    
    let r = createRef(O, (5, 6.6, 7i8, 8i8))
    echo r[]
    

In this example, if you provide the 3rd as `int`, not expected `int8`, you 
won't get the 4th item of tuple into your object - `7` literal will pass an 
`int` value (32/64 bits), setting `z` and `q` fields to `7` and `0` 
respectively.

Reply via email to