diff --git a/godot/core/arrays.nim b/godot/core/arrays.nim index fcbafb2..3bbb2c9 100644 --- a/godot/core/arrays.nim +++ b/godot/core/arrays.nim @@ -21,7 +21,7 @@ proc newArray*(arr: GodotArray): Array {.inline.} = import variants -proc newArray*(s: varargs[Variant]): Array = +proc newArray*(s: varargs[Variant], `newVariant`): Array = new(result, arrayFinalizer) initGodotArray(result.godotArray) for v in s: diff --git a/godot/core/poolarrays.nim b/godot/core/poolarrays.nim index 29fda96..afd951a 100644 --- a/godot/core/poolarrays.nim +++ b/godot/core/poolarrays.nim @@ -16,10 +16,6 @@ template definePoolArrayBase(T, GodotT, DataT, fieldName, newProcName, proc poolArrayFinalizer(arr: T) = arr.fieldName.deinit() - proc newProcName*(): T {.inline.} = - new(result, poolArrayFinalizer) - initProcName(result.fieldName) - proc fieldName*(self: T): ptr GodotT {.inline.} = ## WARNING: do not keep the returned value for longer than the lifetime of ## the array. @@ -88,6 +84,13 @@ template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName; newProcName(self.fieldName.subarray(idxFrom.cint, idxTo.cint)) when not noData: + proc newProcName*(s: varargs[DataT]): T {.inline.} = + new(result) + initProcName(result.fieldName) + result.fieldName.setLen(s.len.cint) + for idx, data in s: + result.fieldName[idx.cint] = data + proc add*(self: T; data: DataT) {.inline.} = self.fieldName.add(data) @@ -138,6 +141,15 @@ definePoolArray(PoolStringArray, GodotPoolStringArray, string, godotPoolStringArray, newPoolStringArray, initGodotPoolStringArray, true) +proc newPoolStringArray*(s: varargs[string]): PoolStringArray {.inline.} = + new(result) + initGodotPoolStringArray(result.godotPoolStringArray) + result.godotPoolStringArray.setLen(s.len.cint) + for idx, str in s: + var gstr = str.toGodotString() + result.godotPoolStringArray[idx.cint] = gstr + gstr.deinit() + proc add*(self: PoolStringArray; data: string) = var s = data.toGodotString() self.godotPoolStringArray.add(s)