Update after recent GDNative API changes

This commit is contained in:
Ruslan Mustakov 2018-01-12 23:22:50 +07:00
commit d4ab8a5524
5 changed files with 62 additions and 40 deletions

View file

@ -1,4 +1,4 @@
version = "0.7.1"
version = "0.7.2"
author = "Xored Software, Inc."
description = "Godot Engine bindings"
license = "MIT"

View file

@ -1265,18 +1265,20 @@ type
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
# String API
charStringLength: proc (self: GodotCharString): cint
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
charStringGetData: proc (self: GodotCharString): cstring
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
charStringDestroy: proc (self: var GodotCharString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNew: proc (dest: var GodotString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNewCopy: proc (dest: var GodotString, src: GodotString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNewData: proc (dest: var GodotString, contents: cstring, size: cint)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNewUTF16Data: pointer
stringGetData: proc (self: GodotString, dest: cstring, size: var cint)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNewWithWideString: pointer
stringOperatorIndex: pointer
stringOperatorIndexConst: pointer
stringUTF16Str: pointer
stringWideStr: pointer
stringOperatorEqual: proc (self, other: GodotString): bool
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringOperatorLess: proc (self, other: GodotString): bool
@ -1285,6 +1287,9 @@ type
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringLength: proc (self: GodotString): cint
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringCasecmpTo: pointer
stringNocasecmpTo: pointer
stringNaturalnocasecmpTo: pointer
stringBeginsWith: pointer
stringBeginsWithCharArray: pointer
stringBigrams: pointer
@ -1376,11 +1381,14 @@ type
stringErase: pointer
stringAscii: pointer
stringAsciiExtended: pointer
stringUtf8: pointer
stringUtf8: proc (self: GodotString): GodotCharString
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringParseUtf8: pointer
stringParseUtf8WithLen: pointer
stringCharsToUtf8: pointer
stringCharsToUtf8WithLen: pointer
stringCharsToUtf8: proc (str: cstring): GodotString
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringCharsToUtf8WithLen: proc (str: cstring, len: cint): GodotString
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringHash: pointer
stringHash64: pointer
stringHashChars: pointer
@ -2541,14 +2549,16 @@ type
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
# String API
charStringLength*: proc (self: GodotCharString): cint
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
charStringGetData*: proc (self: GodotCharString): cstring
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
charStringDestroy*: proc (self: var GodotCharString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNew*: proc (dest: var GodotString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNewCopy*: proc (dest: var GodotString, src: GodotString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringNewData*: proc (dest: var GodotString, contents: cstring, size: cint)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringGetData*: proc (self: GodotString, dest: cstring, size: var cint)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringOperatorEqual*: proc (self, other: GodotString): bool
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringOperatorLess*: proc (self, other: GodotString): bool
@ -2559,6 +2569,12 @@ type
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringDestroy*: proc (self: var GodotString)
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringUtf8*: proc (self: GodotString): GodotCharString
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringCharsToUtf8*: proc (str: cstring): GodotString
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
stringCharsToUtf8WithLen*: proc (str: cstring, len: cint): GodotString
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
# Misc API
objectDestroy*: proc (self: ptr GodotObject)
@ -3120,15 +3136,20 @@ proc setGDNativeAPI*(apiStruct: pointer, initOptions: ptr GDNativeInitOptions) =
variantDestroy
# String API
charStringLength
charStringGetData
charStringDestroy
stringNew
stringNewCopy
stringNewData
stringGetData
stringOperatorEqual
stringOperatorLess
stringOperatorPlus
stringLength
stringDestroy
stringUtf8
stringCharsToUtf8
stringCharsToUtf8WithLen
# Misc API
objectDestroy

View file

@ -697,10 +697,14 @@ proc makeMethod(types: Table[string, GodotType], tree: PNode,
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
if not typ.isSingleton:
# for singletons we don't generate Nim setters/getters,
# but use plain procedures instead. That's because setter syntax is
# supposed to be used on an object (have at least 2 params).
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"]
@ -924,16 +928,18 @@ proc genApi*(targetDir: string, apiJsonFile: string) =
# 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)
if not typ.isSingleton:
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)
if not typ.isSingleton:
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)

View file

@ -32,6 +32,9 @@ type
GodotString* {.byref.} = object
data: array[sizeof(int), byte]
GodotCharString* {.byref.} = object
data: array[sizeof(int), byte]
VariantType* {.size: sizeof(cint), pure.} = enum
Nil, ## atomic types
Bool,

View file

@ -8,16 +8,7 @@ proc initGodotString(dest: var GodotString) {.inline, raises: [].} =
proc initGodotString(dest: var GodotString; contents: cstring;
size: cint) {.inline.} =
## Initializes ``dest`` from UTF-8 ``contents``
getGDNativeAPI().stringNewData(dest, contents, size)
proc getData(self: GodotString; dest: cstring;
size: var cint) {.inline.} =
## Converts ``self`` into UTF-8 encoding, putting the result into ``dest``.
getGDNativeAPI().stringGetData(self, dest, size)
proc len*(self: GodotString): cint {.inline.} =
## Returns the length of string in bytes if it is represented as UTF-8.
getData(self, nil, result)
dest = getGDNativeAPI().stringCharsToUtf8WithLen(contents, size)
proc `==`*(self, b: GodotString): bool {.inline.} =
getGDNativeAPI().stringOperatorEqual(self, b)
@ -33,10 +24,11 @@ proc deinit*(self: var GodotString) {.inline.} =
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)
var charStr = getGDNativeAPI().stringUtf8(self)
let length = getGDNativeAPI().charStringLength(charStr)
result = newString(length)
copyMem(addr result[0], getGDNativeAPI().charStringGetData(charStr), length)
getGDNativeAPI().charStringDestroy(charStr)
assert(result[length] == '\0')
proc toGodotString*(s: string): GodotString {.inline.} =