type TRow = seq[string] TRows = seq[TRow] proc dbGetRowsCb(arr: pointer; colCount: int32; values, columns: cstringArray): int32 {.cdecl.} = var cols:TRow for i in 0..<colCount: cols.add($values[i]) var arr = cast[ptr TRows](arr) arr[].add(cols) return 0 proc dbGetRows*(q:string): TRows = var err:cstring="" var arr: TRows discard db.exec(q, dbGetRowsCb, result.addr, err) if err != "": echo err free err Run
In the dbGetRowsCb proc if i change the lines var arr = cast[ptr TRows](arr) arr[].add(cols) Run to var arr = cast[ptr TRows](arr)[] arr.add(cols) Run The sequence returned by dbGetRows is empty. Why??? Is it because the original sequence, once dereferenced, is copied to "var arr", hence "cols" is not added to it but to a copy which is deleted once the proc returns?