attempt to make 0.19 compatible

This commit is contained in:
Fabian Keller 2018-12-30 12:40:10 +01:00
commit 5ab4775939
5 changed files with 86 additions and 91 deletions

View file

@ -73,12 +73,9 @@ proc newVariant*(r: cdouble): Variant {.inline.} =
proc newVariant*(s: string): Variant {.inline.} = proc newVariant*(s: string): Variant {.inline.} =
new(result, variantFinalizer) new(result, variantFinalizer)
if s.isNil: var godotStr = s.toGodotString()
initGodotVariant(result.godotVariant) initGodotVariant(result.godotVariant, godotStr)
else: godotStr.deinit()
var godotStr = s.toGodotString()
initGodotVariant(result.godotVariant, godotStr)
godotStr.deinit()
import basis, nodepaths import basis, nodepaths
import planes, quats, rect2, aabb, rids import planes, quats, rect2, aabb, rids

View file

@ -1,9 +1,15 @@
# Copyright 2018 Xored Software, Inc. # Copyright 2018 Xored Software, Inc.
import streams, json, os, strutils, times, sets, tables import streams, json, os, strutils, times, sets, tables, options
import sequtils, algorithm import sequtils, algorithm
import compiler.ast, compiler.renderer, compiler.idents, compiler.astalgo import compiler.ast, compiler.renderer, compiler.idents, compiler.astalgo
when (NimMajor, NimMinor, NimPatch) >= (0, 19, 0):
var gic* = newIdentCache()
proc getIdent(ident: string): PIdent =
getIdent(gic, ident)
proc ident(ident: string): PNode = proc ident(ident: string): PNode =
result = newNode(nkIdent) result = newNode(nkIdent)
result.ident = getIdent(ident) result.ident = getIdent(ident)
@ -139,19 +145,19 @@ proc findCommonRoot(typeRegistry: Table[string, GodotType],
var idx = 0 var idx = 0
while true: while true:
var curType: string var curType = none(string)
var allEqual = true var allEqual = true
for chain in chains: for chain in chains:
if idx >= chain.len: if idx >= chain.len:
allEqual = false allEqual = false
break break
if curType.isNil: if curType.isNone:
curType = chain[idx] curType = some(chain[idx])
elif curType != chain[idx]: elif curType.get != chain[idx]:
allEqual = false allEqual = false
break break
if allEqual: if allEqual:
result = curType result = curType.get
else: else:
break break
inc idx inc idx
@ -224,7 +230,7 @@ proc newRefTypeNode(typeSection: PNode, typ, base, doc: string,
inherit.add(ident(base)) inherit.add(ident(base))
objTy.add(inherit) objTy.add(inherit)
if not doc.isNil: if doc.len > 0:
let recList = newNode(nkRecList) let recList = newNode(nkRecList)
let docNode = newNode(nkCommentStmt) let docNode = newNode(nkCommentStmt)
docNode.comment = doc docNode.comment = doc
@ -275,7 +281,7 @@ type
godotName: string godotName: string
typ: GodotType typ: GodotType
args: seq[MethodArg] args: seq[MethodArg]
returnType: string returnType: Option[string]
isVirtual: bool isVirtual: bool
isBase: bool isBase: bool
isDiscardable: bool isDiscardable: bool
@ -428,7 +434,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
newCStringLit(meth.godotName)) newCStringLit(meth.godotName))
) )
let vars = newNode(nkVarSection) let vars = newNode(nkVarSection)
var varargsName: string var varargsName = none(string)
var isVarargs: bool var isVarargs: bool
var staticArgsLen: int var staticArgsLen: int
var argLenNode = newIntLit(0) var argLenNode = newIntLit(0)
@ -436,7 +442,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
if meth.args.len > 0: if meth.args.len > 0:
for idx, arg in meth.args: for idx, arg in meth.args:
if arg.kind == ArgKind.VarArgs: if arg.kind == ArgKind.VarArgs:
varargsName = arg.name varargsName = some(arg.name)
isVarargs = true isVarargs = true
vars.add(newIdentDefs(ident("callError"), ident("VariantCallError"))) vars.add(newIdentDefs(ident("callError"), ident("VariantCallError")))
elif arg.kind == ArgKind.Bound: elif arg.kind == ArgKind.Bound:
@ -450,13 +456,13 @@ 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.isNil: meth.args.len staticArgsLen = if varargsName.isSome: meth.args.len
else: meth.args.len - 1 else: meth.args.len - 1
if not varargsName.isNil: if varargsName.isSome:
argLenNode = newCall("cint", argLenNode = newCall("cint",
infix(newIntLit(staticArgsLen), infix(newIntLit(staticArgsLen),
ident("+"), ident("+"),
newDotExpr(ident(varargsName), ident("len")))) newDotExpr(ident(varargsName.get), ident("len"))))
argsAlloc.add(newCall("godotAlloc", newCall("cint", infix( argsAlloc.add(newCall("godotAlloc", newCall("cint", infix(
newCall("sizeof", ident("Variant")), ident("*"), newCall("sizeof", ident("Variant")), ident("*"),
newNode(nkPar).addChain(argLenNode)))) newNode(nkPar).addChain(argLenNode))))
@ -477,12 +483,12 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
else: ident(arg.name) else: ident(arg.name)
if arg.kind == ArgKind.VarArgs: if arg.kind == ArgKind.VarArgs:
argName = newNode(nkBracketExpr).addChain( argName = newNode(nkBracketExpr).addChain(
ident(varargsName), ident(varargsName.get),
infix(ident("idx"), ident("-"), newIntLit(staticArgsLen))) infix(ident("idx"), ident("-"), newIntLit(staticArgsLen)))
let argIdx = if arg.kind == ArgKind.VarArgs: ident("idx") else: newIntLit(idx) let argIdx = if arg.kind == ArgKind.VarArgs: ident("idx") else: newIntLit(idx)
let isStandardType = arg.typ in standardTypes let isStandardType = arg.typ in standardTypes
let isWrappedType = arg.typ in wrapperTypes let isWrappedType = arg.typ in wrapperTypes
let convArg = if not varargsName.isNil: let convArg = if varargsName.isSome:
getInternalPtr(newCall("toVariant", argName), "Variant") getInternalPtr(newCall("toVariant", argName), "Variant")
elif isWrappedType: getInternalPtr(argName, arg.typ) elif isWrappedType: getInternalPtr(argName, arg.typ)
elif isStandardType: newCall("unsafeAddr", argName) elif isStandardType: newCall("unsafeAddr", argName)
@ -493,7 +499,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
raise newException(ValueError, raise newException(ValueError,
"Non-standard type $# for varargs params of method $# of type $#" % "Non-standard type $# for varargs params of method $# of type $#" %
[arg.typ, meth.godotName, meth.typ.godotName]) [arg.typ, meth.godotName, meth.typ.godotName])
if not isStandardType and varargsName.isNil: if not isStandardType and varargsName.isNone:
if arg.typ == "string": if arg.typ == "string":
argConversions.add(newNode(nkVarSection).addChain( argConversions.add(newNode(nkVarSection).addChain(
newIdentDefs(ident("argToPassToGodot" & $idx), newEmptyNode(), newIdentDefs(ident("argToPassToGodot" & $idx), newEmptyNode(),
@ -560,31 +566,32 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
var isStringRet: bool var isStringRet: bool
var isWrapperRet: bool var isWrapperRet: bool
let retValIdent = if not isVarargs: ident("ptrCallVal") else: ident(retName) let retValIdent = if not isVarargs: ident("ptrCallVal") else: ident(retName)
if not meth.returnType.isNil and not isVarargs: if meth.returnType.isSome and not isVarargs:
let returnType = meth.returnType.get
var addrToAssign = newCall("addr", retValIdent) var addrToAssign = newCall("addr", retValIdent)
if meth.returnType in smallIntTypes: if returnType in smallIntTypes:
isConversionRet = true isConversionRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs( body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("int64"), retValIdent, ident("int64"),
))) )))
elif meth.returnType in float32Types: elif returnType in float32Types:
isConversionRet = true isConversionRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs( body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("float64"), retValIdent, ident("float64"),
))) )))
elif meth.returnType in wrapperTypes: elif returnType in wrapperTypes:
isWrapperRet = true isWrapperRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs( body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("Godot" & meth.returnType), retValIdent, ident("Godot" & returnType),
))) )))
elif meth.returnType in standardTypes: elif returnType in standardTypes:
addrToAssign = newCall("addr", ident("result")) addrToAssign = newCall("addr", ident("result"))
elif meth.returnType == "string": elif returnType == "string":
isStringRet = true isStringRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs( body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("GodotString"), retValIdent, ident("GodotString"),
))) )))
elif meth.returnType != "void": elif returnType != "void":
isObjRet = true isObjRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs( body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, newNode(nkPtrTy).addChain(ident("GodotObject")), retValIdent, newNode(nkPtrTy).addChain(ident("GodotObject")),
@ -594,7 +601,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
if not isVarargs: if not isVarargs:
body.add(theCall) body.add(theCall)
else: else:
if not meth.returnType.isNil: if meth.returnType.isSome:
isVariantRet = true isVariantRet = true
let callStmt = newNode(nkLetSection).addChain( let callStmt = newNode(nkLetSection).addChain(
newIdentDefs( newIdentDefs(
@ -603,14 +610,14 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
newNode(nkEmpty), theCall)) newNode(nkEmpty), theCall))
body.add(callStmt) body.add(callStmt)
if varargsName.isNil: if varargsName.isNone:
for idx, arg in meth.args: for idx, arg in meth.args:
if arg.typ == "string": if arg.typ == "string":
body.add(newCall("deinit", ident("argToPassToGodot" & $idx))) body.add(newCall("deinit", ident("argToPassToGodot" & $idx)))
if meth.args.len > 0 and not varargsName.isNil: if meth.args.len > 0 and varargsName.isSome:
body.add(freeCall) body.add(freeCall)
if not varargsName.isNil: if varargsName.isSome:
let errCheck = newIfStmt( let errCheck = newIfStmt(
infix(newDotExpr(ident("callError"), ident("error")), ident("!="), infix(newDotExpr(ident("callError"), ident("error")), ident("!="),
newDotExpr(ident("VariantCallErrorType"), ident("OK"))), newDotExpr(ident("VariantCallErrorType"), ident("OK"))),
@ -638,11 +645,11 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
elif isConversionRet: elif isConversionRet:
body.add(newNode(nkAsgn).addChain( body.add(newNode(nkAsgn).addChain(
ident("result"), ident("result"),
newCall(meth.returnType, retValIdent))) newCall(meth.returnType.get, retValIdent)))
elif isWrapperRet: elif isWrapperRet:
body.add(newNode(nkAsgn).addChain( body.add(newNode(nkAsgn).addChain(
ident("result"), ident("result"),
newCall("new" & meth.returnType, retValIdent))) newCall("new" & meth.returnType.get, retValIdent)))
elif isObjRet: elif isObjRet:
body.add(newNode(nkAsgn).addChain(ident("result"), body.add(newNode(nkAsgn).addChain(ident("result"),
newCall(newBracketExpr(ident("asNimGodotObject"), newCall(newBracketExpr(ident("asNimGodotObject"),
@ -655,8 +662,8 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
let procType = if meth.isVirtual: nkMethodDef let procType = if meth.isVirtual: nkMethodDef
else: nkProcDef else: nkProcDef
var params = newSeqOfCap[PNode](meth.args.len + 2) var params = newSeqOfCap[PNode](meth.args.len + 2)
if not meth.returnType.isNil: if meth.returnType.isSome:
params.add(ident(meth.returnType)) params.add(ident(meth.returnType.get))
else: else:
params.add(newNode(nkEmpty)) params.add(newNode(nkEmpty))
if not meth.typ.isSingleton: if not meth.typ.isSingleton:
@ -684,7 +691,7 @@ proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
if meth.isVirtual and meth.isBase and meth.typ.name != "PhysicsBody": if meth.isVirtual and meth.isBase and meth.typ.name != "PhysicsBody":
# Nim doesn't like `base` on PhysicsBody methods - wtf # Nim doesn't like `base` on PhysicsBody methods - wtf
pragma.add(ident("base")) pragma.add(ident("base"))
if meth.isDiscardable and not meth.returnType.isNil: if meth.isDiscardable and meth.returnType.isSome:
pragma.add(ident("discardable")) pragma.add(ident("discardable"))
procDecl.sons[4] = pragma procDecl.sons[4] = pragma
tree.add(procDecl) tree.add(procDecl)
@ -729,8 +736,8 @@ proc getMethodInfo(methodObj: JsonNode, types: Table[string, GodotType],
nimName = nimName & "Impl" nimName = nimName & "Impl"
let returnType = if methodObj["return_type"].str != "void": let returnType = if methodObj["return_type"].str != "void":
toNimType(types, methodObj["return_type"].str) some(toNimType(types, methodObj["return_type"].str))
else: nil else: none(string)
const discardableMethods = toSet(["emit_signal"]) const discardableMethods = toSet(["emit_signal"])
result = MethodInfo( result = MethodInfo(
name: ident(nimName), name: ident(nimName),
@ -764,13 +771,13 @@ proc makeProperty(types: Table[string, GodotType], tree: PNode,
let getter = findMethod(obj, propertyObj["getter"].str) let getter = findMethod(obj, propertyObj["getter"].str)
let nimType = if getter.isNil: toNimType(types, propertyObj["type"].str) let nimType = if getter.isNil: toNimType(types, propertyObj["type"].str)
else: getMethodInfo(getter, types, typ).returnType else: getMethodInfo(getter, types, typ).returnType.get("void")
let getterInfo = MethodInfo( let getterInfo = MethodInfo(
name: getterName, name: getterName,
typ: typ, typ: typ,
godotName: propertyObj["getter"].str, godotName: propertyObj["getter"].str,
args: @[], args: newSeq[MethodArg](),
returnType: nimType returnType: some(nimType)
) )
let setterInfo = MethodInfo( let setterInfo = MethodInfo(
name: setterName, name: setterName,
@ -779,10 +786,12 @@ proc makeProperty(types: Table[string, GodotType], tree: PNode,
args: @[MethodArg(name: "val", typ: nimType)] args: @[MethodArg(name: "val", typ: nimType)]
) )
if "index" in propertyObj and propertyObj["index"] != newJInt(-1): if "index" in propertyObj and propertyObj["index"] != newJInt(-1):
getterInfo.args = @[MethodArg(defaultVal: newJString($propertyObj["index"]), getterInfo.args =
typ: "int", kind: ArgKind.Bound)] & getterInfo.args @[MethodArg(defaultVal: newJString($propertyObj["index"]),
setterInfo.args = @[MethodArg(defaultVal: newJString($propertyObj["index"]), typ: "int", kind: ArgKind.Bound)] & getterInfo.args
typ: "int", kind: ArgKind.Bound)] & setterInfo.args setterInfo.args =
@[MethodArg(defaultVal: newJString($propertyObj["index"]),
typ: "int", kind: ArgKind.Bound)] & setterInfo.args
generateMethod(tree, methodBindRegistry, getterInfo, withImplementation) generateMethod(tree, methodBindRegistry, getterInfo, withImplementation)
generateMethod(tree, methodBindRegistry, setterInfo, withImplementation) generateMethod(tree, methodBindRegistry, setterInfo, withImplementation)
@ -920,7 +929,7 @@ proc genApi*(targetDir: string, apiJsonFile: string) =
let className = godotClassName.replace("_", "") let className = godotClassName.replace("_", "")
var baseClassName = obj["base_class"].str var baseClassName = obj["base_class"].str
baseClassName = toNimType(baseClassName.replace("_", "")) baseClassName = toNimType(baseClassName.replace("_", ""))
if baseClassName.isNil or baseClassName.len == 0: if baseClassName.len == 0:
baseClassName = "NimGodotObject" baseClassName = "NimGodotObject"
var doc = "" var doc = ""
for attr in classAttributes: for attr in classAttributes:

View file

@ -38,10 +38,7 @@ proc `$`*(self: GodotString): string =
proc toGodotString*(s: string): GodotString {.inline.} = proc toGodotString*(s: string): GodotString {.inline.} =
## Converts the Nim string into ``GodotString`` ## Converts the Nim string into ``GodotString``
if s.isNil: initGodotString(result, cstring(s), cint(s.len + 1))
initGodotString(result)
else:
initGodotString(result, cstring(s), cint(s.len + 1))
proc toGodotString*(s: cstring): GodotString {.inline.} = proc toGodotString*(s: cstring): GodotString {.inline.} =
## Converts the cstring into ``GodotString`` ## Converts the cstring into ``GodotString``

View file

@ -1,6 +1,6 @@
# Copyright 2018 Xored Software, Inc. # Copyright 2018 Xored Software, Inc.
import macros, tables, typetraits import macros, tables, typetraits, strutils, sets, sequtils, options
import godotinternal, internal.godotvariants import godotinternal, internal.godotvariants
import godotnim, core.variants import godotnim, core.variants
@ -10,8 +10,8 @@ type
typ: NimNode typ: NimNode
defaultValue: NimNode defaultValue: NimNode
isNoGodot: bool isNoGodot: bool
hint: string hint: Option[string]
hintStr: string hintStr: Option[string]
usage: NimNode usage: NimNode
isExported: bool isExported: bool
@ -111,12 +111,12 @@ proc removePragma(statement: NimNode, pname: string): bool =
return true return true
proc removeStrPragma(statement: NimNode, proc removeStrPragma(statement: NimNode,
pname: string): string {.compileTime.} = pname: string): Option[string] {.compileTime.} =
## Removes the pragma from the node and returns value of the pragma ## Removes the pragma from the node and returns value of the pragma
## Works for routine nodes or nnkPragmaExpr ## Works for routine nodes or nnkPragmaExpr
let node = removePragmaNode(statement, pname) let node = removePragmaNode(statement, pname)
result = if node.isNil: nil result = if node.isNil: none(string)
else: $node else: some($node)
proc isExported(node: NimNode): bool {.compileTime.} = proc isExported(node: NimNode): bool {.compileTime.} =
if node.kind == nnkPragmaExpr: if node.kind == nnkPragmaExpr:
@ -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.isNil: result.parentName = "Object" if result.parentName == "": result.parentName = "Object"
for statement in body: for statement in body:
case statement.kind: case statement.kind:
of nnkVarSection: of nnkVarSection:
@ -424,9 +424,6 @@ template registerGodotField(classNameLit, classNameIdent, propNameLit,
unsafeAddr attr, setFunc, getFunc) unsafeAddr attr, setFunc, getFunc)
hintStrGodot.deinit() hintStrGodot.deinit()
static:
import strutils, sets, sequtils
proc toGodotStyle(s: string): string {.compileTime.} = proc toGodotStyle(s: string): string {.compileTime.} =
result = newStringOfCap(s.len + 10) result = newStringOfCap(s.len + 10)
for c in s: for c in s:
@ -447,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.isNil: if obj.parentName == "":
objTy.add(newEmptyNode()) objTy.add(newEmptyNode())
else: else:
objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName))) objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName)))
@ -506,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.isNil: newStrLitNode("Object") let parentName = if obj.parentName == "": 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.isNil: false let isRef: bool = if obj.parentName == "": false
else: obj.parentName in refClasses else: obj.parentName in refClasses
result.add(getAst( result.add(getAst(
registerGodotClass(classNameIdent, classNameLit, isRef, parentName, registerGodotClass(classNameIdent, classNameLit, isRef, parentName,
@ -519,10 +516,10 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
# Register fields (properties) # Register fields (properties)
for field in obj.fields: for field in obj.fields:
if field.isNoGodot: continue if field.isNoGodot: continue
let hintStr = if field.hintStr.isNil: "NIM" let hintStr = if field.hintStr.isNone: "NIM"
else: field.hintStr else: field.hintStr.get
let hint = if field.hint.isNil: "NIM" let hint = if field.hint.isNone: "NIM"
else: field.hint else: field.hint.get
let usage = let usage =
if field.usage.isNil: if field.usage.isNil:
newLit(ord(GodotPropertyUsage.Default) or newLit(ord(GodotPropertyUsage.Default) or

View file

@ -1,6 +1,6 @@
# Copyright 2018 Xored Software, Inc. # Copyright 2018 Xored Software, Inc.
import tables, typetraits, macros, unicode import tables, typetraits, macros, unicode, strutils, sets
import gdnativeapi import gdnativeapi
import core.godotcoretypes, core.godotbase import core.godotcoretypes, core.godotbase
import core.vector2, core.rect2, import core.vector2, core.rect2,
@ -101,8 +101,6 @@ var classRegistryStatic* {.compileTime.}: TableRef[FNV1Hash, ObjectInfo]
static: static:
classRegistryStatic = newTable[FNV1Hash, ObjectInfo]() classRegistryStatic = newTable[FNV1Hash, ObjectInfo]()
static:
import sets, strutils
var nativeClasses {.compileTime.} = newSeq[string]() var nativeClasses {.compileTime.} = newSeq[string]()
var refClasses* {.compileTime.} = newSeq[string]() var refClasses* {.compileTime.} = newSeq[string]()
@ -204,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.isNil: if baseT == "":
result = newNilLit() result = newNilLit()
else: else:
let rStr = newNimNode(nnkRStrLit) let rStr = newNimNode(nnkRStrLit)
@ -345,24 +343,21 @@ proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit) result = newNimNode(nnkRStrLit)
result.strVal = s result.strVal = s
static:
import strutils
macro toGodotName(T: typedesc): string = macro toGodotName(T: typedesc): string =
var godotName: string var godotName =
if T is GodotString or T is string: if T is GodotString or T is string:
godotName = "String" "String"
elif T is SomeFloat: elif T is SomeFloat:
godotName = "float" "float"
elif T is SomeUnsignedInt or T is SomeSignedInt: elif T is SomeUnsignedInt or T is SomeSignedInt:
godotName = "int" "int"
if godotName.isNil or godotName.len == 0:
let nameStr = (($T.getType()[1][1].symbol).split(':')[0])
godotName = case nameStr:
of "File", "Directory", "Thread", "Mutex", "Semaphore":
"_" & nameStr
else: else:
nameStr let nameStr = (($T.getType()[1][1].symbol).split(':')[0])
case nameStr:
of "File", "Directory", "Thread", "Mutex", "Semaphore":
"_" & nameStr
else:
nameStr
result = newLit(godotName) result = newLit(godotName)
@ -717,7 +712,7 @@ 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: elif val.getType() == VariantType.Nil:
s = nil s = ""
else: else:
result = ConversionResult.TypeError result = ConversionResult.TypeError