Define Variant and Array in their own modules
This commit is contained in:
parent
f30df6d81b
commit
360be5759e
15 changed files with 201 additions and 166 deletions
|
|
@ -3,120 +3,129 @@
|
||||||
import hashes
|
import hashes
|
||||||
import "../internal/godotinternaltypes.nim", "../internal/godotarrays.nim"
|
import "../internal/godotinternaltypes.nim", "../internal/godotarrays.nim"
|
||||||
|
|
||||||
import godotbase, poolarrays
|
type
|
||||||
|
Array* = ref object
|
||||||
|
godotArray: GodotArray
|
||||||
|
|
||||||
|
proc godotArray*(arr: Array): ptr GodotArray {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## ``arr``
|
||||||
|
addr arr.godotArray
|
||||||
|
|
||||||
proc arrayFinalizer(arr: Array) =
|
proc arrayFinalizer(arr: Array) =
|
||||||
arr.godotArray[].deinit()
|
arr.godotArray.deinit()
|
||||||
|
|
||||||
proc newArray*(): Array {.inline.} =
|
proc newArray*(): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[])
|
initGodotArray(result.godotArray)
|
||||||
|
|
||||||
proc newArray*(arr: GodotArray): Array {.inline.} =
|
proc newArray*(arr: GodotArray): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
result.godotArray[] = arr
|
result.godotArray = arr
|
||||||
|
|
||||||
|
import poolarrays, variants
|
||||||
|
|
||||||
proc newArray*(pca: PoolColorArray): Array {.inline.} =
|
proc newArray*(pca: PoolColorArray): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], pca.godotPoolColorArray[])
|
initGodotArray(result.godotArray, pca.godotPoolColorArray[])
|
||||||
|
|
||||||
proc newArray*(pv3a: PoolVector3Array): Array {.inline.} =
|
proc newArray*(pv3a: PoolVector3Array): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], pv3a.godotPoolVector3Array[])
|
initGodotArray(result.godotArray, pv3a.godotPoolVector3Array[])
|
||||||
|
|
||||||
proc newArray*(pv2a: PoolVector2Array): Array {.inline.} =
|
proc newArray*(pv2a: PoolVector2Array): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], pv2a.godotPoolVector2Array[])
|
initGodotArray(result.godotArray, pv2a.godotPoolVector2Array[])
|
||||||
|
|
||||||
proc newArray*(psa: PoolStringArray): Array {.inline.} =
|
proc newArray*(psa: PoolStringArray): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], psa.godotPoolStringArray[])
|
initGodotArray(result.godotArray, psa.godotPoolStringArray[])
|
||||||
|
|
||||||
proc newArray*(pra: PoolRealArray): Array {.inline.} =
|
proc newArray*(pra: PoolRealArray): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], pra.godotPoolRealArray[])
|
initGodotArray(result.godotArray, pra.godotPoolRealArray[])
|
||||||
|
|
||||||
proc newArray*(pia: PoolIntArray): Array {.inline.} =
|
proc newArray*(pia: PoolIntArray): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], pia.godotPoolIntArray[])
|
initGodotArray(result.godotArray, pia.godotPoolIntArray[])
|
||||||
|
|
||||||
proc newArray*(pba: PoolByteArray): Array {.inline.} =
|
proc newArray*(pba: PoolByteArray): Array {.inline.} =
|
||||||
new(result, arrayFinalizer)
|
new(result, arrayFinalizer)
|
||||||
initGodotArray(result.godotArray[], pba.godotPoolByteArray[])
|
initGodotArray(result.godotArray, pba.godotPoolByteArray[])
|
||||||
|
|
||||||
import variants
|
import variants
|
||||||
|
|
||||||
proc `[]=`*(self: var Array; idx: int; value: Variant) {.inline.} =
|
proc `[]=`*(self: var Array; idx: int; value: Variant) {.inline.} =
|
||||||
self.godotArray[][idx.cint] = value.godotVariant[]
|
self.godotArray[idx.cint] = value.godotVariant[]
|
||||||
|
|
||||||
proc `[]`*(self: Array; idx: int): Variant {.inline.} =
|
proc `[]`*(self: Array; idx: int): Variant {.inline.} =
|
||||||
newVariant(self.godotArray[][idx.cint])
|
newVariant(self.godotArray[idx.cint])
|
||||||
|
|
||||||
proc add*(self: var Array; value: Variant) {.inline.} =
|
proc add*(self: var Array; value: Variant) {.inline.} =
|
||||||
self.godotArray[].add(value.godotVariant[])
|
self.godotArray.add(value.godotVariant[])
|
||||||
|
|
||||||
proc clear*(self: var Array) {.inline.} =
|
proc clear*(self: var Array) {.inline.} =
|
||||||
self.godotArray[].clear()
|
self.godotArray.clear()
|
||||||
|
|
||||||
proc count*(self: Array; value: Variant): int {.inline.} =
|
proc count*(self: Array; value: Variant): int {.inline.} =
|
||||||
self.godotArray[].count(value.godotVariant[]).int
|
self.godotArray.count(value.godotVariant[]).int
|
||||||
|
|
||||||
proc isEmpty*(self: Array): bool {.inline.} =
|
proc isEmpty*(self: Array): bool {.inline.} =
|
||||||
self.godotArray[].isEmpty()
|
self.godotArray.isEmpty()
|
||||||
|
|
||||||
proc erase*(self: var Array; value: Variant) {.inline.} =
|
proc erase*(self: var Array; value: Variant) {.inline.} =
|
||||||
self.godotArray[].erase(value.godotVariant[])
|
self.godotArray.erase(value.godotVariant[])
|
||||||
|
|
||||||
proc first*(self: Array): Variant {.inline.} =
|
proc first*(self: Array): Variant {.inline.} =
|
||||||
newVariant(self.godotArray[].first())
|
newVariant(self.godotArray.first())
|
||||||
|
|
||||||
proc last*(self: Array): Variant {.inline.} =
|
proc last*(self: Array): Variant {.inline.} =
|
||||||
newVariant(self.godotArray[].last())
|
newVariant(self.godotArray.last())
|
||||||
|
|
||||||
proc find*(self: Array; what: Variant; f: int): int {.inline.} =
|
proc find*(self: Array; what: Variant; f: int): int {.inline.} =
|
||||||
self.godotArray[].find(what.godotVariant[], f.cint).int
|
self.godotArray.find(what.godotVariant[], f.cint).int
|
||||||
|
|
||||||
proc findLast*(self: Array; what: Variant): int {.inline.} =
|
proc findLast*(self: Array; what: Variant): int {.inline.} =
|
||||||
self.godotArray[].findLast(what.godotVariant[]).int
|
self.godotArray.findLast(what.godotVariant[]).int
|
||||||
|
|
||||||
proc contains*(self: Array; value: Variant): bool {.inline.} =
|
proc contains*(self: Array; value: Variant): bool {.inline.} =
|
||||||
self.godotArray[].contains(value.godotVariant[])
|
self.godotArray.contains(value.godotVariant[])
|
||||||
|
|
||||||
proc hash*(self: Array): Hash {.inline.} =
|
proc hash*(self: Array): Hash {.inline.} =
|
||||||
hash(self.godotArray[].godotHash())
|
hash(self.godotArray.godotHash())
|
||||||
|
|
||||||
proc insert*(self: var Array; pos: int; value: Variant) {.inline.} =
|
proc insert*(self: var Array; pos: int; value: Variant) {.inline.} =
|
||||||
self.godotArray[].insert(pos.cint, value.godotVariant[])
|
self.godotArray.insert(pos.cint, value.godotVariant[])
|
||||||
|
|
||||||
proc reverse*(self: var Array) {.inline.} =
|
proc reverse*(self: var Array) {.inline.} =
|
||||||
self.godotArray[].reverse()
|
self.godotArray.reverse()
|
||||||
|
|
||||||
proc popLast*(self: var Array): Variant {.inline.} =
|
proc popLast*(self: var Array): Variant {.inline.} =
|
||||||
newVariant(self.godotArray[].popLast())
|
newVariant(self.godotArray.popLast())
|
||||||
|
|
||||||
proc popFirst*(self: var Array): Variant {.inline.} =
|
proc popFirst*(self: var Array): Variant {.inline.} =
|
||||||
newVariant(self.godotArray[].popFirst())
|
newVariant(self.godotArray.popFirst())
|
||||||
|
|
||||||
proc addLast*(self: var Array; value: Variant) {.inline.} =
|
proc addLast*(self: var Array; value: Variant) {.inline.} =
|
||||||
self.godotArray[].addLast(value.godotVariant[])
|
self.godotArray.addLast(value.godotVariant[])
|
||||||
|
|
||||||
proc addFirst*(self: var Array; value: Variant) {.inline.} =
|
proc addFirst*(self: var Array; value: Variant) {.inline.} =
|
||||||
self.godotArray[].addFirst(value.godotVariant[])
|
self.godotArray.addFirst(value.godotVariant[])
|
||||||
|
|
||||||
proc delete*(self: var Array; idx: int) {.inline.} =
|
proc delete*(self: var Array; idx: int) {.inline.} =
|
||||||
self.godotArray[].delete(idx.cint)
|
self.godotArray.delete(idx.cint)
|
||||||
|
|
||||||
proc setLen*(self: var Array; size: int) {.inline.} =
|
proc setLen*(self: var Array; size: int) {.inline.} =
|
||||||
self.godotArray[].setLen(size.cint)
|
self.godotArray.setLen(size.cint)
|
||||||
|
|
||||||
proc rfind*(self: Array; what: Variant; f: int): int {.inline.} =
|
proc rfind*(self: Array; what: Variant; f: int): int {.inline.} =
|
||||||
self.godotArray[].rfind(what.godotVariant[], f.cint).int
|
self.godotArray.rfind(what.godotVariant[], f.cint).int
|
||||||
|
|
||||||
proc len*(self: Array): int {.inline.} =
|
proc len*(self: Array): int {.inline.} =
|
||||||
self.godotArray[].len.int
|
self.godotArray.len.int
|
||||||
|
|
||||||
proc sort*(self: var Array) {.inline.} =
|
proc sort*(self: var Array) {.inline.} =
|
||||||
self.godotArray[].sort()
|
self.godotArray.sort()
|
||||||
|
|
||||||
iterator items*(arr: Array): Variant {.inline.} =
|
iterator items*(arr: Array): Variant {.inline.} =
|
||||||
for i in 0..<arr.len:
|
for i in 0..<arr.len:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Color* {.byref.} = object
|
Color* {.byref.} = object
|
||||||
r*: float32
|
r*: float32
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
# Copyright 2017 Xored Software, Inc.
|
# Copyright 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import hashes
|
import hashes
|
||||||
import godotbase
|
|
||||||
import "../internal/godotinternaltypes.nim", "../internal/godotstrings.nim",
|
import "../internal/godotinternaltypes.nim", "../internal/godotstrings.nim",
|
||||||
"../internal/godotdictionaries.nim", "../internal/godotvariants.nim"
|
"../internal/godotdictionaries.nim", "../internal/godotvariants.nim"
|
||||||
|
|
||||||
|
|
@ -34,6 +33,8 @@ proc isEmpty*(self: Dictionary): bool {.inline.} =
|
||||||
proc clear*(self: var Dictionary) {.inline.} =
|
proc clear*(self: var Dictionary) {.inline.} =
|
||||||
self.godotDictionary.clear()
|
self.godotDictionary.clear()
|
||||||
|
|
||||||
|
import variants, arrays
|
||||||
|
|
||||||
proc contains*(self: Dictionary; key: Variant): bool {.inline.}=
|
proc contains*(self: Dictionary; key: Variant): bool {.inline.}=
|
||||||
self.godotDictionary.contains(key.godotVariant[])
|
self.godotDictionary.contains(key.godotVariant[])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,34 +84,6 @@ proc stepify*(value, step: float32): float32 =
|
||||||
else:
|
else:
|
||||||
value
|
value
|
||||||
|
|
||||||
import "../internal/godotinternaltypes.nim"
|
|
||||||
|
|
||||||
type
|
|
||||||
Variant* = ref object
|
|
||||||
godotVariant: GodotVariant
|
|
||||||
noDeinit: bool # used to avoid copying when passing the variant to Godot
|
|
||||||
|
|
||||||
Array* = ref object
|
|
||||||
godotArray: GodotArray
|
|
||||||
|
|
||||||
proc markNoDeinit*(v: Variant) {.inline.} =
|
|
||||||
## Makes it so that internal GodotVariant object will not be destroyed
|
|
||||||
## when the reference is gone. Use only if you know what you are doing.
|
|
||||||
v.noDeinit = true
|
|
||||||
|
|
||||||
proc isNoDeinit*(v: Variant): bool {.inline.} =
|
|
||||||
v.noDeinit
|
|
||||||
|
|
||||||
proc godotArray*(arr: Array): ptr GodotArray {.inline.} =
|
|
||||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
|
||||||
## ``arr``
|
|
||||||
addr arr.godotArray
|
|
||||||
|
|
||||||
proc godotVariant*(v: Variant): ptr GodotVariant {.inline.} =
|
|
||||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
|
||||||
## ``v``
|
|
||||||
addr v.godotVariant
|
|
||||||
|
|
||||||
# System Functions
|
# System Functions
|
||||||
|
|
||||||
proc godotAlloc*(bytes: cint): pointer {.
|
proc godotAlloc*(bytes: cint): pointer {.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
# Copyright 2017 Xored Software, Inc.
|
# Copyright 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase
|
|
||||||
|
|
||||||
import "../internal/godotnodepaths.nim", "../internal/godotstrings.nim"
|
import "../internal/godotnodepaths.nim", "../internal/godotstrings.nim"
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, vector3
|
import vector3
|
||||||
|
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,70 @@
|
||||||
# Copyright 2017 Xored Software, Inc.
|
# Copyright 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, vector2, vector3, colors
|
import vector2, vector3, colors
|
||||||
import "../internal/godotpoolarrays.nim", "../internal/godotstrings.nim"
|
import "../internal/godotpoolarrays.nim", "../internal/godotstrings.nim"
|
||||||
|
|
||||||
# byte
|
type
|
||||||
|
PoolByteArray* = ref object
|
||||||
|
godotPoolByteArray: GodotPoolByteArray
|
||||||
|
PoolIntArray* = ref object
|
||||||
|
godotPoolIntArray: GodotPoolIntArray
|
||||||
|
PoolRealArray* = ref object
|
||||||
|
godotPoolRealArray: GodotPoolRealArray
|
||||||
|
PoolVector2Array* = ref object
|
||||||
|
godotPoolVector2Array: GodotPoolVector2Array
|
||||||
|
PoolVector3Array* = ref object
|
||||||
|
godotPoolVector3Array: GodotPoolVector3Array
|
||||||
|
PoolColorArray* = ref object
|
||||||
|
godotPoolColorArray: GodotPoolColorArray
|
||||||
|
PoolStringArray* = ref object
|
||||||
|
godotPoolStringArray: GodotPoolStringArray
|
||||||
|
|
||||||
|
proc godotPoolByteArray*(self: PoolByteArray):
|
||||||
|
ptr GodotPoolByteArray {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolByteArray
|
||||||
|
|
||||||
|
proc godotPoolIntArray*(self: PoolIntArray):
|
||||||
|
ptr GodotPoolIntArray {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolIntArray
|
||||||
|
|
||||||
|
proc godotPoolRealArray*(self: PoolRealArray):
|
||||||
|
ptr GodotPoolRealArray {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolRealArray
|
||||||
|
|
||||||
|
proc godotPoolVector2Array*(self: PoolVector2Array):
|
||||||
|
ptr GodotPoolVector2Array {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolVector2Array
|
||||||
|
|
||||||
|
proc godotPoolVector3Array*(self: PoolVector3Array):
|
||||||
|
ptr GodotPoolVector3Array {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolVector3Array
|
||||||
|
|
||||||
|
proc godotPoolColorArray*(self: PoolColorArray):
|
||||||
|
ptr GodotPoolColorArray {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolColorArray
|
||||||
|
|
||||||
|
proc godotPoolStringArray*(self: PoolStringArray):
|
||||||
|
ptr GodotPoolStringArray {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## the array.
|
||||||
|
addr self.godotPoolStringArray
|
||||||
|
|
||||||
|
import godotbase, arrays
|
||||||
|
|
||||||
template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
||||||
noData = false) =
|
noData = false) =
|
||||||
type
|
|
||||||
T* = ref object
|
|
||||||
fieldName: GodotT
|
|
||||||
|
|
||||||
proc poolArrayFinalizer(arr: T) =
|
proc poolArrayFinalizer(arr: T) =
|
||||||
arr.fieldName.deinit()
|
arr.fieldName.deinit()
|
||||||
|
|
@ -40,11 +96,6 @@ template definePoolArray(T, GodotT, DataT, fieldName, newProcName, initProcName;
|
||||||
proc len*(self: T): int {.inline.} =
|
proc len*(self: T): int {.inline.} =
|
||||||
self.fieldName.len.int
|
self.fieldName.len.int
|
||||||
|
|
||||||
proc fieldName*(self: T): ptr GodotT {.inline.} =
|
|
||||||
## WARNING: do not keep the returned value for longer than the lifetime of
|
|
||||||
## the array.
|
|
||||||
addr self.fieldName
|
|
||||||
|
|
||||||
when not noData:
|
when not noData:
|
||||||
proc add*(self: var T; data: DataT) {.inline.} =
|
proc add*(self: var T; data: DataT) {.inline.} =
|
||||||
self.fieldName.add(data)
|
self.fieldName.add(data)
|
||||||
|
|
@ -87,7 +138,6 @@ definePoolArray(PoolVector3Array, GodotPoolVector3Array, Vector3,
|
||||||
definePoolArray(PoolColorArray, GodotPoolColorArray, Color,
|
definePoolArray(PoolColorArray, GodotPoolColorArray, Color,
|
||||||
godotPoolColorArray, newPoolColorArray,
|
godotPoolColorArray, newPoolColorArray,
|
||||||
initGodotPoolColorArray)
|
initGodotPoolColorArray)
|
||||||
|
|
||||||
definePoolArray(PoolStringArray, GodotPoolStringArray, string,
|
definePoolArray(PoolStringArray, GodotPoolStringArray, string,
|
||||||
godotPoolStringArray, newPoolStringArray,
|
godotPoolStringArray, newPoolStringArray,
|
||||||
initGodotPoolStringArray, true)
|
initGodotPoolStringArray, true)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, vector3
|
import vector3
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, vector2
|
import vector2
|
||||||
|
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, planes, vector3
|
import planes, vector3
|
||||||
|
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import godotbase
|
|
||||||
|
|
||||||
import "../internal/godotinternaltypes.nim"
|
import "../internal/godotinternaltypes.nim"
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, vector2, rect2
|
import vector2, rect2
|
||||||
|
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase, basis, vector3, planes, rect3
|
import basis, vector3, planes, rect3
|
||||||
|
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,56 @@
|
||||||
import tables
|
import tables
|
||||||
|
|
||||||
import godotbase
|
|
||||||
import basis, nodepaths
|
|
||||||
import planes, poolarrays, quats, rect2, rect3, rids
|
|
||||||
import transforms, transform2d, vector2
|
|
||||||
import vector3, colors
|
|
||||||
|
|
||||||
import "../internal/godotinternaltypes.nim"
|
import "../internal/godotinternaltypes.nim"
|
||||||
import "../internal/godotvariants.nim", "../internal/godotpoolarrays.nim",
|
import "../internal/godotvariants.nim"
|
||||||
"../internal/godotstrings.nim", "../internal/godotnodepaths.nim"
|
import "../internal/godotpoolarrays.nim", "../internal/godotstrings.nim",
|
||||||
|
"../internal/godotnodepaths.nim"
|
||||||
|
|
||||||
|
type
|
||||||
|
Variant* = ref object
|
||||||
|
godotVariant: GodotVariant
|
||||||
|
noDeinit: bool # used to avoid copying when passing the variant to Godot
|
||||||
|
|
||||||
export VariantType, VariantCallErrorType, VariantCallError
|
export VariantType, VariantCallErrorType, VariantCallError
|
||||||
|
|
||||||
|
proc markNoDeinit*(v: Variant) {.inline.} =
|
||||||
|
## Makes it so that internal GodotVariant object will not be destroyed
|
||||||
|
## when the reference is gone. Use only if you know what you are doing.
|
||||||
|
v.noDeinit = true
|
||||||
|
|
||||||
|
proc godotVariant*(v: Variant): ptr GodotVariant {.inline.} =
|
||||||
|
## WARNING: do not keep the returned value for longer than the lifetime of
|
||||||
|
## ``v``
|
||||||
|
addr v.godotVariant
|
||||||
|
|
||||||
proc getType*(v: Variant): VariantType =
|
proc getType*(v: Variant): VariantType =
|
||||||
v.godotVariant[].getType()
|
v.godotVariant.getType()
|
||||||
|
|
||||||
proc variantFinalizer(v: Variant) =
|
proc variantFinalizer(v: Variant) =
|
||||||
if not v.isNoDeinit:
|
if not v.noDeinit:
|
||||||
v.godotVariant[].deinit()
|
v.godotVariant.deinit()
|
||||||
|
|
||||||
proc newVariant*(): Variant {.inline.} =
|
proc newVariant*(): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[])
|
initGodotVariant(result.godotVariant)
|
||||||
|
|
||||||
proc newVariant*(v: Variant): Variant {.inline.} =
|
proc newVariant*(v: Variant): Variant {.inline.} =
|
||||||
## Makes a copy
|
## Makes a copy
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], v.godotVariant[])
|
initGodotVariant(result.godotVariant, v.godotVariant)
|
||||||
|
|
||||||
proc newVariant*(v: GodotVariant): Variant {.inline.} =
|
proc newVariant*(v: GodotVariant): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
result.godotVariant[] = v
|
result.godotVariant = v
|
||||||
|
|
||||||
proc newVariant*(b: bool): Variant {.inline.} =
|
proc newVariant*(b: bool): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], b)
|
initGodotVariant(result.godotVariant, b)
|
||||||
|
|
||||||
# resolves Nim call ambiguities well
|
# resolves Nim call ambiguities well
|
||||||
template numConstructor(T, ConvT) =
|
template numConstructor(T, ConvT) =
|
||||||
proc newVariant*(i: T): Variant {.inline.} =
|
proc newVariant*(i: T): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], ConvT(i))
|
initGodotVariant(result.godotVariant, ConvT(i))
|
||||||
|
|
||||||
numConstructor(uint8, uint64)
|
numConstructor(uint8, uint64)
|
||||||
numConstructor(uint16, uint64)
|
numConstructor(uint16, uint64)
|
||||||
|
|
@ -56,206 +66,207 @@ numConstructor(int, int64)
|
||||||
|
|
||||||
proc newVariant*(r: cdouble): Variant {.inline.} =
|
proc newVariant*(r: cdouble): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], r)
|
initGodotVariant(result.godotVariant, r)
|
||||||
|
|
||||||
proc newVariant*(s: GodotString): Variant {.inline.} =
|
|
||||||
new(result, variantFinalizer)
|
|
||||||
initGodotVariant(result.godotVariant[], s)
|
|
||||||
|
|
||||||
proc newVariant*(s: string): Variant {.inline.} =
|
proc newVariant*(s: string): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
var godotStr = s.toGodotString()
|
var godotStr = s.toGodotString()
|
||||||
initGodotVariant(result.godotVariant[], godotStr)
|
initGodotVariant(result.godotVariant, godotStr)
|
||||||
godotStr.deinit()
|
godotStr.deinit()
|
||||||
|
|
||||||
|
import basis, nodepaths
|
||||||
|
import planes, poolarrays, quats, rect2, rect3, rids
|
||||||
|
import transforms, transform2d, vector2
|
||||||
|
import vector3, colors
|
||||||
|
|
||||||
proc newVariant*(v2: Vector2): Variant {.inline.} =
|
proc newVariant*(v2: Vector2): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], v2)
|
initGodotVariant(result.godotVariant, v2)
|
||||||
|
|
||||||
proc newVariant*(rect2: Rect2): Variant {.inline.} =
|
proc newVariant*(rect2: Rect2): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], rect2)
|
initGodotVariant(result.godotVariant, rect2)
|
||||||
|
|
||||||
proc newVariant*(v3: Vector3): Variant {.inline.} =
|
proc newVariant*(v3: Vector3): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], v3)
|
initGodotVariant(result.godotVariant, v3)
|
||||||
|
|
||||||
proc newVariant*(t2d: Transform2D): Variant {.inline.} =
|
proc newVariant*(t2d: Transform2D): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], t2d)
|
initGodotVariant(result.godotVariant, t2d)
|
||||||
|
|
||||||
proc newVariant*(plane: Plane): Variant {.inline.} =
|
proc newVariant*(plane: Plane): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], plane)
|
initGodotVariant(result.godotVariant, plane)
|
||||||
|
|
||||||
proc newVariant*(quat: Quat): Variant {.inline.} =
|
proc newVariant*(quat: Quat): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], quat)
|
initGodotVariant(result.godotVariant, quat)
|
||||||
|
|
||||||
proc newVariant*(rect3: Rect3): Variant {.inline.} =
|
proc newVariant*(rect3: Rect3): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], rect3)
|
initGodotVariant(result.godotVariant, rect3)
|
||||||
|
|
||||||
proc newVariant*(basis: Basis): Variant {.inline.} =
|
proc newVariant*(basis: Basis): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], basis)
|
initGodotVariant(result.godotVariant, basis)
|
||||||
|
|
||||||
proc newVariant*(trans: Transform): Variant {.inline.} =
|
proc newVariant*(trans: Transform): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], trans)
|
initGodotVariant(result.godotVariant, trans)
|
||||||
|
|
||||||
proc newVariant*(color: Color): Variant {.inline.} =
|
proc newVariant*(color: Color): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], color)
|
initGodotVariant(result.godotVariant, color)
|
||||||
|
|
||||||
proc newVariant*(nodePath: NodePath): Variant {.inline.} =
|
proc newVariant*(nodePath: NodePath): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], nodePath.godotNodePath[])
|
initGodotVariant(result.godotVariant, nodePath.godotNodePath[])
|
||||||
|
|
||||||
proc newVariant*(godotNodePath: GodotNodePath): Variant {.inline.} =
|
proc newVariant*(godotNodePath: GodotNodePath): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], godotNodePath)
|
initGodotVariant(result.godotVariant, godotNodePath)
|
||||||
|
|
||||||
proc newVariant*(rid: RID): Variant {.inline.} =
|
proc newVariant*(rid: RID): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], rid)
|
initGodotVariant(result.godotVariant, rid)
|
||||||
|
|
||||||
proc newVariant*(obj: ptr GodotObject): Variant {.inline.} =
|
proc newVariant*(obj: ptr GodotObject): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], obj)
|
initGodotVariant(result.godotVariant, obj)
|
||||||
|
|
||||||
import arrays
|
import arrays
|
||||||
|
|
||||||
proc newVariant*(arr: Array): Variant {.inline.} =
|
proc newVariant*(arr: Array): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], arr.godotArray[])
|
initGodotVariant(result.godotVariant, arr.godotArray[])
|
||||||
|
|
||||||
proc newVariant*(pba: PoolByteArray): Variant {.inline.} =
|
proc newVariant*(pba: PoolByteArray): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], pba.godotPoolByteArray[])
|
initGodotVariant(result.godotVariant, pba.godotPoolByteArray[])
|
||||||
|
|
||||||
proc newVariant*(pia: PoolIntArray): Variant {.inline.} =
|
proc newVariant*(pia: PoolIntArray): Variant {.inline.} =
|
||||||
initGodotVariant(result.godotVariant[], pia.godotPoolIntArray[])
|
initGodotVariant(result.godotVariant, pia.godotPoolIntArray[])
|
||||||
|
|
||||||
proc newVariant*(pra: PoolRealArray): Variant {.inline.} =
|
proc newVariant*(pra: PoolRealArray): Variant {.inline.} =
|
||||||
initGodotVariant(result.godotVariant[], pra.godotPoolRealArray[])
|
initGodotVariant(result.godotVariant, pra.godotPoolRealArray[])
|
||||||
|
|
||||||
proc newVariant*(psa: PoolStringArray): Variant {.inline.} =
|
proc newVariant*(psa: PoolStringArray): Variant {.inline.} =
|
||||||
initGodotVariant(result.godotVariant[], psa.godotPoolStringArray[])
|
initGodotVariant(result.godotVariant, psa.godotPoolStringArray[])
|
||||||
|
|
||||||
proc newVariant*(pv2a: PoolVector2Array): Variant {.inline.} =
|
proc newVariant*(pv2a: PoolVector2Array): Variant {.inline.} =
|
||||||
initGodotVariant(result.godotVariant[], pv2a.godotPoolVector2Array[])
|
initGodotVariant(result.godotVariant, pv2a.godotPoolVector2Array[])
|
||||||
|
|
||||||
proc newVariant*(pv3a: PoolVector3Array): Variant {.inline.} =
|
proc newVariant*(pv3a: PoolVector3Array): Variant {.inline.} =
|
||||||
initGodotVariant(result.godotVariant[], pv3a.godotPoolVector3Array[])
|
initGodotVariant(result.godotVariant, pv3a.godotPoolVector3Array[])
|
||||||
|
|
||||||
proc newVariant*(pca: PoolColorArray): Variant {.inline.} =
|
proc newVariant*(pca: PoolColorArray): Variant {.inline.} =
|
||||||
initGodotVariant(result.godotVariant[], pca.godotPoolColorArray[])
|
initGodotVariant(result.godotVariant, pca.godotPoolColorArray[])
|
||||||
|
|
||||||
import dictionaries
|
import dictionaries
|
||||||
|
|
||||||
proc newVariant*(dict: Dictionary): Variant {.inline.} =
|
proc newVariant*(dict: Dictionary): Variant {.inline.} =
|
||||||
new(result, variantFinalizer)
|
new(result, variantFinalizer)
|
||||||
initGodotVariant(result.godotVariant[], dict.godotDictionary[])
|
initGodotVariant(result.godotVariant, dict.godotDictionary[])
|
||||||
|
|
||||||
proc asBool*(self: Variant): bool {.inline.} =
|
proc asBool*(self: Variant): bool {.inline.} =
|
||||||
self.godotVariant[].asBool()
|
self.godotVariant.asBool()
|
||||||
|
|
||||||
proc asUInt*(self: Variant): uint64 =
|
proc asUInt*(self: Variant): uint64 =
|
||||||
self.godotVariant[].asUInt()
|
self.godotVariant.asUInt()
|
||||||
|
|
||||||
proc asInt*(self: Variant): int64 =
|
proc asInt*(self: Variant): int64 =
|
||||||
self.godotVariant[].asInt()
|
self.godotVariant.asInt()
|
||||||
|
|
||||||
proc asReal*(self: Variant): cdouble =
|
proc asReal*(self: Variant): cdouble =
|
||||||
self.godotVariant[].asReal()
|
self.godotVariant.asReal()
|
||||||
|
|
||||||
proc asString*(self: Variant): string =
|
proc asString*(self: Variant): string =
|
||||||
var s = self.godotVariant[].asGodotString()
|
var s = self.godotVariant.asGodotString()
|
||||||
result = $s
|
result = $s
|
||||||
s.deinit()
|
s.deinit()
|
||||||
|
|
||||||
proc asVector2*(self: Variant): Vector2 =
|
proc asVector2*(self: Variant): Vector2 =
|
||||||
self.godotVariant[].asVector2()
|
self.godotVariant.asVector2()
|
||||||
|
|
||||||
proc asRect2*(self: Variant): Rect2 =
|
proc asRect2*(self: Variant): Rect2 =
|
||||||
self.godotVariant[].asRect2()
|
self.godotVariant.asRect2()
|
||||||
|
|
||||||
proc asVector3*(self: Variant): Vector3 =
|
proc asVector3*(self: Variant): Vector3 =
|
||||||
self.godotVariant[].asVector3()
|
self.godotVariant.asVector3()
|
||||||
|
|
||||||
proc asTransform2D*(self: Variant): Transform2D =
|
proc asTransform2D*(self: Variant): Transform2D =
|
||||||
self.godotVariant[].asTransform2D()
|
self.godotVariant.asTransform2D()
|
||||||
|
|
||||||
proc asPlane*(self: Variant): Plane =
|
proc asPlane*(self: Variant): Plane =
|
||||||
self.godotVariant[].asPlane()
|
self.godotVariant.asPlane()
|
||||||
|
|
||||||
proc asQuat*(self: Variant): Quat =
|
proc asQuat*(self: Variant): Quat =
|
||||||
self.godotVariant[].asQuat()
|
self.godotVariant.asQuat()
|
||||||
|
|
||||||
proc asRect3*(self: Variant): Rect3 =
|
proc asRect3*(self: Variant): Rect3 =
|
||||||
self.godotVariant[].asRect3()
|
self.godotVariant.asRect3()
|
||||||
|
|
||||||
proc asBasis*(self: Variant): Basis =
|
proc asBasis*(self: Variant): Basis =
|
||||||
self.godotVariant[].asBasis()
|
self.godotVariant.asBasis()
|
||||||
|
|
||||||
proc asTransform*(self: Variant): Transform =
|
proc asTransform*(self: Variant): Transform =
|
||||||
self.godotVariant[].asTransform()
|
self.godotVariant.asTransform()
|
||||||
|
|
||||||
proc asColor*(self: Variant): Color =
|
proc asColor*(self: Variant): Color =
|
||||||
self.godotVariant[].asColor()
|
self.godotVariant.asColor()
|
||||||
|
|
||||||
proc asNodePath*(self: Variant): NodePath =
|
proc asNodePath*(self: Variant): NodePath =
|
||||||
result = newNodePath(self.godotVariant[].asNodePath())
|
result = newNodePath(self.godotVariant.asNodePath())
|
||||||
|
|
||||||
proc asRID*(self: Variant): RID =
|
proc asRID*(self: Variant): RID =
|
||||||
self.godotVariant[].asRID()
|
self.godotVariant.asRID()
|
||||||
|
|
||||||
proc asGodotObject*(self: Variant): ptr GodotObject =
|
proc asGodotObject*(self: Variant): ptr GodotObject =
|
||||||
self.godotVariant[].asGodotObject()
|
self.godotVariant.asGodotObject()
|
||||||
|
|
||||||
proc asArray*(self: Variant): Array =
|
proc asArray*(self: Variant): Array =
|
||||||
newArray(self.godotVariant[].asGodotArray())
|
newArray(self.godotVariant.asGodotArray())
|
||||||
|
|
||||||
proc asPoolByteArray*(self: Variant): PoolByteArray =
|
proc asPoolByteArray*(self: Variant): PoolByteArray =
|
||||||
newPoolByteArray(self.godotVariant[].asGodotPoolByteArray())
|
newPoolByteArray(self.godotVariant.asGodotPoolByteArray())
|
||||||
|
|
||||||
proc asPoolIntArray*(self: Variant): PoolIntArray =
|
proc asPoolIntArray*(self: Variant): PoolIntArray =
|
||||||
newPoolIntArray(self.godotVariant[].asGodotPoolIntArray())
|
newPoolIntArray(self.godotVariant.asGodotPoolIntArray())
|
||||||
|
|
||||||
proc asPoolRealArray*(self: Variant): PoolRealArray =
|
proc asPoolRealArray*(self: Variant): PoolRealArray =
|
||||||
newPoolRealArray(self.godotVariant[].asGodotPoolRealArray())
|
newPoolRealArray(self.godotVariant.asGodotPoolRealArray())
|
||||||
|
|
||||||
proc asPoolStringArray*(self: Variant): PoolStringArray =
|
proc asPoolStringArray*(self: Variant): PoolStringArray =
|
||||||
newPoolStringArray(self.godotVariant[].asGodotPoolStringArray())
|
newPoolStringArray(self.godotVariant.asGodotPoolStringArray())
|
||||||
|
|
||||||
proc asPoolVector2Array*(self: Variant): PoolVector2Array =
|
proc asPoolVector2Array*(self: Variant): PoolVector2Array =
|
||||||
newPoolVector2Array(self.godotVariant[].asGodotPoolVector2Array())
|
newPoolVector2Array(self.godotVariant.asGodotPoolVector2Array())
|
||||||
|
|
||||||
proc asPoolVector3Array*(self: Variant): PoolVector3Array =
|
proc asPoolVector3Array*(self: Variant): PoolVector3Array =
|
||||||
newPoolVector3Array(self.godotVariant[].asGodotPoolVector3Array())
|
newPoolVector3Array(self.godotVariant.asGodotPoolVector3Array())
|
||||||
|
|
||||||
proc asPoolColorArray*(self: Variant): PoolColorArray =
|
proc asPoolColorArray*(self: Variant): PoolColorArray =
|
||||||
newPoolColorArray(self.godotVariant[].asGodotPoolColorArray())
|
newPoolColorArray(self.godotVariant.asGodotPoolColorArray())
|
||||||
|
|
||||||
proc asDictionary*(self: Variant): Dictionary {.inline.} =
|
proc asDictionary*(self: Variant): Dictionary {.inline.} =
|
||||||
newDictionary(self.godotVariant[].asGodotDictionary)
|
newDictionary(self.godotVariant.asGodotDictionary)
|
||||||
|
|
||||||
proc hasMethod*(self: Variant; meth: string): bool =
|
proc hasMethod*(self: Variant; meth: string): bool =
|
||||||
var s = meth.toGodotString()
|
var s = meth.toGodotString()
|
||||||
result = self.godotVariant[].hasMethod(s)
|
result = self.godotVariant.hasMethod(s)
|
||||||
s.deinit()
|
s.deinit()
|
||||||
|
|
||||||
proc `==`*(self, other: Variant): bool =
|
proc `==`*(self, other: Variant): bool =
|
||||||
if self.isNil and other.isNil: return true
|
if self.isNil and other.isNil: return true
|
||||||
if self.isNil != other.isNil: return false
|
if self.isNil != other.isNil: return false
|
||||||
result = self.godotVariant[] == other.godotVariant[]
|
result = self.godotVariant == other.godotVariant
|
||||||
|
|
||||||
proc `<`*(self, other: Variant): bool =
|
proc `<`*(self, other: Variant): bool =
|
||||||
result = self.godotVariant[] < other.godotVariant[]
|
result = self.godotVariant < other.godotVariant
|
||||||
|
|
||||||
proc hashCompare*(self, other: Variant): bool =
|
proc hashCompare*(self, other: Variant): bool =
|
||||||
self.godotVariant[].hashCompare(other.godotVariant[])
|
self.godotVariant.hashCompare(other.godotVariant)
|
||||||
|
|
||||||
proc booleanize*(self: Variant; isValid: var bool): bool =
|
proc booleanize*(self: Variant; isValid: var bool): bool =
|
||||||
self.godotVariant[].booleanize(isValid)
|
self.godotVariant.booleanize(isValid)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
# Copyright (c) 2017 Xored Software, Inc.
|
# Copyright (c) 2017 Xored Software, Inc.
|
||||||
|
|
||||||
import godotbase
|
|
||||||
|
|
||||||
import "../internal/godotstrings.nim"
|
import "../internal/godotstrings.nim"
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue