@LeGuim I guess bits would be truncated if you do the unsafe cast.
I created the following macros. It's a bit too verbose though - considering the
python/c++.
macro settattr(attr:static[string]): typed =
newNimNode(nnkAsgn).add(
newNimNode(nnkDotExpr).add(
newIdentNode(!"obj"),
newIdentNode(attr)
),
newNimNode(nnkDotExpr).add(
newIdentNode(!"data"),
newIdentNode(attr)
)
)
proc fillObj[T](obj:ref T,data:object|tuple) =
for k,v in data.fieldPairs:
settattr(k)
proc createRef(T:typedesc, data:tuple|object): auto =
result = new(T)
fillObj(result,data)
proc createRef(data:object): auto =
result = new(type(data)
fillObj(result, data)