From 1770d13119fe5593a290c35ed266079c1bf46f0d Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Sun, 10 Mar 2019 17:53:41 -0600 Subject: [PATCH] Make setStackBottom backwards compatible --- godot/nim/godotmacros.nim | 23 ++++++++++++++++------ godot/nim/godotnim.nim | 41 ++++++++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/godot/nim/godotmacros.nim b/godot/nim/godotmacros.nim index 9859619..5b17717 100644 --- a/godot/nim/godotmacros.nim +++ b/godot/nim/godotmacros.nim @@ -544,17 +544,28 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} = template registerGodotMethod(classNameLit, classNameIdent, methodNameIdent, methodNameLit, minArgs, maxArgs, argTypes, methFuncIdent, hasReturnValue) = - {.emit: """/*TYPESECTION*/ -N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom); -""".} + when (NimMajor, NimMinor, NimPatch) < (0, 19, 0): + {.emit: """/*TYPESECTION*/ + N_NOINLINE(void, setStackBottom)(void* thestackbottom); + """.} + else: + {.emit: """/*TYPESECTION*/ + N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom); + """.} + proc methFuncIdent(obj: ptr GodotObject, methodData: pointer, userData: pointer, numArgs: cint, args: var array[MAX_ARG_COUNT, ptr GodotVariant]): GodotVariant {.noconv.} = var stackBottom {.volatile.}: pointer - {.emit: """ - nimGC_setStackBottom((void*)(&`stackBottom`)); - """.} + when (NimMajor, NimMinor, NimPatch) < (0, 19, 0): + {.emit: """ + setStackBottom((void*)(&`stackBottom`)); + """.} + else: + {.emit: """ + nimGC_setStackBottom((void*)(&`stackBottom`)); + """.} let self = cast[classNameIdent](userData) const isStaticCall = methodNameLit == cstring"_ready" or methodNameLit == cstring"_process" or diff --git a/godot/nim/godotnim.nim b/godot/nim/godotnim.nim index 45161fc..4694572 100644 --- a/godot/nim/godotnim.nim +++ b/godot/nim/godotnim.nim @@ -832,10 +832,16 @@ proc fromVariant*[T: Table or TableRef or OrderedTable or OrderedTableRef](t: va else: result = ConversionResult.TypeError -{.emit: """/*TYPESECTION*/ -N_LIB_EXPORT N_CDECL(void, NimMain)(void); -N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom); -""".} +when (NimMajor, NimMinor, NimPatch) < (0, 19, 0): + {.emit: """/*TYPESECTION*/ + N_LIB_EXPORT N_CDECL(void, NimMain)(void); + N_NOINLINE(void, setStackBottom)(void* thestackbottom); + """.} +else: + {.emit: """/*TYPESECTION*/ + N_LIB_EXPORT N_CDECL(void, NimMain)(void); + N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom); + """.} var nativeLibHandle: pointer proc getNativeLibHandle*(): pointer = @@ -848,10 +854,17 @@ proc godot_nativescript_init(handle: pointer) {. nativeLibHandle = handle var stackBottom {.volatile.}: pointer - {.emit: """ - NimMain(); - nimGC_setStackBottom((void*)(&`stackBottom`)); - """.} + + when (NimMajor, NimMinor, NimPatch) < (0, 19, 0): + {.emit: """ + NimMain(); + setStackBottom((void*)(&`stackBottom`)); + """.} + else: + {.emit: """ + NimMain(); + nimGC_setStackBottom((void*)(&`stackBottom`)); + """.} GC_fullCollect() GC_disable() @@ -886,9 +899,15 @@ proc registerFrameCallback*(cb: proc () {.closure.}) = proc godot_nativescript_frame() {.cdecl, exportc, dynlib.} = var stackBottom {.volatile.}: pointer - {.emit: """ - nimGC_setStackBottom((void*)(&`stackBottom`)); - """.} + + when (NimMajor, NimMinor, NimPatch) < (0, 19, 0): + {.emit: """ + setStackBottom((void*)(&`stackBottom`)); + """.} + else: + {.emit: """ + nimGC_setStackBottom((void*)(&`stackBottom`)); + """.} for cb in idleCallbacks: cb() GC_step(nimGcStepLengthUs, true, 0)