Always generate init with super call
This commit is contained in:
parent
e3c014a359
commit
b5fd4295e6
2 changed files with 21 additions and 20 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
version = "0.5.6"
|
version = "0.5.7"
|
||||||
author = "Xored Software, Inc."
|
author = "Xored Software, Inc."
|
||||||
description = "Godot Engine bindings"
|
description = "Godot Engine bindings"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
|
|
@ -451,25 +451,26 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
|
||||||
else: postfix(decl.name, "*")
|
else: postfix(decl.name, "*")
|
||||||
recList.add(newIdentDefs(name, decl.typ))
|
recList.add(newIdentDefs(name, decl.typ))
|
||||||
|
|
||||||
# Add default values to init method
|
# Add default values and/or super call to init method
|
||||||
if initBody.len > 0:
|
initBody.insert(0, newNimNode(nnkCommand).add(ident("procCall"),
|
||||||
var initMethod: NimNode
|
newCall("init", newCall(obj.parentName, ident("self")))))
|
||||||
for meth in obj.methods:
|
var initMethod: NimNode
|
||||||
if meth.name == "init" and meth.nimNode[3].len == 1:
|
for meth in obj.methods:
|
||||||
initMethod = meth.nimNode
|
if meth.name == "init" and meth.nimNode[3].len == 1:
|
||||||
break
|
initMethod = meth.nimNode
|
||||||
if initMethod.isNil:
|
break
|
||||||
obj.methods.add(MethodDecl(
|
if initMethod.isNil:
|
||||||
name: "init",
|
obj.methods.add(MethodDecl(
|
||||||
args: newSeq[VarDecl](),
|
name: "init",
|
||||||
returnType: newEmptyNode(),
|
args: newSeq[VarDecl](),
|
||||||
isVirtual: true,
|
returnType: newEmptyNode(),
|
||||||
isNoGodot: false,
|
isVirtual: true,
|
||||||
nimNode: newProc(ident("init"), body = initBody,
|
isNoGodot: false,
|
||||||
procType = nnkMethodDef)
|
nimNode: newProc(ident("init"), body = initBody,
|
||||||
))
|
procType = nnkMethodDef)
|
||||||
else:
|
))
|
||||||
initMethod.body.insert(0, initBody)
|
else:
|
||||||
|
initMethod.body.insert(0, initBody)
|
||||||
|
|
||||||
# {.this: self.} for convenience
|
# {.this: self.} for convenience
|
||||||
result.add(newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
|
result.add(newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue