From 66c939b9e6ab20e39d1e4ef7d17684b4982e5952 Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Mon, 4 Jun 2018 11:47:17 +0700 Subject: [PATCH] Fix for latest Nim Closes #23. --- godot/internal/godotstrings.nim | 3 +-- godot/nim/godotnim.nim | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/godot/internal/godotstrings.nim b/godot/internal/godotstrings.nim index d3eb287..17443cb 100644 --- a/godot/internal/godotstrings.nim +++ b/godot/internal/godotstrings.nim @@ -29,14 +29,13 @@ proc `$`*(self: GodotString): string = result = newString(length) copyMem(addr result[0], getGDNativeAPI().charStringGetData(charStr), length) getGDNativeAPI().charStringDestroy(charStr) - assert(result[length] == '\0') proc toGodotString*(s: string): GodotString {.inline.} = ## Converts the Nim string into ``GodotString`` if s.isNil: initGodotString(result) else: - initGodotString(result, unsafeAddr s[0], cint(s.len + 1)) + initGodotString(result, cstring(s), cint(s.len + 1)) proc toGodotString*(s: cstring): GodotString {.inline.} = ## Converts the cstring into ``GodotString`` diff --git a/godot/nim/godotnim.nim b/godot/nim/godotnim.nim index 8f3d6fb..0b13477 100644 --- a/godot/nim/godotnim.nim +++ b/godot/nim/godotnim.nim @@ -297,8 +297,8 @@ macro toGodotName(T: typedesc): string = godotName = "float" elif T is SomeUnsignedInt or T is SomeSignedInt: godotName = "int" - if godotName.isNil: - let nameStr: string = (($T.getType()[1][1].symbol).split(':')[0]) + if godotName.isNil or godotName.len == 0: + let nameStr = (($T.getType()[1][1].symbol).split(':')[0]) godotName = case nameStr: of "File", "Directory", "Thread", "Mutex", "Semaphore": "_" & nameStr