Small changes to add 0.18.0 compatibility
Change toGodotName back to macro because that got fixed in devel change isSome to isNone in godotapigen
This commit is contained in:
parent
3a935b9308
commit
34fda99def
3 changed files with 33 additions and 15 deletions
|
|
@ -456,7 +456,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
|
||||||
ident("array"), ident("MAX_ARG_COUNT"),
|
ident("array"), ident("MAX_ARG_COUNT"),
|
||||||
if isVarargs: newNode(nkPtrTy).addChain(ident("GodotVariant"))
|
if isVarargs: newNode(nkPtrTy).addChain(ident("GodotVariant"))
|
||||||
else: ident("pointer"))))
|
else: ident("pointer"))))
|
||||||
staticArgsLen = if varargsName.isSome: meth.args.len
|
staticArgsLen = if varargsName.isNone: meth.args.len
|
||||||
else: meth.args.len - 1
|
else: meth.args.len - 1
|
||||||
if varargsName.isSome:
|
if varargsName.isSome:
|
||||||
argLenNode = newCall("cint",
|
argLenNode = newCall("cint",
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ proc parseType(definition, callSite: NimNode): ObjectDecl =
|
||||||
parseError(option, "valid type specifier expected")
|
parseError(option, "valid type specifier expected")
|
||||||
result.isTool = isTool
|
result.isTool = isTool
|
||||||
|
|
||||||
if result.parentName == "": result.parentName = "Object"
|
if result.parentName.len == 0: result.parentName = "Object"
|
||||||
for statement in body:
|
for statement in body:
|
||||||
case statement.kind:
|
case statement.kind:
|
||||||
of nnkVarSection:
|
of nnkVarSection:
|
||||||
|
|
@ -444,7 +444,7 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
|
||||||
let objTy = newNimNode(nnkObjectTy)
|
let objTy = newNimNode(nnkObjectTy)
|
||||||
typeDef.add(newNimNode(nnkRefTy).add(objTy))
|
typeDef.add(newNimNode(nnkRefTy).add(objTy))
|
||||||
objTy.add(newEmptyNode())
|
objTy.add(newEmptyNode())
|
||||||
if obj.parentName == "":
|
if obj.parentName.len == 0:
|
||||||
objTy.add(newEmptyNode())
|
objTy.add(newEmptyNode())
|
||||||
else:
|
else:
|
||||||
objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName)))
|
objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName)))
|
||||||
|
|
@ -503,11 +503,11 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
|
||||||
result.add(meth.nimNode)
|
result.add(meth.nimNode)
|
||||||
|
|
||||||
# Register Godot object
|
# Register Godot object
|
||||||
let parentName = if obj.parentName == "": newStrLitNode("Object")
|
let parentName = if obj.parentName.len == 0: newStrLitNode("Object")
|
||||||
else: newStrLitNode(obj.parentName)
|
else: newStrLitNode(obj.parentName)
|
||||||
let classNameLit = newStrLitNode(obj.name)
|
let classNameLit = newStrLitNode(obj.name)
|
||||||
let classNameIdent = ident(obj.name)
|
let classNameIdent = ident(obj.name)
|
||||||
let isRef: bool = if obj.parentName == "": false
|
let isRef: bool = if obj.parentName.len == 0: false
|
||||||
else: obj.parentName in refClasses
|
else: obj.parentName in refClasses
|
||||||
# Wrapping bools with a newLit is required as a temporary workaround for
|
# Wrapping bools with a newLit is required as a temporary workaround for
|
||||||
# https://github.com/nim-lang/Nim/issues/7375
|
# https://github.com/nim-lang/Nim/issues/7375
|
||||||
|
|
@ -544,9 +544,15 @@ 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):
|
||||||
|
{.emit: """/*TYPESECTION*/
|
||||||
|
N_NOINLINE(void, setStackBottom)(void* thestackbottom);
|
||||||
|
""".}
|
||||||
|
else:
|
||||||
|
{.emit: """
|
||||||
N_NOINLINE(void, nimGC_setStackBottom)(void* thestackbottom);
|
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]):
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ macro baseNativeType(T: typedesc): cstring =
|
||||||
if typeName == "NimGodotObject":
|
if typeName == "NimGodotObject":
|
||||||
break
|
break
|
||||||
t = getType(t[1][1])
|
t = getType(t[1][1])
|
||||||
if baseT == "":
|
if baseT.len == 0:
|
||||||
result = newNilLit()
|
result = newNilLit()
|
||||||
else:
|
else:
|
||||||
let rStr = newNimNode(nnkRStrLit)
|
let rStr = newNimNode(nnkRStrLit)
|
||||||
|
|
@ -343,7 +343,7 @@ proc newRStrLit(s: string): NimNode {.compileTime.} =
|
||||||
result = newNimNode(nnkRStrLit)
|
result = newNimNode(nnkRStrLit)
|
||||||
result.strVal = s
|
result.strVal = s
|
||||||
|
|
||||||
proc toGodotName(T: typedesc): string =
|
macro toGodotName(T: typedesc): string =
|
||||||
if T is GodotString or T is string:
|
if T is GodotString or T is string:
|
||||||
"String"
|
"String"
|
||||||
elif T is SomeFloat:
|
elif T is SomeFloat:
|
||||||
|
|
@ -708,10 +708,16 @@ proc toVariant*(s: string): Variant {.inline.} =
|
||||||
proc fromVariant*(s: var string, val: Variant): ConversionResult =
|
proc fromVariant*(s: var string, val: Variant): ConversionResult =
|
||||||
if val.getType() == VariantType.String:
|
if val.getType() == VariantType.String:
|
||||||
s = val.asString()
|
s = val.asString()
|
||||||
elif val.getType() == VariantType.Nil:
|
when (NimMajor, NimMinor, NimPatch) < (0, 19, 0):
|
||||||
s = ""
|
if val.getType() == VariantType.Nil:
|
||||||
|
s = nil
|
||||||
|
else:
|
||||||
|
result = ConversionResult.TypeError
|
||||||
else:
|
else:
|
||||||
result = ConversionResult.TypeError
|
if val.getType() == VariantType.Nil:
|
||||||
|
s = ""
|
||||||
|
else:
|
||||||
|
result = ConversionResult.TypeError
|
||||||
|
|
||||||
template arrTypeInfo(T) =
|
template arrTypeInfo(T) =
|
||||||
result.variantType = VariantType.Array
|
result.variantType = VariantType.Array
|
||||||
|
|
@ -829,10 +835,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 =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue