diff --git a/godot/core/godotcore.nim b/godot/core/godotcore.nim index 7928af0..f0a0884 100644 --- a/godot/core/godotcore.nim +++ b/godot/core/godotcore.nim @@ -285,6 +285,10 @@ proc print*(message: string) {.inline.} = let s = message.toGodotString() godotPrint(s) +proc print*(message: cstring) {.inline.} = + let s = message.toGodotString() + godotPrint(s) + template printWarning*(warn: typed) = let (filename, line) = instantiationInfo() godotPrintWarning(cstring($warn), nil, cstring(filename), line.cint) diff --git a/godot/core/strings.nim b/godot/core/strings.nim index f4c1789..0a800ac 100644 --- a/godot/core/strings.nim +++ b/godot/core/strings.nim @@ -56,3 +56,7 @@ proc `$`*(self: GodotString): string = proc toGodotString*(s: string): GodotString {.inline.} = ## Converts the Nim string into ``GodotString`` initGodotString(result, unsafeAddr s[0], cint(s.len + 1)) + +proc toGodotString*(s: cstring): GodotString {.inline.} = + ## Converts the cstring into ``GodotString`` + initGodotString(result, s, cint(s.len + 1)) diff --git a/godot/nim/godotnim.nim b/godot/nim/godotnim.nim index b8dd95c..a13be85 100644 --- a/godot/nim/godotnim.nim +++ b/godot/nim/godotnim.nim @@ -554,4 +554,16 @@ proc godot_gdnative_init(options: ptr GodotNativeInitOptions) {. proc godot_gdnative_terminate(options: ptr GodotNativeTerminateOptions) {. cdecl, exportc, dynlib.} = - deallocHeap() + deallocHeap(runFinalizers = true, allowGcAfterwards = false) + +proc godot_nativescript_thread_enter() {. + cdecl, exportc, dynlib.} = + when compileOption("threads"): + setupForeignThreadGc() + else: + print(cstring"A foreign thread is created, but app is compiled without --threads:on. Bad things will happen if Nim code is invoked from this thread.") + +proc godot_nativescript_thread_exit() {. + cdecl, exportc, dynlib.} = + when compileOption("threads"): + teardownForeignThreadGc()