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

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

View file

@ -1,6 +1,6 @@
# Copyright 2018 Xored Software, Inc.
import tables, typetraits, macros, unicode
import tables, typetraits, macros, unicode, strutils, sets
import gdnativeapi
import core.godotcoretypes, core.godotbase
import core.vector2, core.rect2,
@ -101,8 +101,6 @@ var classRegistryStatic* {.compileTime.}: TableRef[FNV1Hash, ObjectInfo]
static:
classRegistryStatic = newTable[FNV1Hash, ObjectInfo]()
static:
import sets, strutils
var nativeClasses {.compileTime.} = newSeq[string]()
var refClasses* {.compileTime.} = newSeq[string]()
@ -204,7 +202,7 @@ macro baseNativeType(T: typedesc): cstring =
if typeName == "NimGodotObject":
break
t = getType(t[1][1])
if baseT.isNil:
if baseT == "":
result = newNilLit()
else:
let rStr = newNimNode(nnkRStrLit)
@ -345,24 +343,21 @@ proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit)
result.strVal = s
static:
import strutils
macro toGodotName(T: typedesc): string =
var godotName: string
if T is GodotString or T is string:
godotName = "String"
elif T is SomeFloat:
godotName = "float"
elif T is SomeUnsignedInt or T is SomeSignedInt:
godotName = "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
var godotName =
if T is GodotString or T is string:
"String"
elif T is SomeFloat:
"float"
elif T is SomeUnsignedInt or T is SomeSignedInt:
"int"
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)
@ -717,7 +712,7 @@ proc fromVariant*(s: var string, val: Variant): ConversionResult =
if val.getType() == VariantType.String:
s = val.asString()
elif val.getType() == VariantType.Nil:
s = nil
s = ""
else:
result = ConversionResult.TypeError