Add missing $ to standard types

This commit is contained in:
Ruslan Mustakov 2017-08-06 13:58:54 +07:00
commit 6aaeed4dca
6 changed files with 58 additions and 24 deletions

View file

@ -134,10 +134,13 @@ proc len*(self: Array): int {.inline.} =
proc sort*(self: var Array) {.inline.} = proc sort*(self: var Array) {.inline.} =
self.godotArray.sort() self.godotArray.sort()
iterator items*(arr: Array): Variant = iterator items*(self: Array): Variant =
for i in 0..<arr.len: for i in 0..<self.len:
yield arr[i] yield self[i]
iterator pairs*(arr: Array): tuple[key: int, val: Variant] = iterator pairs*(self: Array): tuple[key: int, val: Variant] =
for i in 0..<arr.len: for i in 0..<self.len:
yield (i, arr[i]) yield (i, self[i])
proc `$`*(self: Array): string =
$self.godotArray

View file

@ -97,3 +97,14 @@ iterator values*(dict: Dictionary): Variant =
iterator pairs*(dict: Dictionary): tuple[key, val: Variant] = iterator pairs*(dict: Dictionary): tuple[key, val: Variant] =
for key in keys(dict): for key in keys(dict):
yield (key, dict[key]) yield (key, dict[key])
proc `$`*(self: Dictionary): string =
result = newStringOfCap(32)
result.add('{')
for k, v in self:
if result.len > 1:
result.add(", ")
result.add($k)
result.add(": ")
result.add($v)
result.add('}')

View file

@ -22,6 +22,9 @@ proc idCInt(self: RID): cint {.
proc id*(self: RID): uint32 {.inline.} = proc id*(self: RID): uint32 {.inline.} =
cast[uint32](self.idCInt()) cast[uint32](self.idCInt())
proc `$`*(self: RID): string =
$self.id
proc `==`*(a, b: RID): bool {. proc `==`*(a, b: RID): bool {.
importc: "godot_rid_operator_equal".} importc: "godot_rid_operator_equal".}
proc `<`*(a, b: RID): bool {. proc `<`*(a, b: RID): bool {.

View file

@ -27,6 +27,9 @@ proc variantFinalizer*(v: Variant) =
if not v.noDeinit: if not v.noDeinit:
v.godotVariant.deinit() v.godotVariant.deinit()
proc `$`*(self: Variant): string {.inline.} =
$self.godotVariant
proc newVariant*(): Variant {.inline.} = proc newVariant*(): Variant {.inline.} =
new(result, variantFinalizer) new(result, variantFinalizer)
initGodotVariant(result.godotVariant) initGodotVariant(result.godotVariant)
@ -174,9 +177,7 @@ 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() $self
result = $s
s.deinit()
proc asVector2*(self: Variant): Vector2 = proc asVector2*(self: Variant): Vector2 =
self.godotVariant.asVector2() self.godotVariant.asVector2()

View file

@ -4,6 +4,10 @@ type
GodotArray* {.byref.} = object GodotArray* {.byref.} = object
data: array[sizeof(int), byte] data: array[sizeof(int), byte]
proc len*(self: GodotArray): cint {.
noSideEffect,
importc: "godot_array_size".}
import hashes import hashes
import godotobjects, godotpoolarrays, godotvariants, godotstrings import godotobjects, godotpoolarrays, godotvariants, godotstrings
@ -94,26 +98,33 @@ proc rfind*(self: GodotArray; what: GodotVariant;
f: cint): cint {. f: cint): cint {.
noSideEffect, noSideEffect,
importc: "godot_array_rfind".} importc: "godot_array_rfind".}
proc len*(self: GodotArray): cint {.
noSideEffect,
importc: "godot_array_size".}
proc sort*(self: var GodotArray) {.importc: "godot_array_sort".} proc sort*(self: var GodotArray) {.importc: "godot_array_sort".}
proc sortCustom*(self: var GodotArray; obj: var GodotObject; proc sortCustom*(self: var GodotArray; obj: var GodotObject;
funcName: GodotString) {. funcName: GodotString) {.
importc: "godot_array_sort_custom".} importc: "godot_array_sort_custom".}
iterator items*(arr: GodotArray): GodotVariant = iterator items*(self: GodotArray): GodotVariant =
for i in 0..<arr.len: for i in 0..<self.len:
yield arr[i] yield self[i]
iterator mitems*(arr: var GodotArray): var GodotVariant = iterator mitems*(self: var GodotArray): var GodotVariant =
for i in 0..<arr.len: for i in 0..<self.len:
yield arr.mget(i)[] yield self.mget(i)[]
iterator pairs*(arr: GodotArray): tuple[key: cint, val: GodotVariant] = iterator pairs*(self: GodotArray): tuple[key: cint, val: GodotVariant] =
for i in 0..<arr.len: for i in 0..<self.len:
yield (i, arr[i]) yield (i, self[i])
iterator mpairs*(arr: var GodotArray): tuple[key: cint, val: var GodotVariant] = iterator mpairs*(self: var GodotArray): tuple[key: cint,
for i in 0..<arr.len: val: var GodotVariant] =
yield (i, arr.mget(i)[]) for i in 0..<self.len:
yield (i, self.mget(i)[])
proc `$`*(self: GodotArray): string =
result = newStringOfCap(32)
result.add('[')
for item in self:
if result.len > 1:
result.add(", ")
result.add($item)
result.add(']')

View file

@ -191,3 +191,8 @@ proc hashCompare*(self, other: GodotVariant): bool {.
importc: "godot_variant_hash_compare".} importc: "godot_variant_hash_compare".}
proc booleanize*(self: GodotVariant; isValid: var bool): bool {. proc booleanize*(self: GodotVariant; isValid: var bool): bool {.
importc: "godot_variant_booleanize".} importc: "godot_variant_booleanize".}
proc `$`*(self: GodotVariant): string =
var s = self.asGodotString()
result = $s
s.deinit()