Make setStackBottom backwards compatible

This commit is contained in:
Joey Payne 2019-03-10 17:53:41 -06:00
commit 1770d13119
2 changed files with 47 additions and 17 deletions

View file

@ -544,17 +544,28 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
template registerGodotMethod(classNameLit, classNameIdent, methodNameIdent, template registerGodotMethod(classNameLit, classNameIdent, methodNameIdent,
methodNameLit, minArgs, maxArgs, methodNameLit, minArgs, maxArgs,
argTypes, methFuncIdent, hasReturnValue) = argTypes, methFuncIdent, hasReturnValue) =
{.emit: """/*TYPESECTION*/ when (NimMajor, NimMinor, NimPatch) < (0, 19, 0):
N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom); {.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, proc methFuncIdent(obj: ptr GodotObject, methodData: pointer,
userData: pointer, numArgs: cint, userData: pointer, numArgs: cint,
args: var array[MAX_ARG_COUNT, ptr GodotVariant]): args: var array[MAX_ARG_COUNT, ptr GodotVariant]):
GodotVariant {.noconv.} = GodotVariant {.noconv.} =
var stackBottom {.volatile.}: pointer var stackBottom {.volatile.}: pointer
{.emit: """ when (NimMajor, NimMinor, NimPatch) < (0, 19, 0):
nimGC_setStackBottom((void*)(&`stackBottom`)); {.emit: """
""".} setStackBottom((void*)(&`stackBottom`));
""".}
else:
{.emit: """
nimGC_setStackBottom((void*)(&`stackBottom`));
""".}
let self = cast[classNameIdent](userData) let self = cast[classNameIdent](userData)
const isStaticCall = methodNameLit == cstring"_ready" or const isStaticCall = methodNameLit == cstring"_ready" or
methodNameLit == cstring"_process" or methodNameLit == cstring"_process" or

View file

@ -832,10 +832,16 @@ proc fromVariant*[T: Table or TableRef or OrderedTable or OrderedTableRef](t: va
else: else:
result = ConversionResult.TypeError result = ConversionResult.TypeError
{.emit: """/*TYPESECTION*/ when (NimMajor, NimMinor, NimPatch) < (0, 19, 0):
N_LIB_EXPORT N_CDECL(void, NimMain)(void); {.emit: """/*TYPESECTION*/
N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom); 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 var nativeLibHandle: pointer
proc getNativeLibHandle*(): pointer = proc getNativeLibHandle*(): pointer =
@ -848,10 +854,17 @@ proc godot_nativescript_init(handle: pointer) {.
nativeLibHandle = handle nativeLibHandle = handle
var stackBottom {.volatile.}: pointer var stackBottom {.volatile.}: pointer
{.emit: """
NimMain(); when (NimMajor, NimMinor, NimPatch) < (0, 19, 0):
nimGC_setStackBottom((void*)(&`stackBottom`)); {.emit: """
""".} NimMain();
setStackBottom((void*)(&`stackBottom`));
""".}
else:
{.emit: """
NimMain();
nimGC_setStackBottom((void*)(&`stackBottom`));
""".}
GC_fullCollect() GC_fullCollect()
GC_disable() GC_disable()
@ -886,9 +899,15 @@ proc registerFrameCallback*(cb: proc () {.closure.}) =
proc godot_nativescript_frame() {.cdecl, exportc, dynlib.} = proc godot_nativescript_frame() {.cdecl, exportc, dynlib.} =
var stackBottom {.volatile.}: pointer 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: for cb in idleCallbacks:
cb() cb()
GC_step(nimGcStepLengthUs, true, 0) GC_step(nimGcStepLengthUs, true, 0)