Create github-pages branch

This commit is contained in:
Ruslan Mustakov 2017-08-01 11:03:37 +07:00
commit e60f8cfe32
30 changed files with 1 additions and 4508 deletions

5
.gitignore vendored
View file

@ -1,4 +1 @@
nimcache/
.DS_Store
/godot/apigen/apigen
/godot/apigen/apigen.exe
.DS_Store

16
.vscode/settings.json vendored
View file

@ -1,16 +0,0 @@
{
"editor.tabSize": 2,
"editor.rulers": [80],
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"nim.project": ["godot/core/godot.nim",
"godot/apigen/apigen.nim"],
"nim.buildOnSave": false,
"nim.lintOnSave": true,
"nim.licenseString": "# Copyright 2017 Xored Software, Inc.\n\n",
"files.exclude": {
"**/nimcache/**": true
}
}

20
LICENSE
View file

@ -1,20 +0,0 @@
godot-nim - Nim bindings for Godot Engine
The MIT License
Copyright (c) 2017 Xored Software Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,14 +0,0 @@
# Nim bindings for Godot Engine
Nim bindings for Godot 3.0 based on [GDNative](https://godotengine.org/article/dlscript-here).
## Links
- [Godot Engine](http://www.godotengine.org/)
- [Nim](http://nim-lang.org/)
## License
This project is licensed under the MIT license. Read [LICENSE](https://github.com/pragmagic/godot-nim/blob/master/LICENSE) file for details.
Copyright (c) 2017 Xored Software, Inc.

View file

@ -1,7 +0,0 @@
[Package]
name: "godot"
version: "0.1.0"
author: "Xored Software, Inc."
description: "Godot Engine bindings"
license: "MIT"
srcDir: "godot"

View file

@ -1,862 +0,0 @@
# Copyright 2017 Xored Software, Inc.
import streams, json, ospaths, strutils, times, sets, tables
import sequtils, algorithm
import compiler / [ast, renderer, idents, astalgo]
proc ident(ident: string): PNode =
result = newNode(nkIdent)
result.ident = getIdent(ident)
proc addChain(node: PNode, others: varargs[PNode]): PNode {.discardable.} =
for other in others:
node.add(other)
result = node
proc newIdentDefs(name, typ: PNode,
defaultVal: PNode = nil): PNode =
result = newNode(nkIdentDefs)
result.add(name)
result.add(typ)
if defaultVal.isNil:
result.add(newNode(nkEmpty))
else:
result.add(defaultVal)
proc newProc(name: PNode, params: openArray[PNode], body = newNode(nkEmpty),
procType = nkProcDef): PNode =
result = newNode(procType)
result.add(name)
result.add(newNode(nkEmpty))
result.add(newNode(nkEmpty))
let formalParams = newNode(nkFormalParams)
for param in params:
formalParams.add(param)
result.add(formalParams)
result.add(newNode(nkEmpty))
result.add(newNode(nkEmpty))
result.add(body)
proc newIfStmt(condition, body: PNode): PNode =
result = newNode(nkIfStmt)
let branch = newNode(nkElifBranch)
result.add(branch)
branch.add(condition)
branch.add(body)
proc newCall(theProc: PNode, args: varargs[PNode]): PNode =
result = newNode(nkCall)
result.add(theProc)
for arg in args:
result.add(arg)
proc newCall(theProc: string, args: varargs[PNode]): PNode =
newCall(ident(theProc), args)
proc newStrLit(s: string): PNode =
result = newNode(nkStrLit)
result.strVal = s
proc newRStrLit(s: string): PNode =
result = newNode(nkRStrLit)
result.strVal = s
proc newCStringLit(s: string): PNode =
newNode(nkCallStrLit).addChain(ident("cstring"), newRStrLit(s))
proc newIntLit(val: BiggestInt): PNode =
result = newNode(nkIntLit)
result.intVal = val
proc newInt64Lit(val: BiggestInt): PNode =
result = newNode(nkInt64Lit)
result.intVal = val
proc newFloatLit(val: BiggestFloat): PNode =
result = newNode(nkFloatLit)
result.floatVal = val
proc newFloat64Lit(val: BiggestFloat): PNode =
result = newNode(nkFloat64Lit)
result.floatVal = val
proc newNilLit(): PNode =
result = newNode(nkNilLit)
proc newDotExpr(left, right: PNode): PNode =
result = newNode(nkDotExpr)
result.add(left)
result.add(right)
proc newCommand(left, right: PNode): PNode =
result = newNode(nkCommand)
result.add(left)
result.add(right)
proc newInfix(left, op, right: PNode): PNode =
result = newNode(nkInfix)
result.add(op)
result.add(left)
result.add(right)
proc newInfix(left: PNode, op: string, right: PNode): PNode =
newInfix(left, ident(op), right)
proc postfix(left: PNode, op: string): PNode =
result = newNode(nkPostfix)
result.add(ident(op))
result.add(left)
proc newExprColonExpr(key, value: PNode): PNode =
newNode(nkExprColonExpr).addChain(key, value)
proc pragma(key: PNode, value: PNode): PNode =
newNode(nkPragma).addChain(key, value)
proc newBracketExpr(first, bracket: PNode): PNode =
newNode(nkBracketExpr).addChain(first, bracket)
proc newEmptyNode(): PNode =
newNode(nkEmpty)
type GodotType = ref object
name: string
godotName: string
baseName: string
doc: string
derivedCount: int
isSingleton: bool
jsonNode: JsonNode
proc findCommonRoot(typeRegistry: Table[string, GodotType],
types: seq[string]): string =
if types.len == 0: return "Object"
var chains = newSeq[seq[string]](types.len)
for idx, typ in types:
chains[idx] = newSeq[string]()
chains[idx].add(typ)
var curTyp = typeRegistry[typ]
while curTyp.baseName != "NimGodotObject":
chains[idx].add(curTyp.baseName)
curTyp = typeRegistry[curTyp.baseName]
chains[idx].reverse()
var idx = 0
while true:
var curType: string
var allEqual = true
for chain in chains:
if idx >= chain.len:
allEqual = false
break
if curType.isNil:
curType = chain[idx]
elif curType != chain[idx]:
allEqual = false
break
if allEqual:
result = curType
else:
break
inc idx
proc incDerivedCount(types: var Table[string, GodotType],
className: string) =
let typ = types.getOrDefault(className)
if not typ.isNil:
inc typ.derivedCount
types.incDerivedCount(typ.baseName)
proc toNimType(godotType: string): string =
case godotType:
of "float": "float64"
of "int": "int64"
of "String": "string"
of "File": "godottypes.File"
else: godotType
proc toNimType(types: Table[string, GodotType], godotType: string): string =
let origType =
if godotType.contains(','):
findCommonRoot(types, godotType.split(','))
else:
godotType
result = toNimType(origType)
proc toNimStyle(name: string): string =
result = newStringOfCap(name.len + 1)
var i = 0
var makeUpperCase: bool
while i < name.len:
if name[i] == '_':
if result.len != 0:
makeUpperCase = true
elif name[i] != '/': # remove slashes
if makeUpperCase:
result.add(name[i].toUpperAscii())
makeUpperCase = false
else:
result.add(name[i])
inc i
while isKeyword(getIdent(result)):
result.add(result[result.len - 1])
if result == "result":
result = "resultVal"
proc newRefTypeNode(typeSection: PNode, typ, base, doc: string,
isExported = true) =
let typeDef = newNode(nkTypeDef)
typeSection.add(typeDef)
if isExported:
typeDef.add(postfix(ident(typ), "*"))
else:
typeDef.add(ident(typ))
typeDef.add(newNode(nkEmpty)) # generic
let objTy = newNode(nkObjectTy)
let refTy = newNode(nkRefTy)
refTy.add(objTy)
typeDef.add(refTy)
objTy.add(newNode(nkEmpty))
let inherit = newNode(nkOfInherit)
inherit.add(ident(base))
objTy.add(inherit)
if not doc.isNil:
let recList = newNode(nkRecList)
let docNode = newNode(nkCommentStmt)
docNode.comment = doc
recList.add(docNode)
objTy.add(recList)
else:
objTy.add(newNode(nkEmpty))
proc makeConstSection(constObj: JsonNode): PNode =
if constObj.len == 0:
return newNode(nkEmpty)
result = newNode(nkConstSection)
for field, val in constObj:
let def = newNode(nkConstDef)
def.add(postfix(ident(field), "*"))
def.add(newNode(nkEmpty)) # infer type
var valNode: PNode
if val.kind == JInt:
valNode = newInt64Lit(val.num)
# valNode.intVal = val.num
elif val.kind == JFloat:
valNode = newFloat64Lit(val.fnum)
elif val.kind == JBool:
valNode = ident($val.bval)
elif val.kind == JString:
valNode = newNode(nkStrLit)
valNode.strVal = val.str
else:
raise newException(ValueError, "Unexpected constant kind: " & $val.kind)
def.add(valNode)
result.add(def)
type MethodArg = tuple[name, typ: string, defaultVal: JsonNode, isVarargs: bool]
const standardTypes = toSet(
["bool", "cint", "int", "uint8", "int8", "uint16", "int16", "uint32", "int32",
"uint64",
"int64", "float32", "cfloat", "float64", "GodotString", "Vector2", "Rect2",
"Vector3", "Transform2D", "Plane", "Quat", "Rect3", "Basis", "Transform",
"Color", "NodePath", "RID", "Dictionary", "Array", "PoolByteArray",
"PoolIntArray", "PoolRealArray", "PoolStringArray", "PoolVector2Array",
"PoolVector3Array", "PoolColorArray", "Variant"])
const smallIntTypes = toSet(["uint8", "int8", "uint16", "int16", "uint32", "int32",
"cint", "int", "Error"])
const int64Types = toSet(["uint64", "int64"])
const intTypes = union(smallIntTypes, int64Types)
const float64Types = toSet(["float64", "cdouble"])
const float32Types = toSet(["float32", "cfloat"])
const floatTypes = union(float64Types, float32Types)
const arrayTypes = toSet(["Array", "PoolByteArray",
"PoolIntArray", "PoolRealArray", "PoolStringArray", "PoolVector2Array",
"PoolVector3Array", "PoolColorArray"])
proc newNilCheck(ident, toAssign: PNode): PNode =
newIfStmt(newCall("isNil", ident),
newNode(nkAsgn).addChain(ident).addChain(
toAssign
)
)
proc singletonName(typ: string): PNode =
ident("singleton" & typ)
proc makeDefaultValue(arg: MethodArg): PNode =
result = newEmptyNode()
if not arg.defaultVal.isNil:
if arg.typ == "bool":
result = ident(arg.defaultVal.str.toLowerAscii())
elif arg.typ in intTypes:
result = newInt64Lit(parseBiggestInt(arg.defaultVal.str))
elif arg.typ == "string" or arg.typ == "NodePath":
result = newStrLit(arg.defaultVal.str)
elif arg.typ in floatTypes:
result = newFloatLit(parseFloat(arg.defaultVal.str))
elif arg.defaultVal.str == "Null":
if arg.typ == "Variant":
result = newCall("variant")
else:
result = newNilLit()
elif arg.typ == "Color":
result = newCall("initColor",
arg.defaultVal.str.split(',').mapIt(newFloatLit(parseFloat(it))))
# elif arg.typ in arrayTypes and (arg.defaultVal.str == "[]" or
# arg.defaultVal.str == "[" & arg.typ & "]"):
# result = newCall("init" & arg.typ)
elif arg.typ == "RID" and arg.defaultVal.str == "[RID]":
result = newCall("initRID")
elif arg.typ == "Vector2" or arg.typ == "Vector3" or arg.typ == "Rect2":
let parts = arg.defaultVal.str.replace("(", "").replace(")", "").
replace(" ", "").
split(",").mapIt(newFloatLit(parseFloat(it)))
if arg.typ.endsWith("r2"):
result = newCall("vec2", parts)
elif arg.typ.endsWith('3'):
result = newCall("vec3", parts)
else:
result = newCall("initRect2", parts)
elif arg.defaultVal.str == "[Object:null]":
result = newNilLit()
elif arg.typ != "Transform" and arg.typ != "Transform2D" and
arg.typ != "Variant" and arg.typ notin arrayTypes: # TODO
raise newException(
ValueError,
"Cannot build default value from $# ($#)" %
[$arg.defaultVal, arg.typ])
proc doGenerateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
name: PNode, godotMethodName: string,
typ: GodotType, args: seq[MethodArg],
returnType: string, isVirtual,
isBase, withImplementation: bool) =
var body: PNode
if not withImplementation:
body = newNode(nkEmpty)
else:
var methodBindName = toNimStyle(
typ.name & "_" & godotMethodName & "_method_bind")
if methodBindName[0].isUpperAscii():
methodBindName[0] = methodBindName[0].toLowerAscii()
if methodBindName notin methodBindRegistry:
let methodBindDecl = newNode(nkVarSection).addChain(
newIdentDefs(
newNode(nkPragmaExpr).addChain(
ident(methodBindName)).addChain(
newNode(nkPragma).addChain(ident("threadvar"))),
newNode(nkPtrTy).addChain(ident("GodotMethodBind"))
))
tree.add(methodBindDecl)
methodBindRegistry.incl(methodBindName)
let nilCheck = newNilCheck(ident(methodBindName),
newCall("getMethod", newCStringLit(typ.godotName),
newCStringLit(godotMethodName))
)
let vars = newNode(nkVarSection)
var varargsName: string
var isVarargs: bool
var staticArgsLen: int
var argLenNode = newIntLit(0)
let argsName = ident("argsToPassToGodot")
if args.len > 0:
for arg in args:
if arg.isVarargs:
varargsName = arg.name
isVarargs = true
vars.add(newIdentDefs(ident("callError"), ident("VariantCallError")))
break
let argsAlloc = newNode(nkCast).addChain(
newNode(nkPtrTy).addChain(
newNode(nkBracketExpr).addChain(
ident("array"), ident("MAX_ARG_COUNT"),
if isVarargs: ident("Variant") else: ident("pointer"))))
staticArgsLen = if varargsName.isNil: args.len
else: args.len - 1
if not varargsName.isNil:
argLenNode = newCall("cint",
newInfix(newIntLit(staticArgsLen),
ident("+"),
newDotExpr(ident(varargsName), ident("len"))))
argsAlloc.add(newCall("godotAlloc", newCall("cint", newInfix(
newCall("sizeof", ident("Variant")), ident("*"),
newNode(nkPar).addChain(argLenNode))))
)
else:
argLenNode = newCall("cint", newIntLit(staticArgsLen))
vars.add(newIdentDefs(
ident("argsStatic"),
newNode(nkBracketExpr).addChain(
ident("array"), newIntLit(staticArgsLen), ident("pointer")),
newNode(nkEmpty)))
argsAlloc.add(newCommand(ident("addr"), ident("argsStatic")))
vars.add(newIdentDefs(argsName, newNode(nkEmpty), argsAlloc))
let argConversions = newNode(nkStmtList)
for idx, arg in args:
var argName = ident(arg.name)
if arg.isVarargs:
argName = newNode(nkBracketExpr).addChain(
ident(varargsName),
newInfix(ident("idx"), ident("-"), newIntLit(staticArgsLen)))
let argIdx = if arg.isVarargs: ident("idx") else: newIntLit(idx)
let isStandardType = arg.typ in standardTypes
let convArg = if not varargsName.isNil: newCall("toGodot", argName)
elif isStandardType: newCall("unsafeAddr", argName)
elif arg.typ == "string": newCall("unsafeAddr",
ident("argToPassToGodot" & $idx))
else: ident("argToPassToGodot" & $idx) # object
if not isStandardType and arg.isVarargs:
raise newException(ValueError,
"Non-standard type $# for varargs params of method $# of type $#" %
[arg.typ, godotMethodName, typ.godotName])
if not isStandardType:
if arg.typ == "string":
argConversions.add(newNode(nkLetSection).addChain(
newIdentDefs(ident("argToPassToGodot" & $idx), newEmptyNode(),
newCall("toGodotString", argName))))
else:
argConversions.add(newNode(nkLetSection).addChain(
newIdentDefs(ident("argToPassToGodot" & $idx), newEmptyNode(),
newDotExpr(argName, ident("godotObject")))))
let argAsgn = newNode(nkAsgn).addChain(
newNode(nkBracketExpr).addChain(
newNode(nkBracketExpr).addChain(argsName), argIdx),
convArg
)
if not arg.isVarargs:
argConversions.add(
argAsgn
)
else:
argConversions.add(newNode(nkVarSection).addChain(
newIdentDefs(ident("idx"), newNode(nkEmpty), newIntLit(staticArgsLen))))
let argLoop = newNode(nkWhileStmt)
argConversions.add(argLoop)
argLoop.add(newInfix(ident("idx"), ident("<"), argLenNode)
)
argLoop.add(argAsgn)
argLoop.add(newCommand(ident("inc"), ident("idx")))
let retName = if isVarargs: "callRet" else: "ptrCallRet"
let theCall = newCall(
newDotExpr(ident(methodBindName),
ident(if isVarargs: "call" else: "ptrCall")),
newDotExpr(ident("self"), ident("godotObject")),
if args.len > 0: argsName else: newNode(nkNilLit),
argLenNode,
if not isVarargs: ident(retName) else: ident("callError")
)
if not isVarargs:
theCall.sons.delete(3)
let freeCall = newCall("godotFree", argsName)
body = newNode(nkStmtList)
if typ.isSingleton:
let varName = singletonName(typ.name)
body.add(newNilCheck(varName, newCall(
newBracketExpr(ident("getSingleton"), ident(typ.name)))))
body.add(newNode(nkLetSection).addChain(newIdentDefs(
ident("self"), newNode(nkEmpty), varName
)))
if not varargsName.isNil:
body.add(
pragma(ident("push"), newExprColonExpr(
newBracketExpr(ident("warning"), ident("Destructor")),
ident("off"))))
body.add(nilCheck)
body.add(vars)
body.add(argConversions)
if not isVarargs:
let retPtrDecl = newNode(nkVarSection).addChain(
newIdentDefs(ident(retName), ident("pointer"), newEmptyNode())
)
body.add(retPtrDecl)
var isVariantRet: bool
var isConversionRet: bool
var isObjRet: bool
var isStringRet: bool
let retValIdent = if not isVarargs: ident("ptrCallVal") else: ident(retName)
if not returnType.isNil and varargsName.isNil:
var addrToAssign = newCall("addr", ident("ptrCallVal"))
if returnType in smallIntTypes:
isConversionRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("int64"),
)))
elif returnType in float32Types:
isConversionRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("float64"),
)))
elif returnType in standardTypes:
addrToAssign = newCall("addr", ident("result"))
elif returnType == "string":
isStringRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, ident("GodotString"),
)))
else:
isObjRet = true
body.add(newNode(nkVarSection).addChain(newIdentDefs(
retValIdent, newNode(nkPtrTy).addChain(ident("GodotObject")),
)))
body.add(newNode(nkAsgn).addChain(ident(retName), addrToAssign))
if not isVarargs:
body.add(theCall)
else:
if not returnType.isNil:
isVariantRet = true
let callStmt = newNode(nkLetSection).addChain(
newIdentDefs(
newNode(nkPragmaExpr).addChain(
ident(retName), newNode(nkPragma).addChain(ident("used"))),
newNode(nkEmpty), theCall))
body.add(callStmt)
# if not returnType.isNil and not varargsName.isNil:
# body.add(newCall("fromGodot", ident("result"), ident(retName)))
# body.add(newCall("deinit", ident(retName)))
if args.len > 0 and not varargsName.isNil:
body.add(freeCall)
if not varargsName.isNil:
let errCheck = newIfStmt(
newInfix(newDotExpr(ident("callError"), ident("error")), ident("!="),
newDotExpr(ident("VariantCallErrorType"), ident("OK"))),
newNode(nkRaiseStmt).addChain(
newCall("newCallError", ident("callError")))
)
body.add(errCheck)
if isVariantRet:
let convErrDef = newNode(nkLetSection).addChain(
newIdentDefs(ident("convErr"), newNode(nkEmpty),
newCall("fromGodot", ident("result"), retValIdent)))
let convCheck = newIfStmt(
newInfix(ident("convErr"), ident("!="),
newDotExpr(ident("ConversionResult"), ident("OK"))),
newNode(nkRaiseStmt).addChain(
newCall("newConversionError", ident("convErr")))
)
body.add(convErrDef)
body.add(convCheck)
if not isVarargs and (isVariantRet or isStringRet):
# varargs use call with "let" so destructor is invoked
body.add(newCall("deinit", retValIdent))
elif isConversionRet:
body.add(newNode(nkAsgn).addChain(ident("result"),
newCall(returnType, retValIdent)))
elif isObjRet:
body.add(newNode(nkAsgn).addChain(ident("result"),
newCall(newBracketExpr(ident("asNimGodotObject"),
newCall("type", ident("result"))), retValIdent)))
elif isStringRet:
body.add(newNode(nkAsgn).addChain(ident("result"),
newCall("$", retValIdent)))
if not varargsName.isNil:
body.add(
pragma(ident("push"), newExprColonExpr(
newBracketExpr(ident("warning"), ident("Destructor")),
ident("on"))))
let procType = if isVirtual: nkMethodDef
else: nkProcDef
var params = newSeqOfCap[PNode](args.len + 2)
if not returnType.isNil:
params.add(ident(returnType))
else:
params.add(newNode(nkEmpty))
if not typ.isSingleton:
params.add(newIdentDefs(ident("self"), ident(toNimType(typ.name))))
for arg in args:
if arg.isVarargs:
params.add(newIdentDefs(ident(arg.name),
newNode(nkBracketExpr).addChain(ident("varargs"), ident(arg.typ))))
else:
let defaultValue = arg.makeDefaultValue()
params.add(newIdentDefs(ident(arg.name), ident(arg.typ), defaultValue))
let procDecl = newProc(if not withImplementation: postfix(name, "*")
else: name,
params, body, procType)
if not withImplementation:
let pragma = newNode(nkPragma)
pragma.add(ident("gcsafe"))
pragma.add(newNode(nkExprColonExpr).addChain(ident("locks"),
newIntLit(0)))
if isVirtual and isBase:
pragma.add(ident("base"))
procDecl.sons[4] = pragma
tree.add(procDecl)
proc generateMethod(tree: PNode, methodBindRegistry: var HashSet[string],
name: PNode, godotMethodName: string,
typ: GodotType, args: seq[MethodArg],
returnType: string, isVirtual, isBase, withImplementation: bool) =
doGenerateMethod(
tree, methodBindRegistry, name, godotMethodName, typ,
args, returnType, isVirtual, isBase, withImplementation)
proc makeProperty(types: Table[string, GodotType], tree: PNode,
methodBindRegistry: var HashSet[string],
typ: GodotType,
propertyObj: JsonNode, withImplementation: bool) =
let getterNameStr = toNimStyle(propertyObj["name"].str)
let getterName = ident(toNimStyle(propertyObj["name"].str))
let setterName = newNode(nkAccQuoted).addChain(ident(getterNameStr & "="))
let nimType = toNimType(types, propertyObj["type"].str)
generateMethod(tree, methodBindRegistry,
getterName, propertyObj["getter"].str, typ,
@[], nimType, isVirtual = false,
isBase = false, withImplementation)
generateMethod(tree, methodBindRegistry,
setterName, propertyObj["setter"].str, typ,
@[("val", nimType, JsonNode(nil), false)],
nil, isVirtual = false, isBase = false, withImplementation)
proc makeMethod(types: Table[string, GodotType], tree: PNode,
methodBindRegistry: var HashSet[string],
typ: GodotType, methodObj: JsonNode,
withImplementation: bool) =
let returnType = if methodObj["return_type"].str != "void":
toNimType(types, methodObj["return_type"].str)
else: nil
for prop in typ.jsonNode["properties"]:
if prop["getter"].str == methodObj["name"].str or
prop["setter"].str == methodObj["name"].str:
return
var args = newSeqOfCap[MethodArg](methodObj["arguments"].len + 1)
var origArgs = methodObj["arguments"]
var isBase = methodObj["is_virtual"].bval
if methodObj["is_virtual"].bval:
proc getMethod(typNode: JsonNode, methName: string): JsonNode =
for meth in typNode["methods"]:
if meth["is_virtual"].bval and
meth["name"].str == methName: return meth
var curTyp = types.getOrDefault(typ.baseName)
while not curTyp.isNil:
let meth = curTyp.jsonNode.getMethod(methodObj["name"].str)
if not meth.isNil:
origArgs = meth["arguments"]
isBase = false
curTyp = types.getOrDefault(curTyp.baseName)
for arg in origArgs:
let typ = toNimType(types, arg["type"].str)
let defaultVal = if arg["has_default_value"].bval: arg["default_value"]
else: nil
args.add((toNimStyle(arg["name"].str), typ,
defaultVal, false))
if methodObj["has_varargs"].bval:
args.add(("variantArgs", "Variant", JsonNode(nil), true))
let godotName = methodObj["name"].str
generateMethod(tree, methodBindRegistry,
ident(toNimStyle(godotName)), methodObj["name"].str,
typ, args,
returnType, methodObj["is_virtual"].bval, isBase,
withImplementation)
proc addAttributeToDoc(doc: var string, propName, propValue: string) =
if doc.len > 0:
doc.add("\n")
doc.add(propName & ": " & propValue)
const classAttributes = ["singleton", "instanciable", "is_reference"]
proc typeNameToModuleName(name: string): string =
var wasUpperOrDigit = true
result = newStringOfCap(name.len + 10)
for idx, c in name:
if c.isUpperAscii() or c.isDigit():
if not wasUpperOrDigit or idx > 0 and idx < name.len - 1 and
name[idx + 1].isLowerAscii():
result.add('_')
result.add(c.toLowerAscii())
wasUpperOrDigit = true
else:
result.add(c)
wasUpperOrDigit = false
if result == "object":
# keyword
result = "objects"
if result == "os":
# to avoid clash with stdlib
result = "gd_os"
proc newRegisterClassNode(typ: GodotType): PNode =
newCall("registerClass",
ident(typ.name),
newCStringLit(typ.godotName),
ident("true") # isNative
)
proc genSingletonDecl(typ: string): PNode =
result = newNode(nkVarSection)
let name = singletonName(typ)
let threadvar = newNode(nkPragma).addChain(ident("threadvar"))
result.add(newIdentDefs(newNode(nkPragmaExpr).addChain(name, threadvar),
ident(typ)))
proc shouldExport(typ: GodotType, types: Table[string, GodotType]): bool =
var curTyp = typ
while not curTyp.isNil and not curTyp.isSingleton:
curTyp = types.getOrDefault(curTyp.baseName)
result = curTyp.isNil
proc genTypeFile*(types: var Table[string, GodotType], targetDir: string) =
for typ in types.values():
types.incDerivedCount(typ.baseName)
var sortedTypes = toSeq(types.values())
sortedTypes.sort do (x, y: GodotType) -> int:
cmp(y.derivedCount, x.derivedCount)
let godotApiTypesTree = newNode(nkStmtList)
godotApiTypesTree.add(newNode(nkImportStmt).addChain(ident("godot")))
let typeSection = newNode(nkTypeSection)
godotApiTypesTree.add(typeSection)
for typ in sortedTypes:
if not typ.shouldExport(types): continue
newRefTypeNode(typeSection, typ.name, typ.baseName, typ.doc)
for typ in sortedTypes:
if not typ.shouldExport(types): continue
let regNode = newCall("registerClass",
ident(typ.name),
newCStringLit(typ.godotName),
ident("true") # isNative
)
godotApiTypesTree.add(regNode)
renderModule(godotApiTypesTree, targetDir / "godottypes.nim")
proc genApi*(targetDir: string, apiJsonFile: string) =
let apiJson = parseJson(newFileStream(apiJsonFile),
apiJsonFile.extractFilename())
var megaImport = newStringOfCap(64 * 1024)
var types = initTable[string, GodotType]()
for obj in apiJson:
let godotClassName = obj["name"].str
let className = godotClassName.replace("_", "")
var baseClassName = obj["base_class"].str
baseClassName = toNimType(baseClassName.replace("_", ""))
if baseClassName.isNil or baseClassName.len == 0:
baseClassName = "NimGodotObject"
var doc = ""
for attr in classAttributes:
if attr in obj:
addAttributeToDoc(doc, attr, $obj[attr])
types[className] = GodotType(
name: className,
godotName: godotClassName,
baseName: baseClassName,
doc: doc,
jsonNode: obj,
isSingleton: obj["singleton"].bval
)
for typ in types.values():
let tree = newNode(nkStmtList)
let importStmt = newNode(nkImportStmt)
importStmt.add(ident("godot"))
importStmt.add(ident("godottypes"))
importStmt.add(newDotExpr(ident("core"), ident("godotcore")))
tree.add(importStmt)
let exportStmt = newNode(nkExportStmt)
exportStmt.add(ident("godottypes"))
tree.add(exportStmt)
var methodBindRegsitry = initSet[string]()
let obj = typ.jsonNode
if typ.baseName != "NimGodotObject":
let baseModule = typeNameToModuleName(typ.baseName)
let baseModuleNode = if getIdent(baseModule).isKeyword:
newStrLit(baseModule & ".nim")
else:
ident(baseModule)
importStmt.add(baseModuleNode)
exportStmt.add(baseModuleNode)
let constSection = makeConstSection(obj["constants"])
if constSection.kind != nkEmpty:
# renderer doesn't properly render empty stmt after type section
tree.add(makeConstSection(obj["constants"]))
if typ.isSingleton:
let typeDecl = newNode(nkTypeSection)
newRefTypeNode(typeDecl, typ.name, typ.baseName, typ.doc,
isExported = false)
tree.add(typeDecl)
tree.add(newRegisterClassNode(typ))
tree.add(genSingletonDecl(typ.name))
# first, generate declarations only for ease of
# human readability of the file
for property in obj["properties"]:
makeProperty(types, tree, methodBindRegsitry, typ, property,
withImplementation = false)
for meth in obj["methods"]:
makeMethod(types, tree, methodBindRegsitry, typ,
meth, withImplementation = false)
for property in obj["properties"]:
makeProperty(types, tree, methodBindRegsitry, typ,
property, withImplementation = true)
for meth in obj["methods"]:
makeMethod(types, tree, methodBindRegsitry, typ, meth,
withImplementation = true)
let moduleName = typeNameToModuleName(typ.name)
renderModule(tree, targetDir / moduleName & ".nim")
megaImport.add("import \"" & moduleName & "\"\n")
genTypeFile(types, targetDir)
writeFile(targetDir / "godotall.nim", megaImport)
when isMainModule:
import os
const usage = slurp("usage.txt")
proc main() =
if paramCount() < 2:
echo usage
quit(-1)
let godotBin = paramStr(1)
let targetDir = paramStr(2)
if not dirExists(targetDir):
echo "The specified directory does not exist"
quit(-1)
if not fileExists(godotBin):
echo "Invalid godot binary path"
quit(-1)
let jsonFile = targetDir / "api.json"
if fileExists(jsonFile) and
godotBin.getLastModificationTime() <= jsonFile.getLastModificationTime():
echo "api.json if up to date - doing nothing."
return
discard execShellCmd(
"\"" & godotBin & "\" --gdnative-generate-json-api \"" & jsonFile & "\"")
if not fileExists(jsonFile):
echo "Failed to generate api.json"
quit(-1)
genApi(targetDir, jsonFile)
main()

View file

@ -1,3 +0,0 @@
Tool for wrapping Godot API into Nim
apigen [godot binary path] [target directory]

View file

@ -1,145 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import hashes
import godotbase, poolarray, variant, strings
proc initArray(dest: var Array) {.
importc: "godot_array_new", header: "godot_array.h".}
proc initArray(dest: var Array; pca: PoolColorArray) {.
importc: "godot_array_new_pool_coloarray",
header: "godot_array.h".}
proc initArray(dest: var Array; pv3a: PoolVector3Array) {.
importc: "godot_array_new_pool_vector3_array",
header: "godot_array.h".}
proc initArray(dest: var Array; pv2a: PoolVector2Array) {.
importc: "godot_array_new_pool_vector2_array",
header: "godot_array.h".}
proc initArray(dest: var Array; psa: PoolStringArray) {.
importc: "godot_array_new_pool_string_array",
header: "godot_array.h".}
proc initArray(dest: var Array; pra: PoolRealArray) {.
importc: "godot_array_new_pool_real_array",
header: "godot_array.h".}
proc initArray(dest: var Array; pia: PoolIntArray) {.
importc: "godot_array_new_pool_int_array",
header: "godot_array.h".}
proc initArray(dest: var Array; pba: PoolByteArray) {.
importc: "godot_array_new_pool_byte_array",
header: "godot_array.h".}
proc initArray*(): Array {.inline.} =
initArray(result)
proc initArray*(pca: PoolColorArray): Array {.inline.} =
initArray(result, pca)
proc initArray*(pv3a: PoolVector3Array): Array {.inline.} =
initArray(result, pv3a)
proc initArray*(pv2a: PoolVector2Array): Array {.inline.} =
initArray(result, pv2a)
proc initArray*(psa: PoolStringArray): Array {.inline.} =
initArray(result, psa)
proc initArray*(pra: PoolRealArray): Array {.inline.} =
initArray(result, pra)
proc initArray*(pia: PoolIntArray): Array {.inline.} =
initArray(result, pia)
proc initArray*(pba: PoolByteArray): Array {.inline.} =
initArray(result, pba)
proc `[]=`*(self: var Array; idx: cint;
value: Variant) {.
noSideEffect,
importc: "godot_array_set", header: "godot_array.h".}
proc `[]`*(self: Array; idx: cint): Variant {.
noSideEffect,
importc: "godot_array_get", header: "godot_array.h".}
proc mget*(self: var Array; idx: cint): ptr Variant {.
importc: "godot_array_operator_index", header: "godot_array.h".}
proc add*(self: var Array; value: Variant) {.
noSideEffect,
importc: "godot_array_append", header: "godot_array.h".}
proc clear*(self: var Array) {.importc: "godot_array_clear",
header: "godot_array.h".}
proc count*(self: Array; value: Variant): cint {.
noSideEffect,
importc: "godot_array_count", header: "godot_array.h".}
proc isEmpty*(self: Array): bool {.
noSideEffect,
importc: "godot_array_empty", header: "godot_array.h".}
proc erase*(self: var Array; value: Variant) {.
importc: "godot_array_erase", header: "godot_array.h".}
proc first*(self: Array): Variant {.
noSideEffect,
importc: "godot_array_front", header: "godot_array.h".}
proc last*(self: Array): Variant {.
noSideEffect,
importc: "godot_array_back", header: "godot_array.h".}
proc find*(self: Array; what: Variant;
f: cint): cint {.
noSideEffect,
importc: "godot_array_find", header: "godot_array.h".}
proc findLast*(self: Array; what: Variant): cint {.
noSideEffect,
importc: "godot_array_find_last", header: "godot_array.h".}
proc contains*(self: Array; value: Variant): bool {.
noSideEffect,
importc: "godot_array_has", header: "godot_array.h".}
proc godotHash*(self: Array): cint {.
noSideEffect,
importc: "godot_array_hash", header: "godot_array.h".}
proc hash*(self: Array): Hash {.inline.} =
hash(godotHash(self))
proc insert*(self: var Array; pos: cint;
value: Variant) {.
importc: "godot_array_insert", header: "godot_array.h".}
proc reverse*(self: var Array) {.importc: "godot_array_invert",
header: "godot_array.h".}
proc popLast*(self: var Array): Variant {.
importc: "godot_array_pop_back", header: "godot_array.h".}
proc popFirst*(self: var Array): Variant {.
importc: "godot_array_pop_front", header: "godot_array.h".}
proc addLast*(self: var Array; value: Variant) {.
importc: "godot_array_push_back", header: "godot_array.h".}
proc addFirst*(self: var Array; value: Variant) {.
importc: "godot_array_push_front", header: "godot_array.h".}
proc delete*(self: var Array; idx: cint) {.
importc: "godot_array_remove", header: "godot_array.h".}
proc setLen*(self: var Array; size: cint) {.
importc: "godot_array_resize", header: "godot_array.h".}
proc rfind*(self: Array; what: Variant;
f: cint): cint {.
noSideEffect,
importc: "godot_array_rfind", header: "godot_array.h".}
proc len*(self: Array): cint {.
noSideEffect,
importc: "godot_array_size", header: "godot_array.h".}
proc sort*(self: var Array) {.importc: "godot_array_sort",
header: "godot_array.h".}
proc sortCustom*(self: var Array; obj: var GodotObject;
funcName: GodotString) {.
importc: "godot_array_sort_custom", header: "godot_array.h".}
iterator items*(arr: Array): Variant =
for i in 0..<arr.len:
yield arr[i]
iterator mitems*(arr: var Array): var Variant =
for i in 0..<arr.len:
yield arr.mget(i)[]
iterator pairs*(arr: Array): tuple[key: cint, val: Variant] =
for i in 0..<arr.len:
yield (i, arr[i])
iterator mpairs*(arr: var Array): tuple[key: cint, val: var Variant] =
for i in 0..<arr.len:
yield (i, arr.mget(i)[])

View file

@ -1,140 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, vector3, quat, strings
type
Basis* {.importc: "godot_basis", header: "godot_basis.h", byref.} = object
proc initBasis(dest: var Basis) {.importc: "godot_basis_new",
header: "godot_basis.h".}
proc initBasis(dest: var Basis;
xAxis: Vector3;
yAxis: Vector3;
zAxis: Vector3) {.
importc: "godot_basis_new_with_rows", header: "godot_basis.h".}
proc initBasis(dest: var Basis;
euler: Quat) {.
importc: "godot_basis_new_with_euler_quat", header: "godot_basis.h".}
proc initBasis(dest: var Basis; axis: Vector3; phi: float32) {.
importc: "godot_basis_new_with_axis_and_angle", header: "godot_basis.h".}
proc initBasis(dest: var Basis; euler: Vector3) {.
importc: "godot_basis_new_with_euler", header: "godot_basis.h".}
proc initBasis*(): Basis {.inline.} =
initBasis(result)
proc initBasis*(xAxis, yAxis, zAxis: Vector3): Basis {.inline.} =
initBasis(result, xAxis, yAxis, zAxis)
proc initBasis*(euler: Quat): Basis {.inline.} =
initBasis(result, euler)
proc initBasis*(axis: Vector3, phi: float32): Basis {.inline.} =
initBasis(result, axis, phi)
proc initBasis*(euler: Vector3): Basis {.inline.} =
initBasis(result, euler)
proc toGodotString*(self: Basis): GodotString {.
noSideEffect,
importc: "godot_basis_as_string", header: "godot_basis.h".}
proc `$`*(self: Basis): string {.inline.} =
$self.toGodotString()
proc inverse*(self: Basis): Basis {.
noSideEffect,
importc: "godot_basis_inverse", header: "godot_basis.h".}
proc transposed*(self: Basis): Basis {.
noSideEffect,
importc: "godot_basis_transposed", header: "godot_basis.h".}
proc orthonormalized*(self: Basis): Basis {.
noSideEffect,
importc: "godot_basis_orthonormalized", header: "godot_basis.h".}
proc determinant*(self: Basis): float32 {.
noSideEffect,
importc: "godot_basis_determinant", header: "godot_basis.h".}
proc rotated*(self: Basis; axis: Vector3;
phi: float32): Basis {.
noSideEffect,
importc: "godot_basis_rotated", header: "godot_basis.h".}
proc scaled*(self: Basis; scale: Vector3): Basis {.
noSideEffect,
importc: "godot_basis_scaled", header: "godot_basis.h".}
proc setScale*(self: var Basis; scale: Vector3) {.
noSideEffect,
importc: "godot_basis_set_scale", header: "godot_basis.h".}
proc setRotationEuler*(self: var Basis;
euler: Vector3) {.
noSideEffect,
importc: "godot_basis_set_rotation_euler", header: "godot_basis.h".}
proc setRotationAxisAngle*(self: var Basis; axis: Vector3; angle: float32) {.
noSideEffect,
importc: "godot_basis_set_rotation_axis_angle", header: "godot_basis.h".}
proc scale*(self: Basis): Vector3 {.
noSideEffect,
importc: "godot_basis_get_scale", header: "godot_basis.h".}
proc euler*(self: Basis): Vector3 {.
noSideEffect,
importc: "godot_basis_get_euler", header: "godot_basis.h".}
proc tdotx*(self: Basis; x: Vector3): float32 {.
noSideEffect,
importc: "godot_basis_tdotx", header: "godot_basis.h".}
proc tdoty*(self: Basis; y: Vector3): float32 {.
noSideEffect,
importc: "godot_basis_tdoty", header: "godot_basis.h".}
proc tdotz*(self: Basis; z: Vector3): float32 {.
noSideEffect,
importc: "godot_basis_tdotz", header: "godot_basis.h".}
proc xform*(self: Basis; v: Vector3): Vector3 {.
noSideEffect,
importc: "godot_basis_xform", header: "godot_basis.h".}
proc xformInv*(self: Basis; v: Vector3): Vector3 {.
noSideEffect,
importc: "godot_basis_xform_inv", header: "godot_basis.h".}
proc orthogonalIndex*(self: Basis): cint {.
noSideEffect,
importc: "godot_basis_get_orthogonal_index", header: "godot_basis.h".}
proc godot_basis_get_elements(self: Basis;
elements: var array[3, Vector3]) {.
noSideEffect,
importc: "godot_basis_get_elements", header: "godot_basis.h".}
proc elements*(self: Basis): array[3, Vector3] {.inline.} =
godot_basis_get_elements(self, result)
proc `[]`*(self: Basis; axis: range[0..2]): Vector3 {.
noSideEffect,
importc: "godot_basis_get_axis", header: "godot_basis.h".}
proc `[]=`*(self: var Basis; axis: range[0..2];
value: Vector3) {.
noSideEffect,
importc: "godot_basis_set_axis", header: "godot_basis.h".}
proc row*(self: Basis; row: cint): Vector3 {.
noSideEffect,
importc: "godot_basis_get_row", header: "godot_basis.h".}
proc setRow*(self: var Basis; row: cint;
value: Vector3) {.
noSideEffect,
importc: "godot_basis_set_row", header: "godot_basis.h".}
proc `==`*(self: Basis; b: Basis): bool {.
noSideEffect,
importc: "godot_basis_operator_equal", header: "godot_basis.h".}
proc `+`*(self: Basis; b: Basis): Basis {.
noSideEffect,
importc: "godot_basis_operator_add", header: "godot_basis.h".}
proc `-`*(self: Basis; b: Basis): Basis {.
noSideEffect,
importc: "godot_basis_operator_substract", header: "godot_basis.h".}
proc `*`*(self: Basis; b: Basis): Basis {.
noSideEffect,
importc: "godot_basis_operator_multiply_vector", header: "godot_basis.h".}
proc `*`*(self: Basis; b: float32): Basis {.
noSideEffect,
importc: "godot_basis_operator_multiply_scalar", header: "godot_basis.h".}

View file

@ -1,76 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, strings
type
Color* {.importc: "godot_color", header: "godot_color.h", byref.} = object
proc initColor(dest: var Color; r, g, b, a: float32) {.
importc: "godot_color_new_rgba", header: "godot_color.h".}
proc initColor(dest: var Color; r, g, b: float32) {.
importc: "godot_color_new_rgb",
header: "godot_color.h".}
proc initColor*(r, g, b, a: float32): Color {.inline.} =
initColor(result, r, g, b, a)
proc initColor*(r, g, b: float32): Color {.inline.} =
initColor(result, r, g, b)
proc r*(self: Color): float32 {.
importc: "godot_color_get_r", header: "godot_color.h".}
proc `r=`*(self: var Color; r: float32) {.
importc: "godot_color_set_r", header: "godot_color.h".}
proc g*(self: Color): float32 {.
importc: "godot_color_get_g", header: "godot_color.h".}
proc `g=`*(self: var Color; g: float32) {.
importc: "godot_color_set_g", header: "godot_color.h".}
proc b*(self: Color): float32 {.
importc: "godot_color_get_b", header: "godot_color.h".}
proc `b=`*(self: var Color; b: float32) {.
importc: "godot_color_set_b", header: "godot_color.h".}
proc a*(self: Color): float32 {.
importc: "godot_color_get_a", header: "godot_color.h".}
proc `a=`*(self: var Color; a: float32) {.
importc: "godot_color_set_a", header: "godot_color.h".}
proc h*(self: Color): float32 {.
importc: "godot_color_get_h", header: "godot_color.h".}
proc s*(self: Color): float32 {.
importc: "godot_color_get_s", header: "godot_color.h".}
proc v*(self: Color): float32 {.
importc: "godot_color_get_v", header: "godot_color.h".}
proc toGodotString*(self: Color): GodotString {.
importc: "godot_color_as_string", header: "godot_color.h".}
proc `$`*(self: Color): string {.inline.} =
$self.toGodotString()
proc toHtml*(self: Color; with_alpha: bool): GodotString {.
importc: "godot_color_to_html", header: "godot_color.h".}
proc to32CInt(self: Color): cint {.
importc: "godot_color_to_32", header: "godot_color.h".}
proc toARGB32CInt(self: Color): cint {.
importc: "godot_color_to_ARGB32", header: "godot_color.h".}
proc to32*(self: Color): uint32 {.inline.}=
cast[uint32](to32CInt(self))
proc toARGB32*(self: Color): uint32 {.inline.} =
cast[uint32](toARGB32CInt(self))
proc gray*(self: Color): float32 {.
importc: "godot_color_gray", header: "godot_color.h".}
proc inverted*(self: Color): Color {.
importc: "godot_color_inverted", header: "godot_color.h".}
proc contrasted*(self: Color): Color {.
importc: "godot_color_contrasted", header: "godot_color.h".}
proc lerp*(self: Color; b: Color; t: float32): Color {.
importc: "godot_color_linear_interpolate", header: "godot_color.h".}
proc blend*(self: Color; over: Color): Color {.
importc: "godot_color_blend", header: "godot_color.h".}
proc `==`*(self, b: Color): bool {.
importc: "godot_color_operator_equal", header: "godot_color.h".}
proc `<`*(self, b: Color): bool {.
importc: "godot_color_operator_less", header: "godot_color.h".}

View file

@ -1,81 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import hashes
import godotbase, arrays, variant, strings
type
Dictionary* {.importc: "godot_dictionary",
header: "godot_dictionary.h", byref.} = object
proc initDictionary(dest: var Dictionary;
src: Dictionary) {.
importc: "godot_dictionary_new_copy",
header: "godot_dictionary.h".}
proc deinit(self: var Dictionary) {.
importc: "godot_dictionary_destroy", header: "godot_dictionary.h".}
proc `=`(self: var Dictionary, other: Dictionary) {.inline.} =
initDictionary(self, other)
proc `=destroy`(self: Dictionary) {.inline.} =
unsafeAddr(self)[].deinit()
proc initDictionary(dest: var Dictionary) {.
importc: "godot_dictionary_new", header: "godot_dictionary.h".}
proc initDictionary*(): Dictionary {.inline.} =
initDictionary(result)
proc len*(self: Dictionary): cint {.
importc: "godot_dictionary_size", header: "godot_dictionary.h".}
proc isEmpty*(self: Dictionary): bool {.
importc: "godot_dictionary_empty", header: "godot_dictionary.h".}
proc clear*(self: var Dictionary) {.
importc: "godot_dictionary_clear", header: "godot_dictionary.h".}
proc contains*(self: Dictionary; key: Variant): bool {.
importc: "godot_dictionary_has",
header: "godot_dictionary.h".}
proc contains*(self: Dictionary; keys: Array): bool {.
importc: "godot_dictionary_has_all",
header: "godot_dictionary.h".}
proc del*(self: var Dictionary; key: Variant) {.
importc: "godot_dictionary_erase", header: "godot_dictionary.h".}
proc godotHash*(self: Dictionary): cint {.
importc: "godot_dictionary_hash", header: "godot_dictionary.h".}
proc hash*(self: Dictionary): Hash {.inline.} =
hash(godotHash(self))
proc keys*(self: Dictionary): Array {.
importc: "godot_dictionary_keys", header: "godot_dictionary.h".}
proc values*(self: Dictionary): Array {.
importc: "godot_dictionary_values", header: "godot_dictionary.h".}
proc `[]`*(self: Dictionary; key: Variant): Variant {.
importc: "godot_dictionary_get", header: "godot_dictionary.h".}
proc `[]=`*(self: var Dictionary; key, value: Variant) {.
importc: "godot_dictionary_set",
header: "godot_dictionary.h".}
proc mget*(self: var Dictionary; key: Variant): ptr Variant {.
importc: "godot_dictionary_operator_index",
header: "godot_dictionary.h".}
proc `==`*(self, other: Dictionary): bool {.
importc: "godot_dictionary_operator_equal",
header: "godot_dictionary.h".}
proc toJson*(self: Dictionary): GodotString {.
importc: "godot_dictionary_to_json", header: "godot_dictionary.h".}
iterator keys*(dict: Dictionary): Variant =
let keyArr = dict.keys()
for key in keyArr:
yield key
iterator values*(dict: Dictionary): Variant =
let valArr = dict.values()
for val in valArr:
yield val
iterator pairs*(dict: Dictionary): tuple[key, val: Variant] =
for key in keys(dict):
yield (key, dict[key])

View file

@ -1,107 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
type
Error* {.importc: "godot_error", header: "../godot.h",
size: sizeof(cint), pure.} = enum
OK,
Failed, ## Generic fail error
Unavailable, ## What is requested is unsupported/unavailable
Unconfigured, ## The object being used hasnt been properly set up yet
Unauthorized, ## Missing credentials for requested resource
ParameterRangeError, ## Parameter given out of range (5)
OutOfMemory, ## Out of memory
FileNotFound,
FileBadDrive,
FileBadPath,
FileNoPermission, ## (10)
FileAlreadyInUse,
FileCantOpen,
FileCantWrite,
FileCantRead,
FileUnrecognized, ## (15)
FileCorrupt,
FileMissingDependencies,
FileEOF,
CantOpen, ## Can't open a resource/socket/file
CantCreate, ## (20)
QueryFailed,
AlreadyInUse,
Locked, ## resource is locked
Timeout,
CantConnect, ## (25)
CantResolve,
ConnectionError,
CantAquireResource,
CantFork,
InvalidData, ## Data passed is invalid (30)
InvalidParameter, ## Parameter passed is invalid
AlreadyExists, ## When adding, item already exists
DoesNotExist, ## When retrieving/erasing, it item does not exist
DatabaseCantRead, ## Database is full
DatabaseCantWrite, ## Database is full (35)
CompilationFailed,
MethodNotFound,
LinkFailed,
ScriptFailed,
CyclicLink, ## (40)
InvalidDeclaration,
DuplicateSymbol,
PauseError,
Busy,
Skip, ## (45)
Help, ## user requested help!!
Bug,
## a bug in the software certainly happened, due to a double
## check failing or unexpected behavior.
PrinterOnFire, ## the parallel port printer is engulfed in flames
WTF ## shit happens, has never been used, though
const MAX_ARG_COUNT* = 128
type
GodotObject* {.importc: "godot_object", header: "../godot.h".} = object
Array* {.importc: "godot_array", header: "godot_array.h", byref.} = object
Variant* {.importc: "godot_variant",
header: "godot_variant.h", byref.} = object
proc initArray(dest: var Array, src: Array) {.
importc: "godot_array_new_copy",
header: "godot_array.h".}
proc deinit(self: var Array) {.importc: "godot_array_destroy",
header: "godot_array.h".}
proc `=`(self: var Array, other: Array) {.inline.} =
initArray(self, other)
proc `=destroy`(self: Array) {.inline.} =
unsafeAddr(self).deinit()
proc initVariant(dest: var Variant; src: Variant) {.
importc: "godot_variant_new_copy", header: "godot_variant.h".}
proc deinit*(self: var Variant) {.
importc: "godot_variant_destroy", header: "godot_variant.h".}
proc `=`(self: var Variant, other: Variant) {.inline.} =
initVariant(self, other)
proc `=destroy`(self: Variant) {.inline.} =
unsafeAddr(self).deinit()
# System Functions
proc godotAlloc*(bytes: cint): pointer {.
importc: "godot_alloc", header: "../godot.h".}
## Allocates the specified number of bytes.
## Using this instead of stdlib proc will help Godot track how much memory
## is in use in debug mode.
proc godotRealloc*(p: pointer; bytes: cint): pointer {.
importc: "godot_realloc", header: "../godot.h".}
## Reallocates the pointer for the specified number of bytes.
## Using this instead of stdlib proc will help Godot track how much memory
## is in use in debug mode.
proc godotFree*(p: pointer) {.importc: "godot_free", header: "../godot.h".}
## Frees the memory pointed to by the pointer.
## Using this instead of stdlib proc will help Godot track how much memory
## is in use in debug mode.

View file

@ -1,296 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase
import strings, vector2, rect2, vector3, transform2d, plane, quat
import rect3, basis, transform, color, nodepath, rid
import dictionary, arrays, poolarray, variant
export godotbase, strings, vector2, rect2, vector3, transform2d, plane, quat,
rect3, basis, transform, color, nodepath, rid, dictionary, arrays,
poolarray, variant
# MethodBind API
type
GodotMethodBind* {.importc: "godot_method_bind",
header: "../godot.h".} = object
proc getMethod*(className: cstring; methodName: cstring): ptr GodotMethodBind {.
importc: "godot_method_bind_get_method", header: "../godot.h".}
proc ptrCall*(methodBind: ptr GodotMethodBind;
instance: ptr GodotObject;
args: ptr array[MAX_ARG_COUNT, pointer];
ret: pointer) {.
importc: "godot_method_bind_ptrcall", header: "../godot.h".}
proc call*(methodBind: ptr GodotMethodBind;
instance: ptr GodotObject;
args: ptr array[MAX_ARG_COUNT, Variant]; argCount: cint;
callError: var VariantCallError): Variant {.
importc: "godot_method_bind_call", header: "../godot.h".}
var getClassMethodBind {.threadvar.}: ptr GodotMethodBind
proc getClassName*(o: ptr GodotObject): string =
if getClassMethodBind.isNil:
getClassMethodBind = getMethod(cstring"Object", cstring"get_class")
var ret: GodotString
getClassMethodBind.ptrCall(o, nil, addr ret)
result = $ret
# Script API
type
GodotNativeInitOptions* {.importc: "godot_native_init_options",
header: "../godot.h".} = object
inEditor* {.importc: "in_editor".}: bool
coreApiHash* {.importc: "core_api_hash".}: uint64
editorApiHash* {.importc: "editor_api_hash".}: uint64
noApiHash* {.importc: "no_api_hash".}: uint64
GodotNativeTerminateOptions* {.importc: "godot_native_terminate_options",
header: "../godot.h".} = object
inEditor* {.importc: "in_editor".}: bool
GodotMethodRPCMode* {.importc: "godot_method_rpc_mode", header: "../godot.h",
size: sizeof(cint), pure.} = enum
Disabled,
Remote,
Sync,
Master,
Slave
GodotMethodAttributes* {.importc: "godot_method_attributes",
header: "../godot.h".} = object
rpcMode* {.importc: "rpc_type".}: GodotMethodRPCMode
GodotPropertyHint* {.importc: "godot_property_hint", header: "../godot.h",
size: sizeof(cint), pure.} = enum
None, ## no hint provided.
Range, ## hint_text = "min,max,step,slider; // slider is optional"
ExpRange, ## hint_text = "min,max,step", exponential edit
Enum, ## hint_text= "val1,val2,val3,etc"
ExpEasing, ## exponential easing funciton (Math::ease)
Length, ## hint_text= "length" (as integer)
SpriteFrame,
KeyAccel, ## hint_text= "length" (as integer)
Flags, ## hint_text= "flag1,flag2,etc" (as bit flags)
Layers2DRender,
Layers2DPhysics,
Layers3DRender,
Layers3DPhysics,
File, ## a file path must be passed, hint_text (optionally)
## is a filter "*.png,*.wav,*.doc,"
Dir, ## a directort path must be passed
GlobalFile, ## a file path must be passed, hint_text (optionally) is a
## filter "*.png,*.wav,*.doc,"
GlobalDir, ## a directort path must be passed
ResourceType, ## a resource object type
MultilineText, ## used for string properties that can contain multiple lines
ColorNoAlpha, ## used for ignoring alpha component when editing a color
ImageCompressLossy,
ImageCompressLossless,
ObjectId,
TypeString, ## a type string, the hint is the base type to choose
NodePathToEditedNode, ## so something else can provide this
## (used in scripts)
MethodOfVariantType, ## a method of a type
MethodOfBaseType, ## a method of a base type
MethodOfInstance, ## a method of an instance
MethodOfScript, ## a method of a script & base
PropertyOfVariantType, ## a property of a type
PropertyOfBaseType, ## a property of a base type
PropertyOfInstance, ## a property of an instance
PropertyOfScript, ## a property of a script & base
PropertyHintMax
const
GODOT_PROPERTY_USAGE_STORAGE_VALUE = 1.cint
GODOT_PROPERTY_USAGE_EDITOR_VALUE = 2.cint
GODOT_PROPERTY_USAGE_NETWORK_VALUE = 4.cint
GODOT_PROPERTY_USAGE_EDITOR_HELPER_VALUE = 8.cint
GODOT_PROPERTY_USAGE_CHECKABLE_VALUE = 16.cint
GODOT_PROPERTY_USAGE_CHECKED_VALUE = 32.cint
GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE = 64.cint
GODOT_PROPERTY_USAGE_GROUP_VALUE = 128.cint
GODOT_PROPERTY_USAGE_CATEGORY_VALUE = 256.cint
GODOT_PROPERTY_USAGE_STORE_IF_NONZERO_VALUE = 512.cint
GODOT_PROPERTY_USAGE_STORE_IF_NONONE_VALUE = 1024.cint
GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE_VALUE = 2048.cint
GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED_VALUE = 4096.cint
GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE_VALUE = 8192.cint
GODOT_PROPERTY_USAGE_STORE_IF_NULL_VALUE = 16384.cint
GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER_VALUE = 32768.cint
GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE = 65536.cint
GODOT_PROPERTY_USAGE_DEFAULT_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or GODOT_PROPERTY_USAGE_EDITOR_VALUE or
GODOT_PROPERTY_USAGE_NETWORK_VALUE
GODOT_PROPERTY_USAGE_DEFAULT_INTL_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or
GODOT_PROPERTY_USAGE_EDITOR_VALUE or GODOT_PROPERTY_USAGE_NETWORK_VALUE or
GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE
GODOT_PROPERTY_USAGE_NOEDITOR_VALUE: cint =
GODOT_PROPERTY_USAGE_STORAGE_VALUE or GODOT_PROPERTY_USAGE_NETWORK_VALUE
type
GodotPropertyUsageFlags* {.importc: "godot_property_usage_flags",
header: "../godot.h", size: sizeof(cint),
pure.} = enum
Storage = GODOT_PROPERTY_USAGE_STORAGE_VALUE
Editor = GODOT_PROPERTY_USAGE_EDITOR_VALUE
Network = GODOT_PROPERTY_USAGE_NETWORK_VALUE
NoEditor = GODOT_PROPERTY_USAGE_NOEDITOR_VALUE
Default = GODOT_PROPERTY_USAGE_DEFAULT_VALUE
EditorHelper = GODOT_PROPERTY_USAGE_EDITOR_HELPER_VALUE
Checkable = GODOT_PROPERTY_USAGE_CHECKABLE_VALUE
## used for editing global variables
Checked = GODOT_PROPERTY_USAGE_CHECKED_VALUE
## used for editing global variables
Internationalized = GODOT_PROPERTY_USAGE_INTERNATIONALIZED_VALUE
## hint for internationalized strings
DefaultIntl = GODOT_PROPERTY_USAGE_DEFAULT_INTL_VALUE
Group = GODOT_PROPERTY_USAGE_GROUP_VALUE
## used for grouping props in the editor
Category = GODOT_PROPERTY_USAGE_CATEGORY_VALUE
NonZero = GODOT_PROPERTY_USAGE_STORE_IF_NONZERO_VALUE
## only store if nonzero
NonOne = GODOT_PROPERTY_USAGE_STORE_IF_NONONE_VALUE
## only store if false
NoInstanceState = GODOT_PROPERTY_USAGE_NO_INSTANCE_STATE_VALUE
RestartIfChanged = GODOT_PROPERTY_USAGE_RESTART_IF_CHANGED_VALUE
ScriptVariable = GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE_VALUE
StoreIfNull = GODOT_PROPERTY_USAGE_STORE_IF_NULL_VALUE
AnimateAsTrigger = GODOT_PROPERTY_USAGE_ANIMATE_AS_TRIGGER_VALUE
UpdateAllIfModified = GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE
GodotPropertyAttributes* {.importc: "godot_property_attributes",
header: "../godot.h", bycopy.} = object
rsetType* {.importc: "rset_type".}: GodotMethodRPCMode
typ* {.importc: "type".}: cint
hint* {.importc: "hint".}: GodotPropertyHint
hintString* {.importc: "hint_string".}: GodotString
usage* {.importc: "usage".}: GodotPropertyUsageFlags
defaultValue* {.importc: "default_value".}: Variant
GodotInstanceCreateFunc* {.importc: "godot_instance_create_func",
header: "../godot.h", bycopy.} = object
createFunc* {.importc: "create_func".}:
proc (obj: ptr GodotObject; methodData: pointer): pointer {.noconv.}
## returns user data
methodData* {.importc: "method_data".}: pointer
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
GodotInstanceDestroyFunc* {.importc: "godot_instance_destroy_func",
header: "../godot.h", bycopy.} = object
destroyFunc* {.importc: "destroy_func".}:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer) {.noconv.}
methodData* {.importc: "method_data".}: pointer
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterClass*(name, base: cstring;
create_func: GodotInstanceCreateFunc;
destroy_func: GodotInstanceDestroyFunc) {.
importc: "godot_script_register_class", header: "../godot.h".}
proc godotScriptRegisterToolClass*(name, base: cstring;
createFunc: GodotInstanceCreateFunc;
destroyFunc: GodotInstanceDestroyFunc) {.
importc: "godot_script_register_tool_class", header: "../godot.h".}
type
GodotInstanceMethod* {.importc: "godot_instance_method",
header: "../godot.h", bycopy.} = object
meth* {.importc: "method".}:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer; numArgs: cint;
args: var ptr array[MAX_ARG_COUNT, Variant]): Variant {.noconv.}
methodData* {.importc: "method_data".}: pointer
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterMethod*(name: cstring; function_name: cstring;
attr: GodotMethodAttributes;
meth: GodotInstanceMethod) {.
importc: "godot_script_register_method", header: "../godot.h".}
type
GodotPropertySetFunc* {.importc: "godot_property_set_func",
header: "../godot.h", bycopy.} = object
setFunc* {.importc: "set_func".}: proc (obj: ptr GodotObject;
methodData: pointer;
userData: pointer;
value: Variant) {.noconv.}
methodData* {.importc: "method_data".}: pointer
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
GodotPropertyGetFunc* {.importc: "godot_property_get_func",
header: "../godot.h", bycopy.} = object
getFunc* {.importc: "get_func".}:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer): Variant {.noconv.}
methodData* {.importc: "method_data".}: pointer
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterProperty*(name: cstring; path: cstring;
attr: var GodotPropertyAttributes;
setFunc: GodotPropertySetFunc;
getFunc: GodotPropertyGetFunc) {.
importc: "godot_script_register_property", header: "../godot.h".}
type
GodotSignalArgument* {.importc: "godot_signal_argument",
header: "../godot.h", bycopy.} = object
name* {.importc: "name".}: GodotString
typ* {.importc: "type".}: cint
hint* {.importc: "hint".}: GodotPropertyHint
hintString* {.importc: "hint_string".}: GodotString
usage* {.importc: "usage".}: GodotPropertyUsageFlags
defaultValue* {.importc: "default_value".}: Variant
GodotSignal* {.importc: "godot_signal", header: "../godot.h".} = object
name* {.importc: "name".}: GodotString
numArgs* {.importc: "num_args".}: cint
args* {.importc: "args".}: ptr GodotSignalArgument
numDefaultArgs* {.importc: "num_default_args".}: cint
defaultArgs* {.importc: "default_args".}: ptr Variant
proc godotScriptRegisterSignal*(name: cstring; signal: GodotSignal) {.
importc: "godot_script_register_signal", header: "../godot.h".}
proc getUserdata*(instance: ptr GodotObject): pointer {.
importc: "godot_native_get_userdata", header: "../godot.h".}
type
GodotClassConstructor* = proc (): ptr GodotObject {.gcsafe, noconv.}
proc getClassConstructor*(className: cstring): GodotClassConstructor {.
importc: "godot_get_class_constructor", header: "../godot.h".}
proc getGlobalConstants*(): Dictionary {.
importc: "godot_get_global_constants", header: "../godot.h".}
proc godotNew*(p_classname: cstring): ptr GodotObject {.
importc: "godot_new", header: "../godot.h".}
proc godotStackBottom*(): pointer {.
importc: "godot_get_stack_bottom", header: "../godot.h".}
proc deinit*(o: ptr GodotObject) {.
importc: "godot_object_destroy", header: "../godot.h".}
# print using Godot's error handler list
proc godotPrintError(description: cstring; function: cstring; file: cstring;
line: cint) {.
importc: "godot_print_error", header: "../godot.h".}
proc godotPrintWarning(description: cstring; function: cstring;
file: cstring; line: cint) {.
importc: "godot_print_warning", header: "../godot.h".}
proc godotPrint(message: GodotString) {.
importc: "godot_print", header: "../godot.h".}
proc print*(message: string) {.inline.} =
let s = message.toGodotString()
godotPrint(s)
template printWarning*(warn: typed) =
let (filename, line) = instantiationInfo()
godotPrintWarning(cstring($warn), nil, cstring(filename), line.cint)
template printError*(err: typed) =
let (filename, line) = instantiationInfo()
godotPrintError(cstring($err), nil, cstring(filename), line.cint)

View file

@ -1,55 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, strings
type
NodePath* {.importc: "godot_node_path",
header: "godot_node_path.h", byref.} = object
proc initNodePath(dest: var NodePath; s: GodotString) {.
importc: "godot_node_path_new", header: "godot_node_path.h".}
proc initNodePath(dest: var NodePath;
src: NodePath) {.
importc: "godot_node_path_new_copy", header: "godot_node_path.h".}
proc deinit(self: var NodePath) {.
importc: "godot_node_path_destroy", header: "godot_node_path.h".}
proc initNodePath*(s: string): NodePath {.inline.} =
initNodePath(result, s.toGodotString())
proc `=destroy`(self: NodePath) {.inline.} =
unsafeAddr(self).deinit()
proc `=`(self: var NodePath, other: NodePath) {.inline.} =
initNodePath(self, other)
proc toGodotString*(self: NodePath): GodotString {.
importc: "godot_node_path_as_string", header: "godot_node_path.h".}
proc `$`*(self: NodePath): string {.inline.} =
let s = self.toGodotString()
result = $s
proc isAbsolute*(self: NodePath): bool {.
importc: "godot_node_path_is_absolute", header: "godot_node_path.h".}
proc nameCount*(self: NodePath): cint {.
importc: "godot_node_path_get_name_count",
header: "godot_node_path.h".}
proc getName*(self: NodePath; idx: cint): GodotString {.
importc: "godot_node_path_get_name", header: "godot_node_path.h".}
proc subnameCount*(self: NodePath): cint {.
importc: "godot_node_path_get_subname_count",
header: "godot_node_path.h".}
proc getSubname*(self: NodePath; idx: cint): GodotString {.
importc: "godot_node_path_get_subname",
header: "godot_node_path.h".}
proc property*(self: NodePath): GodotString {.
importc: "godot_node_path_get_property", header: "godot_node_path.h".}
proc isEmpty*(self: NodePath): bool {.
importc: "godot_node_path_is_empty", header: "godot_node_path.h".}
proc `==`*(a, b: NodePath): bool {.
importc: "godot_node_path_operator_equal",
header: "godot_node_path.h".}
converter fromString*(s: string): NodePath =
initNodePath(result, s.toGodotString())

View file

@ -1,84 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, vector3, strings
type
Plane* {.importc: "godot_plane", header: "godot_plane.h", byref.} = object
proc initPlane(dest: var Plane; a, b, c, d: float32) {.
importc: "godot_plane_new_with_reals", header: "godot_plane.h".}
proc initPlane(dest: var Plane; v1, v2, v3: Vector3) {.
importc: "godot_plane_new_with_vectors",
header: "godot_plane.h".}
proc initPlane(dest: var Plane; normal: Vector3; d: float32) {.
importc: "godot_plane_new_with_normal",
header: "godot_plane.h".}
proc initPlane*(a, b, c, d: float32): Plane =
initPlane(result, a, b, c, d)
proc initPlane*(v1, v2, v3: Vector3): Plane =
initPlane(result, v1, v2, v3)
proc initPlane*(normal: Vector3; d: float32): Plane =
initPlane(result, normal, d)
proc toGodotString*(self: Plane): GodotString {.
noSideEffect,
importc: "godot_plane_as_string", header: "godot_plane.h".}
proc `$`*(self: Plane): string {.inline.} =
$self.toGodotString()
proc normalized*(self: Plane): Plane {.
noSideEffect,
importc: "godot_plane_normalized", header: "godot_plane.h".}
proc center*(self: Plane): Vector3 {.
noSideEffect,
importc: "godot_plane_center", header: "godot_plane.h".}
proc getAnyPoint*(self: Plane): Vector3 {.
noSideEffect,
importc: "godot_plane_get_any_point", header: "godot_plane.h".}
proc isPointOver*(self: Plane; point: Vector3): bool {.
noSideEffect,
importc: "godot_plane_is_point_over",
header: "godot_plane.h".}
proc distanceTo*(self: Plane; point: Vector3): float32 {.
noSideEffect,
importc: "godot_plane_distance_to", header: "godot_plane.h".}
proc contains*(self: Plane; point: Vector3;
epsilon: float32): bool {.
noSideEffect,
importc: "godot_plane_has_point", header: "godot_plane.h".}
proc project*(self: Plane; point: Vector3): Vector3 {.
noSideEffect,
importc: "godot_plane_project", header: "godot_plane.h".}
proc intersect3*(self: Plane; dest: var Vector3;
b, c: Plane): bool {.
noSideEffect,
importc: "godot_plane_intersect_3",
header: "godot_plane.h".}
proc intersectsRay*(self: Plane; dest: var Vector3;
v, dir: Vector3): bool {.
noSideEffect,
importc: "godot_plane_intersects_ray",
header: "godot_plane.h".}
proc intersectsSegment*(self: Plane; dest: var Vector3;
segmentBegin, segmentEnd: Vector3): bool {.
noSideEffect, importc: "godot_plane_intersects_segment",
header: "godot_plane.h".}
proc `-`*(self: Plane): Plane {.
noSideEffect,
importc: "godot_plane_operator_neg", header: "godot_plane.h".}
proc `==`*(a, b: Plane): bool {.
noSideEffect,
importc: "godot_plane_operator_equal", header: "godot_plane.h".}
proc normal*(self: Plane): Vector3 {.
noSideEffect,
importc: "godot_plane_get_normal", header: "godot_plane.h".}
proc `normal=`*(self: var Plane; normal: Vector3) {.
importc: "godot_plane_set_normal", header: "godot_plane.h".}
proc d*(self: Plane): float32 {.
noSideEffect,
importc: "godot_plane_get_d", header: "godot_plane.h".}
proc `d=`*(self: var Plane; d: float32) {.
importc: "godot_plane_set_d", header: "godot_plane.h".}

View file

@ -1,476 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, color, vector2, vector3, strings
type
PoolByteArray* {.importc: "godot_pool_byte_array",
header: "godot_pool_arrays.h", byref.} = object
PoolIntArray* {.importc: "godot_pool_int_array",
header: "godot_pool_arrays.h", byref.} = object
PoolRealArray* {.importc: "godot_pool_real_array",
header: "godot_pool_arrays.h", byref.} = object
PoolStringArray* {.importc: "godot_pool_string_array",
header: "godot_pool_arrays.h", byref.} = object
PoolVector2Array* {.importc: "godot_pool_vector2_array",
header: "godot_pool_arrays.h", byref.} = object
PoolVector3Array* {.importc: "godot_pool_vector3_array",
header: "godot_pool_arrays.h", byref.} = object
PoolColorArray* {.importc: "godot_pool_color_array",
header: "godot_pool_arrays.h", byref.} = object
# byte
proc initPoolByteArray(dest: var PoolByteArray) {.
importc: "godot_pool_byte_array_new", header: "godot_pool_arrays.h".}
proc initPoolByteArray(dest: var PoolByteArray;
src: PoolByteArray) {.
importc: "godot_pool_byte_array_new_copy",
header: "godot_pool_arrays.h".}
proc initPoolByteArray(dest: var PoolByteArray; arr: Array) {.
importc: "godot_pool_byte_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolByteArray) {.
importc: "godot_pool_byte_array_destroy", header: "godot_pool_arrays.h".}
proc initPoolByteArray*(): PoolByteArray {.inline.} =
initPoolByteArray(result)
proc initPoolByteArray*(arr: Array): PoolByteArray {.inline.} =
initPoolByteArray(result, arr)
proc `=`(self: var PoolByteArray, other: PoolByteArray) {.inline.} =
initPoolByteArray(self, other)
proc `=destroy`(self: PoolByteArray) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolByteArray;
data: uint8) {.
importc: "godot_pool_byte_array_append", header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolByteArray, data: uint8) {.
importc: "godot_pool_byte_array_push_back", header: "godot_pool_arrays.h".}
proc add*(self: var PoolByteArray;
arr: PoolByteArray) {.
importc: "godot_pool_byte_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolByteArray; idx: cint;
data: uint8): Error {.
importc: "godot_pool_byte_array_insert", header: "godot_pool_arrays.h".}
proc delete*(self: var PoolByteArray; idx: cint) {.
importc: "godot_pool_byte_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolByteArray) {.
importc: "godot_pool_byte_array_invert", header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolByteArray; size: cint) {.
importc: "godot_pool_byte_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolByteArray; idx: cint; data: uint8) {.
importc: "godot_pool_byte_array_set", header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolByteArray; idx: cint): uint8 {.
noSideEffect,
importc: "godot_pool_byte_array_get",
header: "godot_pool_arrays.h".}
proc len*(self: PoolByteArray): cint {.
noSideEffect,
importc: "godot_pool_byte_array_size", header: "godot_pool_arrays.h".}
iterator items*(arr: PoolByteArray): byte =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolByteArray): tuple[key: cint, val: byte] =
for i in 0..<arr.len:
yield (i, arr[i])
proc initPoolIntArray(dest: var PoolIntArray) {.
importc: "godot_pool_int_array_new", header: "godot_pool_arrays.h".}
proc initPoolIntArray(dest: var PoolIntArray;
src: PoolIntArray) {.
importc: "godot_pool_int_array_new_copy", header: "godot_pool_arrays.h".}
proc initPoolIntArray(dest: var PoolIntArray;
arr: Array) {.
importc: "godot_pool_int_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolIntArray) {.
importc: "godot_pool_int_array_destroy", header: "godot_pool_arrays.h".}
proc initPoolIntArray*(): PoolIntArray {.inline.} =
initPoolIntArray(result)
proc initPoolIntArray*(arr: Array): PoolIntArray {.inline.} =
initPoolIntArray(result, arr)
proc `=`(self: var PoolIntArray, other: PoolIntArray) {.inline.} =
initPoolIntArray(self, other)
proc `=destroy`(self: PoolIntArray) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolIntArray; data: cint) {.
importc: "godot_pool_int_array_append", header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolIntArray; data: cint) {.
importc: "godot_pool_int_array_push_back", header: "godot_pool_arrays.h".}
proc add*(self: var PoolIntArray; arr: PoolIntArray) {.
importc: "godot_pool_int_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolIntArray; idx: cint;
data: cint): Error {.
importc: "godot_pool_int_array_insert", header: "godot_pool_arrays.h".}
proc delete*(self: var PoolIntArray; idx: cint) {.
importc: "godot_pool_int_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolIntArray) {.
importc: "godot_pool_int_array_invert", header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolIntArray; size: cint) {.
importc: "godot_pool_int_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolIntArray; idx: cint; data: cint) {.
importc: "godot_pool_int_array_set", header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolIntArray; idx: cint): cint {.
noSideEffect,
importc: "godot_pool_int_array_get",
header: "godot_pool_arrays.h".}
proc len*(self: PoolIntArray): cint {.
noSideEffect,
importc: "godot_pool_int_array_size",
header: "godot_pool_arrays.h".}
iterator items*(arr: PoolIntArray): cint =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolIntArray): tuple[key: cint, val: cint] =
for i in 0..<arr.len:
yield (i, arr[i])
# Real
proc initPoolRealArray(dest: var PoolRealArray) {.
importc: "godot_pool_real_array_new", header: "godot_pool_arrays.h".}
proc initPoolRealArray(dest: var PoolRealArray;
src: PoolRealArray) {.
importc: "godot_pool_real_array_new_copy",
header: "godot_pool_arrays.h".}
proc initPoolRealArray(dest: var PoolRealArray; arr: Array) {.
importc: "godot_pool_real_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolRealArray) {.
importc: "godot_pool_real_array_destroy", header: "godot_pool_arrays.h".}
proc initPoolRealArray*(): PoolRealArray {.inline.} =
initPoolRealArray(result)
proc initPoolRealArray*(arr: Array): PoolRealArray {.inline.} =
initPoolRealArray(result, arr)
proc `=`(self: var PoolRealArray, other: PoolRealArray) {.inline.} =
initPoolRealArray(self, other)
proc `=destroy`(self: PoolRealArray) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolRealArray; data: float32) {.
importc: "godot_pool_real_array_append",
header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolRealArray; data: float32) {.
importc: "godot_pool_real_array_push_back", header: "godot_pool_arrays.h".}
proc add*(self: var PoolRealArray; arr: PoolRealArray) {.
importc: "godot_pool_real_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolRealArray;
idx: cint; data: float32): Error {.
importc: "godot_pool_real_array_insert", header: "godot_pool_arrays.h".}
proc delete*(self: var PoolRealArray; idx: cint) {.
importc: "godot_pool_real_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolRealArray) {.
importc: "godot_pool_real_array_invert", header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolRealArray; size: cint) {.
importc: "godot_pool_real_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolRealArray; idx: cint; data: float32) {.
importc: "godot_pool_real_array_set", header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolRealArray; idx: cint): float32 {.
noSideEffect,
importc: "godot_pool_real_array_get",
header: "godot_pool_arrays.h".}
proc len*(self: PoolRealArray): cint {.
noSideEffect,
importc: "godot_pool_real_array_size", header: "godot_pool_arrays.h".}
iterator items*(arr: PoolRealArray): float32 =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolRealArray): tuple[key: cint, val: float32] =
for i in 0..<arr.len:
yield (i, arr[i])
# String
proc initPoolStringArray(dest: var PoolStringArray) {.
importc: "godot_pool_string_array_new", header: "godot_pool_arrays.h".}
proc initPoolStringArray(dest: var PoolStringArray;
src: PoolStringArray) {.
importc: "godot_pool_string_array_new_copy",
header: "godot_pool_arrays.h".}
proc initPoolStringArray(dest: var PoolStringArray; arr: Array) {.
importc: "godot_pool_string_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolStringArray) {.
importc: "godot_pool_string_array_destroy",
header: "godot_pool_arrays.h".}
proc initPoolStringArray*(): PoolStringArray {.inline.} =
initPoolStringArray(result)
proc initPoolStringArray*(arr: Array): PoolStringArray {.inline.} =
initPoolStringArray(result, arr)
proc `=`(self: var PoolStringArray, other: PoolStringArray) {.inline.} =
initPoolStringArray(self, other)
proc `=destroy`(self: PoolStringArray) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolStringArray; data: GodotString) {.
importc: "godot_pool_string_array_append",
header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolStringArray; data: GodotString) {.
importc: "godot_pool_string_array_push_back",
header: "godot_pool_arrays.h".}
proc add*(self: var PoolStringArray; arr: PoolStringArray) {.
importc: "godot_pool_string_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolStringArray;
idx: cint; data: GodotString): Error {.
importc: "godot_pool_string_array_insert",
header: "godot_pool_arrays.h".}
proc delete*(self: var PoolStringArray; idx: cint) {.
importc: "godot_pool_string_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolStringArray) {.
importc: "godot_pool_string_array_invert", header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolStringArray; size: cint) {.
importc: "godot_pool_string_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolStringArray; idx: cint;
data: GodotString) {.
importc: "godot_pool_string_array_set",
header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolStringArray; idx: cint): GodotString {.
noSideEffect,
importc: "godot_pool_string_array_get",
header: "godot_pool_arrays.h".}
proc len*(self: PoolStringArray): cint {.
noSideEffect,
importc: "godot_pool_string_array_size",
header: "godot_pool_arrays.h".}
iterator items*(arr: PoolStringArray): GodotString =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolStringArray): tuple[key: cint, val: GodotString] =
for i in 0..<arr.len:
yield (i, arr[i])
# Vector2
proc initPoolVector2Array(dest: var PoolVector2Array) {.
importc: "godot_pool_vector2_array_new", header: "godot_pool_arrays.h".}
proc initPoolVector2Array(dest: var PoolVector2Array;
src: PoolVector2Array) {.
importc: "godot_pool_vector2_array_new_copy",
header: "godot_pool_arrays.h".}
proc initPoolVector2Array(dest: var PoolVector2Array; arr: Array) {.
importc: "godot_pool_vector2_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolVector2Array) {.
importc: "godot_pool_vector2_array_destroy", header: "godot_pool_arrays.h".}
proc initPoolVector2Array*(): PoolVector2Array {.inline.} =
initPoolVector2Array(result)
proc initPoolVector2Array*(arr: Array): PoolVector2Array {.inline.} =
initPoolVector2Array(result, arr)
proc `=`(self: var PoolVector2Array, other: PoolVector2Array) {.inline.} =
initPoolVector2Array(self, other)
proc `=destroy`(self: PoolVector2Array) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolVector2Array; data: Vector2) {.
importc: "godot_pool_vector2_array_append",
header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolVector2Array; data: Vector2) {.
importc: "godot_pool_vector2_array_push_back",
header: "godot_pool_arrays.h".}
proc add*(self: var PoolVector2Array;
arr: PoolVector2Array) {.
importc: "godot_pool_vector2_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolVector2Array;
idx: cint; data: Vector2): Error {.
importc: "godot_pool_vector2_array_insert",
header: "godot_pool_arrays.h".}
proc delete*(self: var PoolVector2Array; idx: cint) {.
importc: "godot_pool_vector2_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolVector2Array) {.
importc: "godot_pool_vector2_array_invert",
header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolVector2Array; size: cint) {.
importc: "godot_pool_vector2_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolVector2Array; idx: cint;
data: ptr Vector2) {.
importc: "godot_pool_vector2_array_set", header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolVector2Array; idx: cint): Vector2 {.
noSideEffect,
importc: "godot_pool_vector2_array_get", header: "godot_pool_arrays.h".}
proc len*(self: PoolVector2Array): cint {.
noSideEffect,
importc: "godot_pool_vector2_array_size", header: "godot_pool_arrays.h".}
iterator items*(arr: PoolVector2Array): Vector2 =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolVector2Array): tuple[key: cint, val: Vector2] =
for i in 0..<arr.len:
yield (i, arr[i])
# Vector3
proc initPoolVector3Array*(dest: var PoolVector3Array) {.
importc: "godot_pool_vector3_array_new", header: "godot_pool_arrays.h".}
proc initPoolVector3Array*(dest: var PoolVector3Array;
src: PoolVector3Array) {.
importc: "godot_pool_vector3_array_new_copy",
header: "godot_pool_arrays.h".}
proc initPoolVector3Array*(dest: var PoolVector3Array; arr: Array) {.
importc: "godot_pool_vector3_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolVector3Array) {.
importc: "godot_pool_vector3_array_destroy",
header: "godot_pool_arrays.h".}
proc initPoolVector3Array*(): PoolVector3Array {.inline.} =
initPoolVector3Array(result)
proc initPoolVector3Array*(arr: Array): PoolVector3Array {.inline.} =
initPoolVector3Array(result, arr)
proc `=`(self: var PoolVector3Array, other: PoolVector3Array) {.inline.} =
initPoolVector3Array(self, other)
proc `=destroy`(self: PoolVector3Array) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolVector3Array;
data: Vector3) {.
importc: "godot_pool_vector3_array_append",
header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolVector3Array;
data: Vector3) {.
importc: "godot_pool_vector3_array_push_back",
header: "godot_pool_arrays.h".}
proc add*(self: var PoolVector3Array;
arr: PoolVector3Array) {.
importc: "godot_pool_vector3_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolVector3Array;
idx: cint; data: Vector3): Error {.
importc: "godot_pool_vector3_array_insert",
header: "godot_pool_arrays.h".}
proc delete*(self: var PoolVector3Array; idx: cint) {.
importc: "godot_pool_vector3_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolVector3Array) {.
importc: "godot_pool_vector3_array_invert", header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolVector3Array; size: cint) {.
importc: "godot_pool_vector3_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolVector3Array;
idx: cint; data: Vector3) {.
importc: "godot_pool_vector3_array_set",
header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolVector3Array;
idx: cint): Vector3 {.
noSideEffect,
importc: "godot_pool_vector3_array_get",
header: "godot_pool_arrays.h".}
proc len*(self: PoolVector3Array): cint {.
noSideEffect,
importc: "godot_pool_vector3_array_size",
header: "godot_pool_arrays.h".}
iterator items*(arr: PoolVector3Array): Vector3 =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolVector3Array): tuple[key: cint, val: Vector3] =
for i in 0..<arr.len:
yield (i, arr[i])
# Color
proc initPoolColorArray(dest: var PoolColorArray) {.
importc: "godot_pool_color_array_new", header: "godot_pool_arrays.h".}
proc initPoolColorArray(dest: var PoolColorArray;
src: PoolColorArray) {.
importc: "godot_pool_color_array_new_copy",
header: "godot_pool_arrays.h".}
proc initPoolColorArray(dest: var PoolColorArray; arr: Array) {.
importc: "godot_pool_color_array_new_with_array",
header: "godot_pool_arrays.h".}
proc deinit(self: var PoolColorArray) {.
importc: "godot_pool_color_array_destroy", header: "godot_pool_arrays.h".}
proc initPoolColorArray*(): PoolColorArray {.inline.} =
initPoolColorArray(result)
proc initPoolColorArray*(arr: Array): PoolColorArray {.inline.} =
initPoolColorArray(result, arr)
proc `=`(self: var PoolColorArray, other: PoolColorArray) {.inline.} =
initPoolColorArray(self, other)
proc `=destroy`(self: PoolColorArray) {.inline.} =
unsafeAddr(self).deinit()
proc add*(self: var PoolColorArray; data: Color) {.
importc: "godot_pool_color_array_append",
header: "godot_pool_arrays.h".}
proc addFirst*(self: var PoolColorArray; data: Color) {.
importc: "godot_pool_color_array_push_back",
header: "godot_pool_arrays.h".}
proc add*(self: var PoolColorArray; arr: PoolColorArray) {.
importc: "godot_pool_color_array_append_array",
header: "godot_pool_arrays.h".}
proc insert*(self: var PoolColorArray;
idx: cint; data: Color): Error {.
importc: "godot_pool_color_array_insert",
header: "godot_pool_arrays.h".}
proc delete*(self: var PoolColorArray; idx: cint) {.
importc: "godot_pool_color_array_remove", header: "godot_pool_arrays.h".}
proc reverse*(self: var PoolColorArray) {.
importc: "godot_pool_color_array_invert", header: "godot_pool_arrays.h".}
proc setLen*(self: var PoolColorArray; size: cint) {.
importc: "godot_pool_color_array_resize", header: "godot_pool_arrays.h".}
proc `[]=`*(self: var PoolColorArray; idx: cint;
data: Color) {.
importc: "godot_pool_color_array_set", header: "godot_pool_arrays.h".}
proc `[]`*(self: PoolColorArray; idx: cint): Color {.
noSideEffect,
importc: "godot_pool_color_array_get", header: "godot_pool_arrays.h".}
proc len*(self: PoolColorArray): cint {.
noSideEffect,
importc: "godot_pool_color_array_size", header: "godot_pool_arrays.h".}
iterator items*(arr: PoolColorArray): Color =
for i in 0..<arr.len:
yield arr[i]
iterator pairs*(arr: PoolColorArray): tuple[key: cint, val: Color] =
for i in 0..<arr.len:
yield (i, arr[i])

View file

@ -1,114 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, vector3, strings
type
Quat* {.importc: "godot_quat", header: "godot_quat.h", byref.} = object
proc initQuat(dest: var Quat; x, y, z, w: float32) {.
importc: "godot_quat_new", header: "godot_quat.h".}
proc initQuat(dest: var Quat; axis: Vector3; angle: float32) {.
importc: "godot_quat_new_with_axis_angle",
header: "godot_quat.h".}
proc initQuat*(x, y, z, w: float32): Quat {.inline.} =
initQuat(result, x, y, z, w)
proc initQuat*(axis: Vector3; angle: float32): Quat {.inline.} =
initQuat(result, axis, angle)
proc x*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_get_x", header: "godot_quat.h".}
proc `x=`*(self: var Quat; val: float32) {.
noSideEffect,
importc: "godot_quat_set_x", header: "godot_quat.h".}
proc y*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_get_y", header: "godot_quat.h".}
proc `y=`*(self: var Quat; val: float32) {.
noSideEffect,
importc: "godot_quat_set_y", header: "godot_quat.h".}
proc z*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_get_z", header: "godot_quat.h".}
proc `z=`*(self: var Quat; val: float32) {.
noSideEffect,
importc: "godot_quat_set_z", header: "godot_quat.h".}
proc w*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_get_w", header: "godot_quat.h".}
proc `w=`*(self: var Quat; val: float32) {.
noSideEffect,
importc: "godot_quat_set_w", header: "godot_quat.h".}
proc toGodotString*(self: Quat): GodotString {.
noSideEffect,
importc: "godot_quat_as_string", header: "godot_quat.h".}
proc `$`*(self: Quat): string {.inline.} =
$self.toGodotString()
proc length*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_length", header: "godot_quat.h".}
proc lengthSquared*(self: Quat): float32 {.
noSideEffect,
importc: "godot_quat_length_squared", header: "godot_quat.h".}
proc normalized*(self: Quat): Quat {.
noSideEffect,
importc: "godot_quat_normalized", header: "godot_quat.h".}
proc isNormalized*(self: Quat): bool {.
noSideEffect,
importc: "godot_quat_is_normalized", header: "godot_quat.h".}
proc inverse*(self: Quat): Quat {.
noSideEffect,
importc: "godot_quat_inverse", header: "godot_quat.h".}
proc dot*(a, b: Quat): float32 {.
noSideEffect,
importc: "godot_quat_dot", header: "godot_quat.h".}
proc xform*(self: Quat; v: Vector3): Vector3 {.
noSideEffect,
importc: "godot_quat_xform", header: "godot_quat.h".}
proc slerp*(self: Quat; b: Quat; t: float32): Quat {.
noSideEffect,
importc: "godot_quat_slerp", header: "godot_quat.h".}
proc slerpni*(self: Quat; b: Quat; t: float32): Quat {.
noSideEffect,
importc: "godot_quat_slerpni", header: "godot_quat.h".}
proc cubicSlerp*(self, b, pre_a, post_b: Quat;
t: float32): Quat {.
noSideEffect,
importc: "godot_quat_cubic_slerp",
header: "godot_quat.h".}
proc `*`*(a: Quat, b: float32): Quat {.
noSideEffect,
importc: "godot_quat_operator_multiply",
header: "godot_quat.h".}
proc `*=`*(a: var Quat, b: float32) {.inline.} =
a = a * b
proc `+`*(a, b: Quat): Quat {.
noSideEffect,
importc: "godot_quat_operator_add", header: "godot_quat.h".}
proc `+=`*(a: var Quat, b: Quat) {.inline.} =
a = a + b
proc `-`*(a, b: Quat): Quat {.
noSideEffect,
importc: "godot_quat_operator_substract",
header: "godot_quat.h".}
proc `-=`* (a: var Quat, b: Quat) {.inline.} =
a = a - b
proc `/`*(self: Quat; b: float32): Quat {.
noSideEffect,
importc: "godot_quat_operator_divide", header: "godot_quat.h".}
proc `/=`*(self: var Quat, b: float32) {.inline.} =
self = self / b
proc `==`*(a, b: Quat): bool {.
noSideEffect,
importc: "godot_quat_operator_equal", header: "godot_quat.h".}
proc `-`*(self: Quat): Quat {.
noSideEffect,
importc: "godot_quat_operator_neg", header: "godot_quat.h".}

View file

@ -1,68 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, vector2, strings
type
Rect2* {.importc: "godot_rect2", header: "godot_rect2.h", byref.} = object
proc initRect2(dest: var Rect2; pos, size: Vector2) {.
importc: "godot_rect2_new_with_position_and_size",
header: "godot_rect2.h".}
proc initRect2(dest: var Rect2; x, y, sizeX, sizeY: float32) {.
importc: "godot_rect2_new", header: "godot_rect2.h".}
proc initRect2*(pos, size: Vector2): Rect2 {.inline.} =
initRect2(result, pos, size)
proc initRect2*(x, y, sizeX, sizeY: float32): Rect2 {.inline.} =
initRect2(result, x, y, sizeX, sizeY)
proc toGodotString*(self: Rect2): GodotString {.
noSideEffect,
importc: "godot_rect2_as_string", header: "godot_rect2.h".}
proc `$`*(self: Rect2): string {.inline.} =
$self.toGodotString()
proc area*(self: Rect2): float32 {.
noSideEffect,
importc: "godot_rect2_get_area", header: "godot_rect2.h".}
proc intersects*(a, b: Rect2): bool {.
noSideEffect,
importc: "godot_rect2_intersects", header: "godot_rect2.h".}
proc encloses*(a, b: Rect2): bool {.
noSideEffect,
importc: "godot_rect2_encloses", header: "godot_rect2.h".}
proc hasNoArea*(self: Rect2): bool {.
noSideEffect,
importc: "godot_rect2_has_no_area", header: "godot_rect2.h".}
proc clip*(a, b: Rect2): Rect2 {.
noSideEffect,
importc: "godot_rect2_clip", header: "godot_rect2.h".}
proc merge*(a, b: Rect2): Rect2 {.
noSideEffect,
importc: "godot_rect2_merge", header: "godot_rect2.h".}
proc contains*(self: Rect2; point: Vector2): bool {.
noSideEffect,
importc: "godot_rect2_has_point", header: "godot_rect2.h".}
proc grow*(self: Rect2; by: float32): Rect2 {.
noSideEffect,
importc: "godot_rect2_grow", header: "godot_rect2.h".}
proc expand*(self: Rect2; to: Vector2): Rect2 {.
noSideEffect,
importc: "godot_rect2_expand", header: "godot_rect2.h".}
proc `==`*(a, b: Rect2): bool {.
noSideEffect,
importc: "godot_rect2_operator_equal",
header: "godot_rect2.h".}
proc position*(self: Rect2): Vector2 {.
noSideEffect,
importc: "godot_rect2_get_position", header: "godot_rect2.h".}
proc size*(self: Rect2): Vector2 {.
noSideEffect,
importc: "godot_rect2_get_size", header: "godot_rect2.h".}
proc setPosition*(self: var Rect2; pos: Vector2) {.
noSideEffect,
importc: "godot_rect2_set_position", header: "godot_rect2.h".}
proc setSize*(self: var Rect2; size: Vector2) {.
noSideEffect,
importc: "godot_rect2_set_size", header: "godot_rect2.h".}

View file

@ -1,100 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase, plane, vector3, strings
type
Rect3* {.importc: "godot_rect3", header: "godot_rect3.h", byref.} = object
proc initRect3(dest: var Rect3; pos, size: Vector3) {.
importc: "godot_rect3_new", header: "godot_rect3.h".}
proc initRect3*(pos, size: Vector3): Rect3 {.inline.} =
initRect3(result, pos, size)
proc position*(self: Rect3): Vector3 {.
noSideEffect,
importc: "godot_rect3_get_position", header: "godot_rect3.h".}
proc setPosition*(self: var Rect3; v: Vector3) {.
noSideEffect
importc: "godot_rect3_set_position", header: "godot_rect3.h".}
proc size*(self: Rect3): Vector3 {.
noSideEffect,
importc: "godot_rect3_get_size", header: "godot_rect3.h".}
proc setSize*(self: var Rect3; v: Vector3) {.
noSideEffect,
importc: "godot_rect3_set_size", header: "godot_rect3.h".}
proc toGodotString*(self: Rect3): GodotString {.
noSideEffect,
importc: "godot_rect3_as_string", header: "godot_rect3.h".}
proc `$`*(self: Rect3): string {.inline.} =
$self.toGodotString()
proc area*(self: Rect3): float32 {.
noSideEffect,
importc: "godot_rect3_get_area", header: "godot_rect3.h".}
proc hasNoArea*(self: Rect3): bool {.
noSideEffect,
importc: "godot_rect3_has_no_area", header: "godot_rect3.h".}
proc hasNoSurface*(self: Rect3): bool {.
noSideEffect,
importc: "godot_rect3_has_no_surface", header: "godot_rect3.h".}
proc intersects*(a, b: Rect3): bool {.
noSideEffect,
importc: "godot_rect3_intersects", header: "godot_rect3.h".}
proc encloses*(self, other: Rect3): bool {.
noSideEffect,
importc: "godot_rect3_encloses", header: "godot_rect3.h".}
proc merge*(self, other: Rect3): Rect3 {.
noSideEffect,
importc: "godot_rect3_merge", header: "godot_rect3.h".}
proc intersection*(self, other: Rect3): Rect3 {.
noSideEffect,
importc: "godot_rect3_intersection", header: "godot_rect3.h".}
proc intersectsPlane*(self: Rect3; plane: Plane): bool {.
noSideEffect,
importc: "godot_rect3_intersects_plane",
header: "godot_rect3.h".}
proc intersectsSegment*(self: Rect3; start, to: Vector3): bool {.
noSideEffect,
importc: "godot_rect3_intersects_segment",
header: "godot_rect3.h".}
proc contains*(self: Rect3; point: Vector3): bool {.
noSideEffect,
importc: "godot_rect3_has_point", header: "godot_rect3.h".}
proc getSupport*(self: Rect3; dir: Vector3): Vector3 {.
noSideEffect,
importc: "godot_rect3_get_support", header: "godot_rect3.h".}
proc getLongestAxis*(self: Rect3): Vector3 {.
noSideEffect,
importc: "godot_rect3_get_longest_axis", header: "godot_rect3.h".}
proc getLongestAxisIndex*(self: Rect3): cint {.
noSideEffect,
importc: "godot_rect3_get_longest_axis_index",
header: "godot_rect3.h".}
proc getLongestAxisSize*(self: Rect3): float32 {.
noSideEffect,
importc: "godot_rect3_get_longest_axis_size",
header: "godot_rect3.h".}
proc getShortestAxis*(self: Rect3): Vector3 {.
noSideEffect,
importc: "godot_rect3_get_shortest_axis", header: "godot_rect3.h".}
proc getShortestAxisIndex*(self: Rect3): cint {.
noSideEffect,
importc: "godot_rect3_get_shortest_axis_index",
header: "godot_rect3.h".}
proc getShortestAxisSize*(self: Rect3): float32 {.
noSideEffect,
importc: "godot_rect3_get_shortest_axis_size",
header: "godot_rect3.h".}
proc expand*(self: Rect3; toPoint: Vector3): Rect3 {.
noSideEffect,
importc: "godot_rect3_expand", header: "godot_rect3.h".}
proc grow*(self: Rect3; by: float32): Rect3 {.
noSideEffect,
importc: "godot_rect3_grow", header: "godot_rect3.h".}
proc getEndpoint*(self: Rect3; idx: cint): Vector3 {.
noSideEffect,
importc: "godot_rect3_get_endpoint", header: "godot_rect3.h".}
proc `==`*(a, b: Rect3): bool {.
noSideEffect,
importc: "godot_rect3_operator_equal",
header: "godot_rect3.h".}

View file

@ -1,28 +0,0 @@
import godotbase
type
RID* {.importc: "godot_rid", header: "godot_rid.h", byref.} = object
proc initRID(dest: var RID) {.
importc: "godot_rid_new",
header: "godot_rid.h".}
proc initRID(dest: var RID; obj: ptr GodotObject) {.
importc: "godot_rid_new_with_resource", header: "godot_rid.h".}
proc initRID*(): RID {.inline.} =
initRID(result)
proc initRID*(obj: ptr GodotObject): RID {.inline.} =
initRID(result, obj)
proc idCInt(self: RID): cint {.
noSideEffect,
importc: "godot_rid_get_id", header: "godot_rid.h".}
proc id*(self: RID): uint32 {.inline.} =
cast[uint32](self.idCInt())
proc `==`*(a, b: RID): bool {.
importc: "godot_rid_operator_equal", header: "godot_rid.h".}
proc `<`*(a, b: RID): bool {.
importc: "godot_rid_operator_less", header: "godot_rid.h".}

View file

@ -1,58 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
import godotbase
type
GodotString* {.importc: "godot_string", header: "godot_string.h",
byref.} = object
proc initGodotString(dest: var GodotString) {.
importc: "godot_string_new", header: "godot_string.h".}
proc initGodotString(dest: var GodotString; src: GodotString) {.
importc: "godot_string_new_copy", header: "godot_string.h".}
proc initGodotString(dest: var GodotString; contents: cstring;
size: cint) {.
importc: "godot_string_new_data", header: "godot_string.h".}
## Initializes ``dest`` from UTF-8 ``contents``
proc getData(self: GodotString; dest: cstring;
size: var cint) {.
noSideEffect
importc: "godot_string_get_data",
header: "godot_string.h".}
## Converts ``self`` into UTF-8 encoding, putting the result into ``dest``.
proc len*(self: GodotString): cint {.inline.} =
## Returns the length of string in bytes if it is represented as UTF-8.
getData(self, nil, result)
proc cstring*(self: GodotString): cstring {.
importc: "godot_string_c_str", header: "godot_string.h".}
proc `==`*(self, b: GodotString): bool {.
importc: "godot_string_operator_equal",
header: "godot_string.h".}
proc `<`*(self, b: GodotString): bool {.
importc: "godot_string_operator_less",
header: "godot_string.h".}
proc `&`*(self, b: GodotString): GodotString {.
importc: "godot_string_operator_plus",
header: "godot_string.h".}
proc deinit*(self: var GodotString) {.importc: "godot_string_destroy",
header: "godot_string.h".}
proc `=destroy`(self: GodotString) {.inline.} =
unsafeAddr(self).deinit()
proc `=`(self: var GodotString, other: GodotString) {.inline.} =
initGodotString(self, other)
proc `$`*(self: GodotString): string =
## Converts the ``GodotString`` into Nim string
var length = self.len
result = newStringOfCap(length)
getData(self, addr result[0], length)
result.setLen(length)
assert(result[length] == '\0')
proc toGodotString*(s: string): GodotString {.inline.} =
## Converts the Nim string into ``GodotString``
initGodotString(result, unsafeAddr s[0], cint(s.len + 1))

View file

@ -1,82 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
type
Transform* {.importc: "godot_transform", header: "godot_transform.h",
byref.} = object
import godotbase, basis, variant, vector3, strings, plane, rect3
proc initTransform(dest: var Transform) {.
importc: "godot_transform_new_identity", header: "godot_transform.h".}
## Initializes the ``dest`` as identity transform.
proc initTransform(dest: var Transform;
xAxis, yAxis, zAxis, origin: Vector3) {.
importc: "godot_transform_new_with_axis_origin",
header: "godot_transform.h".}
proc initTransform(dest: var Transform; basis: Basis;
origin: Vector3) {.
importc: "godot_transform_new",
header: "godot_transform.h".}
proc initTransform*(): Transform {.inline.} =
initTransform(result)
proc initTransform*(xAxis, yAxis, zAxis,
origin: Vector3): Transform {.inline.} =
initTransform(result, xAxis, yAxis, zAxis, origin)
proc initTransform*(basis: Basis, origin: Vector3): Transform {.inline.} =
initTransform(result, basis, origin)
proc basis*(self: Transform): Basis {.
importc: "godot_transform_get_basis", header: "godot_transform.h".}
proc `basis=`*(self: var Transform; v: Basis) {.
importc: "godot_transform_set_basis", header: "godot_transform.h".}
proc origin*(self: Transform): Vector3 {.
importc: "godot_transform_get_origin", header: "godot_transform.h".}
proc `origin=`*(self: var Transform; v: Vector3) {.
importc: "godot_transform_set_origin", header: "godot_transform.h".}
proc toGodotString*(self: Transform): GodotString {.
importc: "godot_transform_as_string", header: "godot_transform.h".}
proc `$`*(self: Transform): string {.inline.} =
$self.toGodotString()
proc inverse*(self: Transform): Transform {.
importc: "godot_transform_inverse", header: "godot_transform.h".}
proc affineInverse*(self: Transform): Transform {.
importc: "godot_transform_affine_inverse",
header: "godot_transform.h".}
proc orthonormalized*(self: Transform): Transform {.
importc: "godot_transform_orthonormalized",
header: "godot_transform.h".}
proc rotated*(self: Transform; axis: Vector3;
phi: float32): Transform {.
importc: "godot_transform_rotated", header: "godot_transform.h".}
proc scaled*(self: Transform; scale: Vector3): Transform {.
importc: "godot_transform_scaled", header: "godot_transform.h".}
proc translated*(self: Transform; offset: Vector3): Transform {.
importc: "godot_transform_translated", header: "godot_transform.h".}
proc lookingAt*(self: Transform;
target, up: Vector3): Transform {.
importc: "godot_transform_looking_at", header: "godot_transform.h".}
proc xformPlane*(self: Transform; v: Plane): Plane {.
importc: "godot_transform_xform_plane", header: "godot_transform.h".}
proc xformInvPlane*(self: Transform; v: Plane): Plane {.
importc: "godot_transform_xform_inv_plane", header: "godot_transform.h".}
proc xformVector3*(self: Transform; v: Vector3): Vector3 {.
importc: "godot_transform_xform_vector3", header: "godot_transform.h".}
proc xformInvVector3*(self: Transform; v: Vector3): Vector3 {.
importc: "godot_transform_xform_inv_vector3", header: "godot_transform.h".}
proc xformRect3*(self: Transform; v: Vector3): Rect3 {.
importc: "godot_transform_xform_rect3", header: "godot_transform.h".}
proc xformInvRect3*(self: Transform; v: Vector3): Vector3 {.
importc: "godot_transform_xform_inv_rect3", header: "godot_transform.h".}
proc `==`*(self: Transform; b: Transform): bool {.
importc: "godot_transform_operator_equal", header: "godot_transform.h".}
proc `*`*(a, b: Transform): Transform {.
importc: "godot_transform_operator_multiply", header: "godot_transform.h".}
proc `*=`*(a: var Transform, b: Transform) {.inline.} =
a = a * b

View file

@ -1,92 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
type
Transform2D* {.importc: "godot_transform2d", header: "godot_transform2d.h",
byref.} = object
import godotbase, strings, variant, vector2, rect2
proc initTransform2D(dest: var Transform2D) {.
importc: "godot_transform2d_new_identity", header: "godot_transform2d.h".}
proc initTransform2D(dest: var Transform2D; rot: float32; pos: Vector2) {.
importc: "godot_transform2d_new", header: "godot_transform2d.h".}
proc initTransform2D(dest: var Transform2D; xAxis, yAxis, origin: Vector2) {.
importc: "godot_transform2d_new_axis_origin",
header: "godot_transform2d.h".}
proc initTransform2D*(): Transform2D {.inline.} =
initTransform2D(result)
proc initTransform2D*(rot: float32; pos: Vector2): Transform2D {.inline.} =
initTransform2D(result, rot, pos)
proc initTransform2D*(xAxis, yAxis, origin: Vector2): Transform2D {.inline.} =
initTransform2D(result, xAxis, yAxis, origin)
proc toGodotString*(self: Transform2D): GodotString {.
importc: "godot_transform2d_as_string",
header: "godot_transform2d.h".}
proc `$`*(self: Transform2D): string {.inline.} =
$self.toGodotString()
proc inverse*(self: Transform2D): Transform2D {.
importc: "godot_transform2d_inverse", header: "godot_transform2d.h".}
proc affineInverse*(self: Transform2D): Transform2D {.
importc: "godot_transform2d_affine_inverse",
header: "godot_transform2d.h".}
proc rotation*(self: Transform2D): float32 {.
importc: "godot_transform2d_get_rotation",
header: "godot_transform2d.h".}
proc origin*(self: Transform2D): Vector2 {.
importc: "godot_transform2d_get_origin",
header: "godot_transform2d.h".}
proc scale*(self: Transform2D): Vector2 {.
importc: "godot_transform2d_get_scale",
header: "godot_transform2d.h".}
proc orthonormalized*(self: Transform2D): Transform2D {.
importc: "godot_transform2d_orthonormalized",
header: "godot_transform2d.h".}
proc rotated*(self: Transform2D; phi: float32): Transform2D {.
importc: "godot_transform2d_rotated",
header: "godot_transform2d.h".}
proc scaled*(self: Transform2D; scale: Vector2): Transform2D {.
importc: "godot_transform2d_scaled",
header: "godot_transform2d.h".}
proc translated*(self: Transform2D;
offset: Vector2): Transform2D {.
importc: "godot_transform2d_translated",
header: "godot_transform2d.h".}
proc xformVector2*(self: Transform2D; v: Vector2): Vector2 {.
importc: "godot_transform2d_xform_vector2",
header: "godot_transform2d.h".}
proc xformInvVector2*(self: Transform2D; v: Vector2): Vector2 {.
importc: "godot_transform2d_xform_inv_vector2",
header: "godot_transform2d.h".}
proc basisXformVector2*(self: Transform2D;
v: Vector2): Vector2 {.
importc: "godot_transform2d_basis_xform_vector2",
header: "godot_transform2d.h".}
proc basisXformInvVector2*(self: Transform2D;
v: Vector2): Vector2 {.
importc: "godot_transform2d_basis_xform_inv_vector2",
header: "godot_transform2d.h".}
proc xformRect2*(self: Transform2D; v: Rect2): Rect2 {.
importc: "godot_transform2d_xform_rect2", header: "godot_transform2d.h".}
proc xformInvRect2*(self: Transform2D; v: Rect2): Rect2 {.
importc: "godot_transform2d_xform_inv_rect2",
header: "godot_transform2d.h".}
proc interpolateWith*(self, m: Transform2D;
c: float32): Transform2D {.
importc: "godot_transform2d_interpolate_with",
header: "godot_transform2d.h".}
proc `==`*(a, b: Transform2D): bool {.
importc: "godot_transform2d_operator_equal",
header: "godot_transform2d.h".}
proc `*`*(a, b: Transform2D): Transform2D {.
importc: "godot_transform2d_operator_multiply",
header: "godot_transform2d.h".}
proc `*=`*(a: var Transform2D, b: Transform2D) {.inline.} =
a = a * b

View file

@ -1,298 +0,0 @@
import godotbase
import arrays, basis, dictionary, nodepath
import plane, poolarray, quat, rect2, rect3, rid
import strings, transform, transform2d, vector2
import vector3, color
type
VariantType* {.importc: "godot_variant_type", header: "godot_variant.h",
size: sizeof(cint), pure.} = enum
Nil, ## atomic types
Bool,
Int,
Real,
String,
# math types
Vector2, ## 5
Rect2,
Vector3,
Transform2D,
Plane,
Quat, ## 10
Rect3,
Basis,
Transform, ## misc types
Color,
NodePath, ## 15
RID,
Object,
Dictionary,
Array, ## 20
# arrays
PoolByteArray,
PoolIntArray,
PoolRealArray,
PoolStringArray,
PoolVector2Array, ## 25
PoolVector3Array,
PoolColorArray
VariantCallErrorType* {.importc: "godot_variant_call_error_error",
header: "godot_variant.h",
size: sizeof(cint),
pure.} = enum
OK,
InvalidMethod,
InvalidArgument,
TooManyArguments,
TooFewArguments,
InstanceIsNull
VariantCallError* {.importc: "godot_variant_call_error",
header: "godot_variant.h".} = object
error* {.importc: "error".}: VariantCallErrorType
argument* {.importc: "argument".}: cint
expected* {.importc: "expected".}: VariantType
proc getType*(p: Variant): VariantType {.
importc: "godot_variant_get_type", header: "godot_variant.h".}
proc initNilVariant(dest: var Variant) {.
importc: "godot_variant_new_nil", header: "godot_variant.h".}
proc initVariant(dest: var Variant; b: bool) {.
importc: "godot_variant_new_bool", header: "godot_variant.h".}
proc initVariant(dest: var Variant; i: uint64) {.
importc: "godot_variant_new_uint", header: "godot_variant.h".}
proc initVariant(dest: var Variant; i: int64) {.
importc: "godot_variant_new_int", header: "godot_variant.h".}
proc initVariant(dest: var Variant; r: cdouble) {.
importc: "godot_variant_new_real", header: "godot_variant.h".}
proc initVariant(dest: var Variant; s: GodotString) {.
importc: "godot_variant_new_string", header: "godot_variant.h".}
proc initVariant(dest: var Variant; v2: Vector2) {.
importc: "godot_variant_new_vector2", header: "godot_variant.h".}
proc initVariant(dest: var Variant; rect2: Rect2) {.
importc: "godot_variant_new_rect2", header: "godot_variant.h".}
proc initVariant(dest: var Variant; v3: Vector3) {.
importc: "godot_variant_new_vector3", header: "godot_variant.h".}
proc initVariant(dest: var Variant; t2d: Transform2D) {.
importc: "godot_variant_new_transform2d",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; plane: Plane) {.
importc: "godot_variant_new_plane", header: "godot_variant.h".}
proc initVariant(dest: var Variant; quat: Quat) {.
importc: "godot_variant_new_quat", header: "godot_variant.h".}
proc initVariant(dest: var Variant; rect3: Rect3) {.
importc: "godot_variant_new_rect3", header: "godot_variant.h".}
proc initVariant(dest: var Variant; basis: Basis) {.
importc: "godot_variant_new_basis", header: "godot_variant.h".}
proc initVariant(dest: var Variant;
trans: Transform) {.
importc: "godot_variant_new_transform",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; color: Color) {.
importc: "godot_variant_new_color", header: "godot_variant.h".}
proc initVariant(dest: var Variant; nodePath: NodePath) {.
importc: "godot_variant_new_node_path",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; rid: RID) {.
importc: "godot_variant_new_rid", header: "godot_variant.h".}
proc initVariant(dest: var Variant; obj: ptr GodotObject) {.
importc: "godot_variant_new_object", header: "godot_variant.h".}
proc initVariant(dest: var Variant; dict: Dictionary) {.
importc: "godot_variant_new_dictionary",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; arr: Array) {.
importc: "godot_variant_new_array", header: "godot_variant.h".}
proc initVariant(dest: var Variant; pba: PoolByteArray) {.
importc: "godot_variant_new_pool_byte_array",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; pia: PoolIntArray) {.
importc: "godot_variant_new_pool_int_array",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; pra: PoolRealArray) {.
importc: "godot_variant_new_pool_real_array",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; psa: PoolStringArray) {.
importc: "godot_variant_new_pool_string_array",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; pv2a: PoolVector2Array) {.
importc: "godot_variant_new_pool_vector2_array",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; pv3a: PoolVector3Array) {.
importc: "godot_variant_new_pool_vector3_array",
header: "godot_variant.h".}
proc initVariant(dest: var Variant; pca: PoolColorArray) {.
importc: "godot_variant_new_pool_color_array",
header: "godot_variant.h".}
proc variant*(): Variant {.inline.} =
initNilVariant(result)
proc variant*(b: bool): Variant {.inline.} =
initVariant(result, b)
proc variant*(i: uint64): Variant {.inline.} =
initVariant(result, i)
proc variant*(i: int64): Variant {.inline.} =
initVariant(result, i)
proc variant*(r: cdouble): Variant {.inline.} =
initVariant(result, r)
proc variant*(s: GodotString): Variant {.inline.} =
initVariant(result, s)
proc variant*(s: string): Variant {.inline.} =
initVariant(result, s.toGodotString())
proc variant*(v2: Vector2): Variant {.inline.} =
initVariant(result, v2)
proc variant*(rect2: Rect2): Variant {.inline.} =
initVariant(result, rect2)
proc variant*(v3: Vector3): Variant {.inline.} =
initVariant(result, v3)
proc variant*(t2d: Transform2D): Variant {.inline.} =
initVariant(result, t2d)
proc variant*(plane: Plane): Variant {.inline.} =
initVariant(result, plane)
proc variant*(quat: Quat): Variant {.inline.} =
initVariant(result, quat)
proc variant*(rect3: Rect3): Variant {.inline.} =
initVariant(result, rect3)
proc variant*(basis: Basis): Variant {.inline.} =
initVariant(result, basis)
proc variant*(trans: Transform): Variant {.inline.} =
initVariant(result, trans)
proc variant*(color: Color): Variant {.inline.} =
initVariant(result, color)
proc variant*(nodePath: NodePath): Variant {.inline.} =
initVariant(result, nodePath)
proc variant*(rid: RID): Variant {.inline.} =
initVariant(result, rid)
proc variant*(obj: ptr GodotObject): Variant {.inline.} =
initVariant(result, obj)
proc variant*(dict: Dictionary): Variant {.inline.} =
initVariant(result, dict)
proc variant*(arr: Array): Variant {.inline.} =
initVariant(result, arr)
proc variant*(pba: PoolByteArray): Variant {.inline.} =
initVariant(result, pba)
proc variant*(pia: PoolIntArray): Variant {.inline.} =
initVariant(result, pia)
proc variant*(pra: PoolRealArray): Variant {.inline.} =
initVariant(result, pra)
proc variant*(psa: PoolStringArray): Variant {.inline.} =
initVariant(result, psa)
proc variant*(pv2a: PoolVector2Array): Variant {.inline.} =
initVariant(result, pv2a)
proc variant*(pv3a: PoolVector3Array): Variant {.inline.} =
initVariant(result, pv3a)
proc variant*(pca: PoolColorArray): Variant {.inline.} =
initVariant(result, pca)
proc asBool*(self: Variant): bool {.
importc: "godot_variant_as_bool", header: "godot_variant.h".}
proc asUint*(self: Variant): uint64 {.
importc: "godot_variant_as_uint", header: "godot_variant.h".}
proc asInt*(self: Variant): int64 {.
importc: "godot_variant_as_int", header: "godot_variant.h".}
proc asReal*(self: Variant): cdouble {.
importc: "godot_variant_as_real", header: "godot_variant.h".}
proc asGodotString*(self: Variant): GodotString {.
importc: "godot_variant_as_string", header: "godot_variant.h".}
proc asString*(self: Variant): string =
let s = self.asGodotString()
result = $s
proc asVector2*(self: Variant): Vector2 {.
importc: "godot_variant_as_vector2", header: "godot_variant.h".}
proc asRect2*(self: Variant): Rect2 {.
importc: "godot_variant_as_rect2", header: "godot_variant.h".}
proc asVector3*(self: Variant): Vector3 {.
importc: "godot_variant_as_vector3", header: "godot_variant.h".}
proc asTransform2D*(self: Variant): Transform2D {.
importc: "godot_variant_as_transform2d", header: "godot_variant.h".}
proc asPlane*(self: Variant): Plane {.
importc: "godot_variant_as_plane", header: "godot_variant.h".}
proc asQuat*(self: Variant): Quat {.
importc: "godot_variant_as_quat", header: "godot_variant.h".}
proc asRect3*(self: Variant): Rect3 {.
importc: "godot_variant_as_rect3", header: "godot_variant.h".}
proc asBasis*(self: Variant): Basis {.
importc: "godot_variant_as_basis", header: "godot_variant.h".}
proc asTransform*(self: Variant): Transform {.
importc: "godot_variant_as_transform", header: "godot_variant.h".}
proc asColor*(self: Variant): Color {.
importc: "godot_variant_as_color", header: "godot_variant.h".}
proc asNodePath*(self: Variant): NodePath {.
importc: "godot_variant_as_node_path", header: "godot_variant.h".}
proc asRid*(self: Variant): RID {.
importc: "godot_variant_as_rid", header: "godot_variant.h".}
proc asObject*(self: Variant): ptr GodotObject {.
importc: "godot_variant_as_object", header: "godot_variant.h".}
proc asDictionary*(self: Variant): Dictionary {.
importc: "godot_variant_as_dictionary", header: "godot_variant.h".}
proc asArray*(self: Variant): Array {.
importc: "godot_variant_as_array", header: "godot_variant.h".}
proc asPoolByteArray*(self: Variant): PoolByteArray {.
importc: "godot_variant_as_pool_byte_array",
header: "godot_variant.h".}
proc asPoolIntArray*(self: Variant): PoolIntArray {.
importc: "godot_variant_as_pool_int_array",
header: "godot_variant.h".}
proc asPoolRealArray*(self: Variant): PoolRealArray {.
importc: "godot_variant_as_pool_real_array",
header: "godot_variant.h".}
proc asPoolStringArray*(self: Variant): PoolStringArray {.
importc: "godot_variant_as_pool_string_array",
header: "godot_variant.h".}
proc asPoolVector2Array*(self: Variant): PoolVector2Array {.
importc: "godot_variant_as_pool_vector2_array",
header: "godot_variant.h".}
proc asPoolVector3Array*(self: Variant): PoolVector3Array {.
importc: "godot_variant_as_pool_vector3_array",
header: "godot_variant.h".}
proc asPoolColorArray*(self: Variant): PoolColorArray {.
importc: "godot_variant_as_pool_color_array",
header: "godot_variant.h".}
proc call*(self: Variant; meth: GodotString;
args: var array[MAX_ARG_COUNT, Variant]; argCount: cint;
error: var VariantCallError): Variant {.
importc: "godot_variant_call", header: "godot_variant.h".}
proc hasMethod*(self: Variant; meth: GodotString): bool {.
importc: "godot_variant_has_method", header: "godot_variant.h".}
proc `==`*(self, other: Variant): bool {.
importc: "godot_variant_operator_equal", header: "godot_variant.h".}
proc `<`*(self, other: Variant): bool {.
importc: "godot_variant_operator_less", header: "godot_variant.h".}
proc hashCompare*(self, other: Variant): bool {.
importc: "godot_variant_hash_compare", header: "godot_variant.h".}
proc booleanize*(self: Variant; isValid: var bool): bool {.
importc: "godot_variant_booleanize", header: "godot_variant.h".}

View file

@ -1,117 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
type
Vector2* {.importc: "godot_vector2", header: "godot_vector2.h",
byref.} = object
import godotbase, strings
proc initVector2(dest: var Vector2; x, y: float32) {.
importc: "godot_vector2_new", header: "godot_vector2.h".}
proc vec2*(x, y: float32): Vector2 {.inline.} =
initVector2(result, x, y)
proc toGodotString*(self: Vector2): GodotString {.
importc: "godot_vector2_as_string", header: "godot_vector2.h".}
proc `$`*(self: Vector2): string {.inline.} =
$self.toGodotString()
proc normalized*(self: Vector2): Vector2 {.
importc: "godot_vector2_normalized", header: "godot_vector2.h".}
proc length*(self: Vector2): float32 {.
importc: "godot_vector2_length", header: "godot_vector2.h".}
proc angle*(self: Vector2): float32 {.
importc: "godot_vector2_angle", header: "godot_vector2.h".}
proc lengthSquared*(self: Vector2): float32 {.
importc: "godot_vector2_length_squared", header: "godot_vector2.h".}
proc isNormalized*(self: Vector2): bool {.
importc: "godot_vector2_is_normalized", header: "godot_vector2.h".}
proc distanceTo*(self, to: Vector2): float32 {.
importc: "godot_vector2_distance_to",
header: "godot_vector2.h".}
proc distanceSquaredTo*(self, to: Vector2): float32 {.
importc: "godot_vector2_distance_squared_to",
header: "godot_vector2.h".}
proc angleTo*(self, to: Vector2): float32 {.
importc: "godot_vector2_angle_to", header: "godot_vector2.h".}
proc angleToPoint*(self, to: Vector2): float32 {.
importc: "godot_vector2_angle_to_point",
header: "godot_vector2.h".}
proc lerp*(self, b: Vector2; t: float32): Vector2 {.
importc: "godot_vector2_linear_interpolate",
header: "godot_vector2.h".}
proc cubicInterpolate*(self, b, pre_a, post_b: Vector2; t: float32): Vector2 {.
importc: "godot_vector2_cubic_interpolate",
header: "godot_vector2.h".}
proc rotated*(self: Vector2; phi: float32): Vector2 {.
importc: "godot_vector2_rotated", header: "godot_vector2.h".}
proc tangent*(self: Vector2): Vector2 {.
importc: "godot_vector2_tangent", header: "godot_vector2.h".}
proc floor*(self: Vector2): Vector2 {.
importc: "godot_vector2_floor", header: "godot_vector2.h".}
proc snapped*(self: Vector2; by: Vector2): Vector2 {.
importc: "godot_vector2_snapped", header: "godot_vector2.h".}
proc aspect*(self: Vector2): float32 {.
importc: "godot_vector2_aspect", header: "godot_vector2.h".}
proc dot*(a, b: Vector2): float32 {.
importc: "godot_vector2_dot", header: "godot_vector2.h".}
proc slide*(self, n: Vector2): Vector2 {.
importc: "godot_vector2_slide", header: "godot_vector2.h".}
proc bounce*(self, n: Vector2): Vector2 {.
importc: "godot_vector2_bounce", header: "godot_vector2.h".}
proc reflect*(self, n: Vector2): Vector2 {.
importc: "godot_vector2_reflect", header: "godot_vector2.h".}
proc abs*(self: Vector2): Vector2 {.
importc: "godot_vector2_abs", header: "godot_vector2.h".}
proc clamped*(self: Vector2; length: float32): Vector2 {.
importc: "godot_vector2_clamped", header: "godot_vector2.h".}
proc `+`*(a, b: Vector2): Vector2 {.
importc: "godot_vector2_operator_add", header: "godot_vector2.h".}
proc `+=`*(a: var Vector2, b: Vector2) {.inline.} =
a += b
proc `-`*(a, b: Vector2): Vector2 {.
importc: "godot_vector2_operator_substract", header: "godot_vector2.h".}
proc `-=`*(a: var Vector2, b: Vector2) {.inline.} =
a = a - b
proc `*`*(a, b: Vector2): Vector2 {.
importc: "godot_vector2_operator_multiply_vector",
header: "godot_vector2.h".}
proc `*=`*(a: var Vector2, b: Vector2) {.inline.} =
a = a * b
proc `*`*(self: Vector2, scalar: float32): Vector2 {.
importc: "godot_vector2_operator_multiply_scalar",
header: "godot_vector2.h".}
proc `*=`*(self: var Vector2, scalar: float32) {.inline.} =
self = self * scalar
proc `/`*(a, b: Vector2): Vector2 {.
importc: "godot_vector2_operator_divide_vector", header: "godot_vector2.h".}
proc `/=`*(a: var Vector2, b: Vector2) {.inline.} =
a = a / b
proc `/`*(self: Vector2; scalar: float32): Vector2 {.
importc: "godot_vector2_operator_divide_scalar", header: "godot_vector2.h".}
proc `/=`*(self: var Vector2; scalar: float32) {.inline.} =
self = self / scalar
proc `==`*(a, b: Vector2): bool {.
importc: "godot_vector2_operator_equal", header: "godot_vector2.h".}
proc `<`*(a, b: Vector2): bool {.
importc: "godot_vector2_operator_less", header: "godot_vector2.h".}
proc `-`*(self: Vector2): Vector2 {.
importc: "godot_vector2_operator_neg", header: "godot_vector2.h".}
proc `x=`*(self: var Vector2; x: float32) {.
importc: "godot_vector2_set_x", header: "godot_vector2.h".}
proc `y=`*(self: var Vector2; y: float32) {.
importc: "godot_vector2_set_y", header: "godot_vector2.h".}
proc x*(self: Vector2): float32 {.
importc: "godot_vector2_get_x", header: "godot_vector2.h".}
proc y*(self: Vector2): float32 {.
importc: "godot_vector2_get_y", header: "godot_vector2.h".}

View file

@ -1,148 +0,0 @@
# Copyright (c) 2017 Xored Software, Inc.
type
Vector3* {.importc: "godot_vector3", header: "godot_vector3.h",
byref.} = object
import godotbase, basis, strings
type
Vector3Axis {.importc: "godot_vector3_axis", header: "godot_vector3.h",
size: sizeof(cint), pure.} = enum
X,
Y,
Z
proc initVector3*(dest: var Vector3; x, y, z: float32) {.
importc: "godot_vector3_new", header: "godot_vector3.h".}
proc vec3*(x, y, z: float32): Vector3 {.inline.} =
initVector3(result, x, y, z)
proc toGodotString*(self: Vector3): GodotString {.
importc: "godot_vector3_as_string", header: "godot_vector3.h".}
proc `$`*(self: Vector3): string {.inline.} =
$self.toGodotString()
proc minAxis*(self: Vector3): cint {.
importc: "godot_vector3_min_axis", header: "godot_vector3.h".}
proc maxAxis*(self: Vector3): cint {.
importc: "godot_vector3_max_axis", header: "godot_vector3.h".}
proc length*(self: Vector3): float32 {.
importc: "godot_vector3_length", header: "godot_vector3.h".}
proc lengthSquared*(self: Vector3): float32 {.
importc: "godot_vector3_length_squared", header: "godot_vector3.h".}
proc isNormalized*(self: Vector3): bool {.
importc: "godot_vector3_is_normalized", header: "godot_vector3.h".}
proc normalized*(self: Vector3): Vector3 {.
importc: "godot_vector3_normalized", header: "godot_vector3.h".}
proc inverse*(self: Vector3): Vector3 {.
importc: "godot_vector3_inverse", header: "godot_vector3.h".}
proc snapped*(self: Vector3; by: float32): Vector3 {.
importc: "godot_vector3_snapped", header: "godot_vector3.h".}
proc rotated*(self: Vector3; axis: Vector3;
phi: float32): Vector3 {.
importc: "godot_vector3_rotated", header: "godot_vector3.h".}
proc lerp*(self: Vector3; b: Vector3; t: float32): Vector3 {.
importc: "godot_vector3_linear_interpolate", header: "godot_vector3.h".}
proc cubicInterpolate*(self, b, preA, postB: Vector3;
t: float32): Vector3 {.
importc: "godot_vector3_cubic_interpolate", header: "godot_vector3.h".}
proc dot*(a, b: Vector3): float32 {.
importc: "godot_vector3_dot", header: "godot_vector3.h".}
proc cross*(a, b: Vector3): Vector3 {.
importc: "godot_vector3_cross", header: "godot_vector3.h".}
proc outer*(a, b: Vector3): Basis {.
importc: "godot_vector3_outer", header: "godot_vector3.h".}
proc toDiagonalMatrix*(self: Vector3): Basis {.
importc: "godot_vector3_to_diagonal_matrix", header: "godot_vector3.h".}
proc abs*(self: Vector3): Vector3 {.
importc: "godot_vector3_abs", header: "godot_vector3.h".}
proc floor*(self: Vector3): Vector3 {.
importc: "godot_vector3_floor", header: "godot_vector3.h".}
proc ceil*(self: Vector3): Vector3 {.
importc: "godot_vector3_ceil", header: "godot_vector3.h".}
proc distanceTo*(a, b: Vector3): float32 {.
importc: "godot_vector3_distance_to", header: "godot_vector3.h".}
proc distanceSquaredTo*(a, b: Vector3): float32 {.
importc: "godot_vector3_distance_squared_to", header: "godot_vector3.h".}
proc angleTo*(self, to: Vector3): float32 {.
importc: "godot_vector3_angle_to", header: "godot_vector3.h".}
proc slide*(self, n: Vector3): Vector3 {.
importc: "godot_vector3_slide", header: "godot_vector3.h".}
proc bounce*(self, n: Vector3): Vector3 {.
importc: "godot_vector3_bounce", header: "godot_vector3.h".}
proc reflect*(self, b: Vector3): Vector3 {.
importc: "godot_vector3_reflect", header: "godot_vector3.h".}
proc `+`*(a, b: Vector3): Vector3 {.
importc: "godot_vector3_operator_add", header: "godot_vector3.h".}
proc `+=`*(a: var Vector3, b: Vector3) {.inline.} =
a = a + b
proc `-`*(a, b: Vector3): Vector3 {.
importc: "godot_vector3_operator_substract", header: "godot_vector3.h".}
proc `-=`*(a: var Vector3, b: Vector3) {.inline.} =
a = a - b
proc `*`*(a, b: Vector3): Vector3 {.
importc: "godot_vector3_operator_multiply_vector",
header: "godot_vector3.h".}
proc `*=`*(a: var Vector3, b: Vector3) {.inline.}=
a = a * b
proc `*`*(self: Vector3; b: float32): Vector3 {.
importc: "godot_vector3_operator_multiply_scalar",
header: "godot_vector3.h".}
proc `*=`*(a: var Vector3; b: float32) {.inline.} =
a = a * b
proc `/`*(a, b: Vector3): Vector3 {.
importc: "godot_vector3_operator_divide_vector",
header: "godot_vector3.h".}
proc `/=`*(a: var Vector3; b: Vector3) {.inline.} =
a = a / b
proc `/`*(self: Vector3; b: float32): Vector3 {.
importc: "godot_vector3_operator_divide_scalar",
header: "godot_vector3.h".}
proc `/=`*(a: var Vector3; b: float32) {.inline.} =
a = a / b
proc `==`*(a, b: Vector3): bool {.
importc: "godot_vector3_operator_equal", header: "godot_vector3.h".}
proc `<`*(a, b: Vector3): bool {.
importc: "godot_vector3_operator_less", header: "godot_vector3.h".}
proc `-`*(self: Vector3): Vector3 {.
importc: "godot_vector3_operator_neg", header: "godot_vector3.h".}
proc setAxis(self: var Vector3; axis: Vector3Axis;
val: float32) {.
importc: "godot_vector3_set_axis", header: "godot_vector3.h".}
proc getAxis(self: Vector3; axis: Vector3Axis): float32 {.
importc: "godot_vector3_get_axis", header: "godot_vector3.h".}
proc `[]`(self: Vector3, idx: range[0..2]): float32 {.inline.} =
self.getAxis(Vector3Axis(idx))
proc `[]=`(self: var Vector3, idx: range[0..2],
val: float32): float32 {.inline.} =
self.setAxis(Vector3Axis(idx), val)
proc x*(self: Vector3): float32 {.inline.} =
self.getAxis(Vector3Axis.X)
proc `x=`*(self: var Vector3, val: float32) {.inline.} =
self.setAxis(Vector3Axis.X, val)
proc y*(self: Vector3): float32 {.inline.} =
self.getAxis(Vector3Axis.Y)
proc `y=`*(self: var Vector3, val: float32) {.inline.} =
self.setAxis(Vector3Axis.Y, val)
proc z*(self: Vector3): float32 {.inline.} =
self.getAxis(Vector3Axis.Z)
proc `z=`*(self: var Vector3, val: float32) {.inline.} =
self.setAxis(Vector3Axis.Z, val)

View file

@ -1,16 +0,0 @@
# Copyright 2017 Xored Software, Inc.
import core.godotbase, core.godotcore
import core / [strings, vector2, rect2, vector3, transform2d, plane, quat]
import core / [rect3, basis, transform, color, nodepath, rid]
import core / [dictionary, arrays, poolarray, variant]
import nim / [godotmacros, godotnim]
export godotbase, strings, vector2, rect2, vector3, transform2d, plane, quat,
rect3, basis, transform, color, nodepath, rid, dictionary, arrays,
poolarray, variant
export godotmacros, godotnim
# from godotcore
export print, printWarning, printError

View file

@ -1,472 +0,0 @@
# Copyright 2017 Xored Software, Inc.
import macros, tables, typetraits
import "../core/godotcore.nim"
import godotnim
type
VarDecl = ref object
name: NimNode
typ: NimNode
defaultValue: NimNode
isNoGodot: bool
hint: string
hintTip: string
usage: string
MethodDecl = ref object
name: string
args: seq[VarDecl]
isVirtual: bool
returnType: NimNode
nimNode: NimNode
isNoGodot: bool
ObjectDecl = ref object
name: string
parentName: string
fields: seq[VarDecl]
methods: seq[MethodDecl]
ParseError = object of Exception
template parseError(node: NimNode, msg: string) =
raise newException(ParseError, lineinfo(node) & ": " & msg)
proc extractNames(definition: NimNode):
tuple[name, parentName: string] =
if definition.kind == nnkIdent:
result.name = $(definition.ident)
else:
if not (definition.kind == nnkInfix and definition[0].ident == !"of"):
parseError(definition, "invalid type definition")
result.name = $(definition[1].ident)
case definition[2].kind:
of nnkIdent:
result.parentName = $definition[2].ident
else:
parseError(definition[2], "parent type expected")
proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit)
result.strVal = s
proc newCStringLit(s: string): NimNode {.compileTime.} =
newNimNode(nnkCallStrLit).add(ident("cstring"), newRStrLit(s))
iterator pragmas(node: NimNode):
tuple[key: NimIdent, value: string, index: int] =
assert node.kind in {nnkPragma, nnkEmpty}
for index in countdown(node.len - 1, 0):
if node[index].kind == nnkExprColonExpr:
let val = $(node[index][1])
yield (node[index][0].ident, val, index)
elif node[index].kind == nnkIdent:
yield (node[index].ident, nil, index)
proc hasPragma(statement: NimNode, pname: string): bool =
## Checks if the pragma is present in the `statement`
if not (RoutineNodes.contains(statement.kind) or
statement.kind == nnkPragmaExpr):
return false
var pragmas = if RoutineNodes.contains(statement.kind): statement.pragma()
else: statement[1]
let pnameIdent = !pname
for ident, val, i in pragmas(pragmas):
if ident == pnameIdent:
return true
proc removePragma(statement: NimNode, pname: string): bool =
## Removes the pragma from the node and returns whether pragma was removed
if not (RoutineNodes.contains(statement.kind) or
statement.kind == nnkPragmaExpr):
return false
var pragmas = if RoutineNodes.contains(statement.kind): statement.pragma()
else: statement[1]
let pnameIdent = !pname
for ident, val, i in pragmas(pragmas):
if ident == pnameIdent:
pragmas.del(i)
return true
proc removeStrPragma(statement: NimNode,
pname: string): string {.compileTime.} =
## Removes the pragma from the node and returns value of the pragma
## Works for routine nodes or nnkPragmaExpr
if not (RoutineNodes.contains(statement.kind) or
statement.kind == nnkPragmaExpr):
return nil
result = nil
var pragmas = if RoutineNodes.contains(statement.kind): statement.pragma()
else: statement[1]
let pnameIdent = !pname
for ident, val, i in pragmas(pragmas):
if ident == pnameIdent:
pragmas.del(i)
return (if val.isNil: "" else: val)
proc isExported(node: NimNode): bool {.compileTime.} =
if node.kind == nnkPragmaExpr:
result = isExported(node[0])
elif node.kind == nnkPostfix:
result = ($node[0] == "*")
proc identDefsToVarDecls(identDefs: NimNode): seq[VarDecl] =
assert(identDefs.kind == nnkIdentDefs)
result = newSeqOfCap[VarDecl](identDefs.len - 2)
for i in 0..<(identDefs.len - 2):
let nameNode = identDefs[i].copyNimTree()
let hint = removeStrPragma(nameNode, "hint")
let hintTip = removeStrPragma(nameNode, "tip")
let usage = removeStrPragma(nameNode, "usage")
let isGdExport = removePragma(nameNode, "gdExport")
if not nameNode.isExported() and isGdExport:
parseError(nameNode, "gdExport is not applicable for private fields")
let isNoGodot = not nameNode.isExported() or not isGdExport
result.add(VarDecl(
name: if nameNode.kind == nnkPragmaExpr: nameNode[0].basename()
else: nameNode.basename(),
typ: identDefs[identDefs.len - 2],
defaultValue: identDefs[identDefs.len - 1],
hint: hint,
hintTip: hintTip,
isNoGodot: isNoGodot,
usage: usage
))
proc parseMethod(meth: NimNode): MethodDecl =
assert(meth.kind in {nnkProcDef, nnkMethodDef})
let methName = meth[0]
let isGdExport = removePragma(meth, "gdExport")
if not methName.isExported() and isGdExport:
parseError(meth, "gdExport is not applicable for private procs/methods")
let isNoGodot = meth.kind != nnkMethodDef and (
not methName.isExported() or
not isGdExport
) or removePragma(meth, "noExport")
result = MethodDecl(
name: $meth[0].basename,
args: newSeq[VarDecl](),
returnType: meth[3][0],
isVirtual: meth.kind == nnkMethodDef,
isNoGodot: isNoGodot,
nimNode: meth
)
for i in 1..<meth[3].len:
var identDefs = meth[3][i]
result.args.add(identDefsToVarDecls(identDefs))
proc parseVarSection(decl: NimNode): seq[VarDecl] =
assert(decl.kind == nnkVarSection)
result = identDefsToVarDecls(decl[0])
proc parseType(definition, callSite: NimNode): ObjectDecl =
let body = callSite[^1]
result = ObjectDecl(
fields: newSeq[VarDecl](),
methods: newSeq[MethodDecl]()
)
(result.name, result.parentName) = extractNames(definition)
if result.parentName.isNil: result.parentName = "Object"
for statement in body:
case statement.kind:
of nnkVarSection:
let varSection = parseVarSection(statement)
result.fields.add(varSection)
of nnkProcDef, nnkMethodDef:
let meth = parseMethod(statement)
result.methods.add(meth)
of nnkCommentStmt:
discard
else:
parseError(statement, "field or method declaration expected")
macro invokeVarArgs(procIdent, objIdent;
minArgs, maxArgs: static[int], numArgsIdent,
argSeqIdent; argTypes: seq[NimNode],
hasReturnValue: static[bool]): typed =
## Produces statement in form:
##
## .. code-block:: nim
## case numArgs:
## of 0:
## meth(self)
## of 1:
## let (arg0, err) = godotToNim[ArgT](argSeq[0])
## if err != ConversionResult.OK:
## error(...)
## return
## meth(self, arg0)
## else:
## error(...)
template conv(procLit, argT, argSeq, idx, argIdent, errIdent) =
let (argIdent, errIdent) = godotToNim[argT](argSeq[idx])
if errIdent != ConversionResult.OK:
let errorKind = if errIdent == ConversionResult.TypeError: "a type error"
else: "a range error"
printError(
"Failed to invoke Nim procedure " & $procLit &
": " & errorKind & " has occurred when converting argument " & $idx &
" of Godot type " & $argSeq[idx].getType())
return
result = newNimNode(nnkCaseStmt)
result.add(numArgsIdent)
for i in minArgs..maxArgs:
let branch = newNimNode(nnkOfBranch).add(newIntLitNode(i))
let branchBody = newStmtList()
let invocation = newNimNode(nnkCall)
invocation.add(procIdent)
invocation.add(objIdent) # self
for idx in 0..<i:
let argIdent = genSym(nskLet, "arg")
let errIdent = genSym(nskLet, "err")
let argT = argTypes[idx]
branchBody.add(getAst(conv($procIdent, argT,
argSeqIdent, idx, argIdent, errIdent)))
invocation.add(argIdent)
if hasReturnValue:
branchBody.add(newNimNode(nnkAsgn).add(ident("result"),
newCall("toGodot", invocation)))
else:
branchBody.add(invocation)
branchBody.add(newNimNode(nnkAsgn).add(ident("result"),
newCall("variant")))
branch.add(branchBody)
result.add(branch)
template printInvokeErr(procName, minArgs, maxArgs, numArgs) =
printError(
"Failed to invoke Nim procedure " & procName &
": expected " & $minArgs & "-" & $maxArgs &
" arguments, but got " & $numArgs)
result.add(newNimNode(nnkElse).add(getAst(
printInvokeErr($procIdent.ident, minArgs, maxArgs, numArgsIdent))))
proc typeError(nimType: cstring, value: string, godotType: VariantType,
className: cstring, propertyName: cstring): string =
result = "Tried to assign incompatible value " & value & " (" & $godotType &
") to field \"" & $propertyName & "\" (" & $nimType & ") of " &
$className
proc rangeError(nimType: cstring, value: string, className: cstring,
propertyName: cstring): string =
result = "Tried to assign the out-of-range value " & value &
" to field \"" & $propertyName & "\" (" & $nimType & ") of " &
$className
proc nimDestroyFunc(obj: ptr GodotObject, methData: pointer,
userData: pointer) {.noconv.} =
let nimObj = cast[ref NimGodotObject](userData)
nimObj.removeGodotObject()
GC_unref(nimObj)
template registerGodotClass(classNameIdent, classNameLit,
baseNameLit, createFuncIdent) =
proc createFuncIdent(obj: ptr GodotObject,
methData: pointer): pointer {.noconv.} =
let nimObj = new(classNameIdent)
setGodotObject(nimObj, obj)
GC_ref(nimObj)
result = cast[pointer](nimObj)
let createFuncObj = GodotInstanceCreateFunc(
createFunc: createFuncIdent
)
let destroyFuncObj = GodotInstanceDestroyFunc(
destroyFunc: nimDestroyFunc
)
registerClass(classNameIdent, classNameLit, false)
godotScriptRegisterClass(classNameLit, baseNameLit,
createFuncObj, destroyFuncObj)
template registerGodotField(classNameLit, classNameIdent, propNameLit,
propNameIdent, propTypeLit, propTypeIdent,
setFuncIdent, getFuncIdent, hintTipLit,
hintIdent, usageIdent, hasDefaultValue,
defaultValueNode) =
proc setFuncIdent(obj: ptr GodotObject, methData: pointer,
nimPtr: pointer, val: Variant) {.noconv.} =
let (nimVal, err) = godotToNim[propTypeIdent](val)
case err:
of ConversionResult.OK:
cast[classNameIdent](nimPtr).propNameIdent = nimVal
of ConversionResult.TypeError:
let errStr = typeError(propTypeLit, $val, val.getType(),
classNameLit, propNameLit)
printError(errStr)
of ConversionResult.RangeError:
let errStr = rangeError(propTypeLit, $val,
classNameLit, propNameLit)
printError(errStr)
proc getFuncIdent(obj: ptr GodotObject, methData: pointer,
nimPtr: pointer): Variant {.noconv.} =
result = nimToGodot(cast[classNameIdent](nimPtr).propNameIdent)
let setFunc = GodotPropertySetFunc(
setFunc: setFuncIdent
)
let getFunc = GodotPropertyGetFunc(
getFunc: getFuncIdent
)
var attr = GodotPropertyAttributes(
typ: ord(godotVariantType(propTypeIdent)),
hintString: hintTipLit.toGodotString(),
hint: GodotPropertyHint.hintIdent,
usage: GodotPropertyUsageFlags.usageIdent
)
when hasDefaultValue:
attr.defaultValue = (defaultValueNode).toGodot()
godotScriptRegisterProperty(classNameLit, propNameLit,
attr, setFunc, getFunc)
static:
import strutils
proc toGodotStyle(s: string): string {.compileTime.} =
result = newStringOfCap(s.len + 10)
for c in s:
if c.isUpperAscii():
result.add('_')
result.add(c.toLowerAscii())
else:
result.add(c)
proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
result = newNimNode(nnkStmtList)
# 1. Nim type definition
let typeDef = newNimNode(nnkTypeDef)
result.add(newNimNode(nnkTypeSection).add(typeDef))
typeDef.add(postfix(ident(obj.name), "*"))
typeDef.add(newEmptyNode())
let objTy = newNimNode(nnkObjectTy)
typeDef.add(newNimNode(nnkRefTy).add(objTy))
objTy.add(newEmptyNode())
if obj.parentName.isNil:
objTy.add(newEmptyNode())
else:
objTy.add(newNimNode(nnkOfInherit).add(ident(obj.parentName)))
let recList = newNimNode(nnkRecList)
objTy.add(recList)
for decl in obj.fields:
if not decl.defaultValue.isNil and decl.defaultValue.kind != nnkEmpty:
parseError(decl.defaultValue,
"Default values are not supported for fields for now.")
recList.add(newIdentDefs(decl.name, decl.typ))
# 2. {.this: self.} for convenience
result.add(newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
ident("this"), ident("self")
)))
# 3. Nim proc defintions
var decls = newSeqOfCap[NimNode](obj.methods.len)
for meth in obj.methods:
let selfArg = newIdentDefs(ident("self"), ident(obj.name))
meth.nimNode.params.insert(1, selfArg)
let decl = meth.nimNode.copyNimTree()
decl.body = newEmptyNode()
decl.addPragma(ident("gcsafe"))
decl.addPragma(newNimNode(nnkExprColonExpr).add(ident("locks"),
newIntLitNode(0)))
decls.add(decl)
# add forward declarations first
for decl in decls:
result.add(decl)
for meth in obj.methods:
result.add(meth.nimNode)
# 4. Register Godot object
let parentName = if obj.parentName.isNil: newNilLit()
else: newStrLitNode(obj.parentName)
let classNameLit = newCStringLit(obj.name)
let classNameIdent = ident(obj.name)
result.add(getAst(
registerGodotClass(classNameIdent, classNameLit, parentName,
genSym(nskProc, "createFunc"))))
# 5. Register fields (properties)
for field in obj.fields:
if field.isNoGodot: continue
let hintTip = if field.hintTip.isNil: ""
else: field.hintTip
let hint = if field.hint.isNil: "None"
else: field.hint
let usage = if field.usage.isNil: "Default"
else: field.usage
let hasDefaultValue = not field.defaultValue.isNil and
field.defaultValue.kind != nnkEmpty
let hintIdent = ident(hint)
let usageIdent = ident(usage)
result.add(getAst(
registerGodotField(classNameLit, classNameIdent,
newCStringLit($field.name.basename()),
ident(field.name), newCStringLit($field.typ),
field.typ, genSym(nskProc, "setFunc"),
genSym(nskProc, "getFunc"),
newStrLitNode(hintTip), hintIdent, usageIdent,
ident($hasDefaultValue), field.defaultValue)))
# 6. Register methods
template registerGodotMethod(classNameLit, classNameIdent, methodNameIdent,
methodNameLit, minArgs, maxArgs,
argTypes, methFuncIdent, hasReturnValue) =
proc methFuncIdent(obj: ptr GodotObject, methodData: pointer,
userData: pointer, numArgs: cint,
args: var ptr array[MAX_ARG_COUNT, Variant]):
Variant {.noconv.} =
let self = cast[classNameIdent](userData)
when defined(release):
invokeVarArgs(methodNameIdent, self, minArgs, maxArgs, numArgs,
args, argTypes, hasReturnValue)
else:
try:
invokeVarArgs(methodNameIdent, self, minArgs, maxArgs, numArgs,
args, argTypes, hasReturnValue)
except:
let ex = getCurrentException()
printError("Unhandled Nim exception (" &
$ex.name & "): " &
ex.msg & "\n" & ex.getStackTrace())
let meth = GodotInstanceMethod(
meth: methFuncIdent
)
godotScriptRegisterMethod(classNameLit, methodNameLit,
GodotMethodAttributes(), meth)
for meth in obj.methods:
if meth.isNoGodot: continue
let maxArgs = meth.args.len
var minArgs = maxArgs
var argTypes = newSeq[NimNode]()
for idx, arg in meth.args:
if minArgs == maxArgs and not arg.defaultValue.isNil and
arg.defaultValue.kind != nnkEmpty:
minArgs = idx
argTypes.add(arg.typ)
let godotMethodName = if meth.isVirtual: "_" & toGodotStyle(meth.name)
else: toGodotStyle(meth.name)
let hasReturnValueBool = not (meth.returnType.isNil or
meth.returnType.kind == nnkEmpty or
$meth.returnType == "void")
let hasReturnValue = if hasReturnValueBool: ident("true")
else: ident("false")
result.add(getAst(
registerGodotMethod(classNameLit, classNameIdent, ident(meth.name),
newCStringLit(godotMethodName), minArgs, maxArgs,
argTypes, genSym(nskProc, "methFunc"),
hasReturnValue)))
macro gdobj*(definition: untyped, body: untyped): typed =
let typeDef = parseType(definition, callsite())
result = genType(typeDef)

View file

@ -1,515 +0,0 @@
# Copyright 2017 Xored Software, Inc.
import tables, typetraits, macros
import "../core/godotbase.nim", "../core/godotcore.nim"
import "../core/strings.nim", "../core/vector2.nim", "../core/rect2.nim",
"../core/vector3.nim", "../core/transform2d.nim",
"../core/plane.nim", "../core/quat.nim", "../core/rect3.nim",
"../core/basis.nim", "../core/transform.nim", "../core/color.nim",
"../core/nodepath.nim", "../core/rid.nim", "../core/dictionary.nim",
"../core/arrays.nim", "../core/poolarray.nim", "../core/variant.nim"
## Definition of NimGodotObject and converters for built-in types.
type
NimGodotObject* = ref object of RootObj
godotObject: ptr GodotObject
ConversionResult* {.pure.} = enum
OK,
TypeError,
## Type mismatch
RangeError
## Types match, but the value is out of range.
## Mainly used for numeric (ordinal) types.
SomeUnsignedInt = uint8 or uint16 or uint32 or uint64 or uint or cuint
SomeSignedInt = int8 or int16 or int32 or int64 or int or cint
SomeFloat = float32 or float64 or cfloat
SomeGodot = bool or Vector2 or Rect2 or Vector3 or
Transform2D or Plane or Quat or Rect3 or
Basis or Transform or Color or NodePath or
RID or GodotObject or Dictionary or Array or
PoolByteArray or PoolIntArray or PoolRealArray or
PoolStringArray or PoolVector2Array or PoolVector3Array or
PoolColorArray or GodotString
SomeGodotOrNum = SomeGodot or SomeSignedInt or SomeUnsignedInt or SomeFloat
CallError* = object of Exception
err*: VariantCallError
ObjectInfo = object
constructor: proc(): NimGodotObject {.gcsafe, nimcall.}
baseNativeClass: cstring
isNative: bool
var classRegistry {.threadvar.}: TableRef[cstring, ObjectInfo]
static:
import sets, strutils
var nativeClasses {.compileTime.} = initSet[string]()
proc godotFinalizer[T: NimGodotObject](obj: T) =
# hmm, not sure yet how to deal with references correctly
# when T is Reference:
# obj.godotObject.deinit()
discard
macro baseNativeType(T: typedesc): cstring =
var t = getType(getType(T)[1][1])
var baseT: string
while true:
let typeName = ($t[1][1]).split(':')[0]
if typeName in nativeClasses:
baseT = typeName
break
if typeName == "NimGodotObject":
break
t = getType(t[1][1])
if baseT.isNil:
result = newNilLit()
else:
let rStr = newNimNode(nnkRStrLit)
rStr.strVal = baseT
result = newNimNode(nnkCallStrLit).add(ident("cstring"), rStr)
template registerClass*(T: typedesc; godotClassName: cstring,
isNativeParam: bool) =
if classRegistry.isNil:
classRegistry = newTable[cstring, ObjectInfo]()
let constructor = proc(): NimGodotObject =
var t: T
new(t, godotFinalizer[T])
result = t
const base = baseNativeType(T)
classRegistry[godotClassName] = ObjectInfo(
constructor: constructor,
baseNativeClass: base,
isNative: isNativeParam
)
when isNativeParam:
static:
nativeClasses.incl(T.name)
proc newNimGodotObject[T: NimGodotObject](
godotObject: ptr GodotObject, godotClassName: cstring): T =
assert(not classRegistry.isNil)
assert(not godotObject.isNil)
let objInfo = classRegistry.getOrDefault(godotClassName)
if objInfo.constructor.isNil:
printError("Nim constructor not found for class " & $godotClassName)
else:
result = T(objInfo.constructor())
result.godotObject = godotObject
proc asNimGodotObject*[T: NimGodotObject](godotObject: ptr GodotObject): T =
if godotObject.isNil: return nil
let userDataPtr = godotObject.getUserData()
if not userDataPtr.isNil:
result = cast[T](userDataPtr)
if result.godotObject != godotObject:
# Could be data from other bindings
result = nil
if result.isNil:
result = newNimGodotObject[T](
godotObject, cstring(godotObject.getClassName()))
proc `as`*[T: NimGodotObject](obj: NimGodotObject, t: typedesc[T]): T =
## Converts the ``obj`` into the specified type.
## Returns ``nil`` if the conversion cannot be performed
## (the ``obj`` is not of the type ``T``)
if obj.isNil or not (obj of T):
when not defined(release):
if not obj.isNil:
printError("Failed to cast object to " &
t.name & "\n" & getStackTrace())
result = nil
else:
result = T(obj)
proc getSingletonGodot*(name: cstring): ptr GodotObject {.
importc: "godot_global_get_singleton", header: "../godot.h".}
proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit)
result.strVal = s
static:
import strutils
macro toGodotName(T: typedesc): cstring =
let nameStr: string = (($T.getType()[1][1].symbol).split(':')[0])
let godotName = case nameStr:
of "File", "Directory", "Thread", "Mutex", "Semaphore":
"_" & nameStr
else:
nameStr
result = newNimNode(nnkCallStrLit).add(
ident("cstring"), newRStrLit(godotName))
proc getSingleton*[T: NimGodotObject](): T =
const godotName = toGodotName(T)
let singleton = getSingletonGodot(godotName)
if singleton.isNil:
printError("Tried to get non-existing singleton of type " & $godotName)
else:
result = asNimGodotObject[T](singleton)
proc gdnew*[T: NimGodotObject](): T =
const godotName = toGodotName(T)
let obj = godotNew(godotName)
if obj.isNil:
printError("godot_new returned nil for type " & $godotName)
result = asNimGodotObject[T](obj)
# const godotName = toGodotName(T)
# let objInfo = classRegistry.getOrDefault(godotName)
# if objInfo.constructor.isNil:
# printError("gdnew invoked on unregistered class: " & $godotName)
# return
# let godotConstructor = getClassConstructor(
# if objInfo.isNative: godotName else: objInfo.baseNativeClass)
# printError("Base native class for " & T.name & ": " & $objInfo.baseNativeClass)
# when not defined(release):
# if godotConstructor.isNil:
# printError("Failed to obtain Godot constrcutor for type: " & $godotName)
# return
# let godotObject = godotConstructor()
# when not defined(release):
# if godotObject.isNil:
# printError("Godot constructor returned nil - must never happen")
# return
# new(result, godotFinalizer[T])
# result.setGodotObject(godotObject)
proc newCallError*(err: VariantCallError): ref CallError =
let msg = case err.error:
of VariantCallErrorType.OK,
VariantCallErrorType.InvalidMethod,
VariantCallErrorType.TooManyArguments,
VariantCallErrorType.TooFewArguments,
VariantCallErrorType.InstanceIsNull:
$err.error
of VariantCallErrorType.InvalidArgument:
"invalid argument at position " & $err.argument & ": expected " &
$err.expected
result = newException(CallError, msg)
result.err = err
proc newConversionError*(err: ConversionResult): ref ValueError =
let msg = case err:
of ConversionResult.TypeError:
"Failed to convert the return value into Nim type"
of ConversionResult.RangeError:
"The returned value was out of bounds"
of ConversionResult.OK:
"OK"
result = newException(ValueError, msg)
proc removeGodotObject*(nimObj: NimGodotObject) =
## Used from destructor
nimObj.godotObject = nil
proc setGodotObject*(nimObj: NimGodotObject, obj: ptr GodotObject) {.inline.} =
assert(not obj.isNil)
assert(nimObj.godotObject.isNil) # reassignment is not allowed
nimObj.godotObject = obj
proc godotObject*(nimObj: NimGodotObject): ptr GodotObject {.inline.} =
nimObj.godotObject
proc godotVariantType*(T: typedesc[NimGodotObject]): VariantType {.inline.} =
VariantType.Object
proc toGodot*(self: NimGodotObject): Variant {.inline.} =
variant(self.godotObject)
proc fromGodot*[T: NimGodotObject](self: var T,
val: Variant): ConversionResult =
if val.getType() == VariantType.Object:
let objPtr = val.asObject()
self = asNimGodotObject[T](objPtr)
if self.isNil:
result = ConversionResult.TypeError
elif val.getType() == VariantType.Nil:
self = nil
else:
result = ConversionResult.TypeError
proc godotVariantType*(T: typedesc[enum]): VariantType {.inline.} =
VariantType.Int
proc toGodot*[T: enum](self: T): Variant {.inline.} =
variant(ord(self))
proc fromGodot*[T: enum](self: var T, val: Variant): ConversionResult =
if val.getType() == VariantType.Int:
self = T(val.asInt())
else:
result = ConversionResult.TypeError
proc toGodot*(self: Variant): Variant {.inline.} =
result = self
proc fromGodot*(self: var Variant, val: Variant): ConversionResult {.inline.} =
self = val
proc godotVariantType*(T: typedesc[SomeGodotOrNum]): VariantType {.inline.} =
when T is SomeSignedInt or T is SomeUnsignedInt:
VariantType.Int
elif T is bool:
VariantType.Bool
elif T is SomeFloat:
VariantType.Real
elif T is string or T is GodotString:
VariantType.String
elif T is Vector2:
VariantType.Vector2
elif T is Rect2:
VariantType.Rect2
elif T is Vector3:
VariantType.Vector3
elif T is Transform2D:
VariantType.Transform2D
elif T is Plane:
VariantType.Plane
elif T is Quat:
VariantType.Quat
elif T is Rect3:
VariantType.Rect3
elif T is Basis:
VariantType.Basis
elif T is Transform:
VariantType.Transform
elif T is Color:
VariantType.Color
elif T is NodePath:
VariantType.NodePath
elif T is RID:
VariantType.RID
elif T is GodotObject:
VariantType.Object
elif T is Dictionary:
VariantType.Dictionary
elif T is Array:
VariantType.Array
elif T is PoolByteArray:
VariantType.PoolByteArray
elif T is PoolIntArray:
VariantType.PoolIntArray
elif T is PoolRealArray:
VariantType.PoolRealArray
elif T is PoolStringArray:
VariantType.PoolStringArray
elif T is PoolVector2Array:
VariantType.PoolVector2Array
elif T is PoolVector3Array:
VariantType.PoolVector3Array
elif T is PoolColorArray:
VariantType.PoolColorArray
else:
VariantType.Nil
proc toGodot*[T: SomeGodotOrNum](val: T): Variant {.inline.} =
result = variant(val)
proc fromGodot*[T: SomeSignedInt or SomeUnsignedInt](
self: var T, val: Variant): ConversionResult =
if val.getType() != VariantType.Int:
result = ConversionResult.TypeError
else:
var intVal: (when T is SomeSignedInt: int64
else: uint64)
intVal = when T is SomeSignedInt: val.asInt()
else: val.asUint()
if intVal > high(T) or intVal < low(T):
result = ConversionResult.RangeError
else:
self = T(intVal)
proc fromGodot*[T: SomeFloat](self: var T, val: Variant): ConversionResult =
if val.getType() == VariantType.Real:
self = val.asReal()
elif val.getType() == VariantType.Int:
self = T(val.asInt())
else:
result = ConversionResult.TypeError
proc fromGodot*[T: SomeGodot](self: var T, val: Variant): ConversionResult =
if godotVariantType(T) != val.getType():
return ConversionResult.TypeError
when self is bool:
self = val.asBool()
elif self is Vector2:
self = val.asVector2()
elif self is Rect2:
self = val.asRect2()
elif self is Vector3:
self = val.asVector3()
elif self is Transform2D:
self = val.asTransform2D()
elif self is Plane:
self = val.asPlane()
elif self is Quat:
self = val.asQuat()
elif self is Rect3:
self = val.asRect3()
elif self is Basis:
self = val.asBasis()
elif self is Transform:
self = val.asTransform()
elif self is Color:
self = val.asColor()
elif self is NodePath:
self = val.asNodePath()
elif self is RID:
self = val.asRID()
elif self is ptr GodotObject:
self = val.asObject()
elif self is Dictionary:
self = val.asDictionary()
elif self is Array:
self = val.asArray()
elif self is PoolByteArray:
self = val.asPoolByteArray()
elif self is PoolIntArray:
self = val.asPoolIntArray()
elif self is PoolRealArray:
self = val.asPoolRealArray()
elif self is PoolStringArray:
self = val.asPoolStringArray()
elif self is PoolVector2Array:
self = val.asPoolVector2Array()
elif self is PoolVector3Array:
self = val.asPoolVector3Array()
elif self is PoolColorArray:
self = val.asPoolColorArray()
elif self is GodotString:
self = val.asGodotString()
else:
# mustn't reach this
result = ConversionError.TypeError
proc godotVariantType*(T: typedesc[string]): VariantType {.inline.} =
VariantType.String
proc toGodot*(s: string): Variant {.inline.} =
variant(s.toGodotString())
proc fromGodot*(s: var string, val: Variant): ConversionResult =
if val.getType() != VariantType.String:
result = ConversionResult.TypeError
else:
s = $val.asGodotString()
proc godotVariantType*(T: typedesc[seq]): VariantType =
VariantType.Array
proc godotVariantType*(T: typedesc[array]): VariantType =
VariantType.Array
proc toGodot*[T](s: openarray[T]): Variant =
var arr: Array
initArray(arr)
mixin toGodot
for item in s:
arr.add(toGodot(item))
result = variant(arr)
proc fromGodot*[T](s: var seq[T], val: Variant): ConversionResult =
if val.getType() != VariantType.Array:
result = ConversionResult.TypeError
else:
let arr = val.asArray()
s = newSeq[T](arr.len)
for idx, item in arr:
mixin fromGodot
let convResult = fromGodot(s[idx], item)
if convResult != ConversionResult.OK:
s = nil
return convResult
proc fromGodot*[T: array](s: var T, val: Variant): ConversionResult =
if val.getType() != VariantType.Array:
result = ConversionResult.TypeError
else:
let arr = val.asArray()
if s.len != arr.len:
return ConversionResult.TypeError
for idx, item in arr:
mixin fromGodot
let convResult = fromGodot(s[idx], item)
if convResult != ConversionResult.OK:
return convResult
proc godotVariantType*(T: typedesc[Table|TableRef]): VariantType {.inline.} =
VariantType.Dictionary
proc toGodot*[T: Table or TableRef](t: T): Variant =
var dict: Dictionary
initDictionary(dict)
mixin toGodot
for k, v in t.pairs():
dict[toGodot(k)] = toGodot(v)
result = variant(dict)
proc fromGodot*[T: Table or TableRef](t: var T, val: Variant): ConversionResult =
if val.getType() != VariantType.Dictionary:
result = ConversionResult.TypeError
else:
let dict = val.asDictionary()
mixin fromGodot
when t is Table:
t = initTable[type(t.keys()), type(t.values())]()
else:
t = newTable[type(t.keys()), type(t.values())]()
for k, v in dict:
var nimKey: type(t.keys())
var nimVal: type(t.values())
let keyResult = fromGodot(nimKey, k)
if keyResult != ConversionResult.OK:
when t is ref:
t = nil
return keyResult
let valResult = fromGodot(nimVal, v)
if valResult != ConversionResult.OK:
when t is ref:
t = nil
return valResult
t[nimKey] = nimVal
proc godotToNim*[T](val: Variant): (T, ConversionResult) =
mixin fromGodot
result[1] = fromGodot(result[0], val)
proc nimToGodot*[T](val: T): Variant =
mixin toGodot
when compiles(toGodot(val)):
result = toGodot(val)
else:
printError("Failed to convert Nim value of type " & T.name &
" into Variant")
initNilVariant(result)
{.emit: """/*TYPESECTION*/
void NimMain(void);
N_NOINLINE(void, setStackBottom)(void* thestackbottom);
""".}
const stackIncreases = defined(emscripten)
proc godot_native_init() {.cdecl, exportc, dynlib.} =
let stackBottom = godotStackBottom()
{.emit: """
NimMain();
setStackBottom(`stackBottom`);
""".}
GC_fullCollect()
GC_disable()
proc godot_native_terminate() {.cdecl, exportc, dynlib.} =
discard

View file

@ -1,14 +0,0 @@
# Copyright 2017 Xored Software, Inc.
import asyncdispatch
import godot, node
gdobj NimRuntime of Node:
method process*(delta: float32) =
if asyncdispatch.hasPendingOperations():
poll(0)
GC_step(2000, false, 0)
when not defined(release):
onUnhandledException = proc(errorMsg: string) =
printError("Unhandled Nim exception: " & errorMsg)