Fix compilation errors in generated API

This commit is contained in:
Joey Payne 2019-03-10 17:08:42 -06:00
commit 0ad22b7b7c
3 changed files with 19 additions and 16 deletions

View file

@ -474,7 +474,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
newNode(nkBracketExpr).addChain(
ident("array"), newIntLit(staticArgsLen), ident("pointer")),
newNode(nkEmpty)))
argsAlloc.add(newCommand(ident("addr"), ident("argsStatic")))
argsAlloc.add(newDotExpr(ident("argsStatic"), ident("addr")))
vars.add(newIdentDefs(argsName, newNode(nkEmpty), argsAlloc))
let argConversions = newNode(nkStmtList)

View file

@ -197,7 +197,7 @@ proc parseType(definition, callSite: NimNode): ObjectDecl =
parseError(option, "valid type specifier expected")
result.isTool = isTool
if result.parentName == "": result.parentName = "Object"
if result.parentName.len == 0: result.parentName = "Object"
for statement in body:
case statement.kind:
of nnkVarSection:
@ -444,7 +444,7 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
let objTy = newNimNode(nnkObjectTy)
typeDef.add(newNimNode(nnkRefTy).add(objTy))
objTy.add(newEmptyNode())
if obj.parentName == "":
if obj.parentName.len == 0:
objTy.add(newEmptyNode())
else:
objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName)))
@ -503,11 +503,11 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
result.add(meth.nimNode)
# Register Godot object
let parentName = if obj.parentName == "": newStrLitNode("Object")
let parentName = if obj.parentName.len == 0: newStrLitNode("Object")
else: newStrLitNode(obj.parentName)
let classNameLit = newStrLitNode(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
# Wrapping bools with a newLit is required as a temporary workaround for
# https://github.com/nim-lang/Nim/issues/7375

View file

@ -202,7 +202,7 @@ macro baseNativeType(T: typedesc): cstring =
if typeName == "NimGodotObject":
break
t = getType(t[1][1])
if baseT == "":
if baseT.len == 0:
result = newNilLit()
else:
let rStr = newNimNode(nnkRStrLit)
@ -343,20 +343,23 @@ proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit)
result.strVal = s
proc toGodotName(T: typedesc): string =
macro toGodotName(T: typedesc): string =
var godotName: string
if T is GodotString or T is string:
"String"
godotName = "String"
elif T is SomeFloat:
"float"
godotName = "float"
elif T is SomeUnsignedInt or T is SomeSignedInt:
"int"
else:
godotName = "int"
if godotName.len == 0:
let nameStr = (($T.getType()[1][1].symbol).split(':')[0])
case nameStr:
of "File", "Directory", "Thread", "Mutex", "Semaphore":
"_" & nameStr
else:
nameStr
godotName = case nameStr:
of "File", "Directory", "Thread", "Mutex", "Semaphore":
"_" & nameStr
else:
nameStr
result = newLit(godotName)
macro asCString(s: static[string]): cstring =
result = newNimNode(nnkCallStrLit).add(