Update after recent GDNative API changes
This commit is contained in:
parent
09326f5104
commit
d4ab8a5524
5 changed files with 62 additions and 40 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
version = "0.7.1"
|
version = "0.7.2"
|
||||||
author = "Xored Software, Inc."
|
author = "Xored Software, Inc."
|
||||||
description = "Godot Engine bindings"
|
description = "Godot Engine bindings"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
|
|
@ -1265,18 +1265,20 @@ type
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
|
|
||||||
# String API
|
# 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)
|
stringNew: proc (dest: var GodotString)
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringNewCopy: proc (dest: var GodotString, src: GodotString)
|
stringNewCopy: proc (dest: var GodotString, src: GodotString)
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringNewData: proc (dest: var GodotString, contents: cstring, size: cint)
|
stringNewWithWideString: pointer
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
|
||||||
stringNewUTF16Data: pointer
|
|
||||||
stringGetData: proc (self: GodotString, dest: cstring, size: var cint)
|
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
|
||||||
stringOperatorIndex: pointer
|
stringOperatorIndex: pointer
|
||||||
stringOperatorIndexConst: pointer
|
stringOperatorIndexConst: pointer
|
||||||
stringUTF16Str: pointer
|
stringWideStr: pointer
|
||||||
stringOperatorEqual: proc (self, other: GodotString): bool
|
stringOperatorEqual: proc (self, other: GodotString): bool
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringOperatorLess: proc (self, other: GodotString): bool
|
stringOperatorLess: proc (self, other: GodotString): bool
|
||||||
|
|
@ -1285,6 +1287,9 @@ type
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringLength: proc (self: GodotString): cint
|
stringLength: proc (self: GodotString): cint
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
|
stringCasecmpTo: pointer
|
||||||
|
stringNocasecmpTo: pointer
|
||||||
|
stringNaturalnocasecmpTo: pointer
|
||||||
stringBeginsWith: pointer
|
stringBeginsWith: pointer
|
||||||
stringBeginsWithCharArray: pointer
|
stringBeginsWithCharArray: pointer
|
||||||
stringBigrams: pointer
|
stringBigrams: pointer
|
||||||
|
|
@ -1376,11 +1381,14 @@ type
|
||||||
stringErase: pointer
|
stringErase: pointer
|
||||||
stringAscii: pointer
|
stringAscii: pointer
|
||||||
stringAsciiExtended: pointer
|
stringAsciiExtended: pointer
|
||||||
stringUtf8: pointer
|
stringUtf8: proc (self: GodotString): GodotCharString
|
||||||
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringParseUtf8: pointer
|
stringParseUtf8: pointer
|
||||||
stringParseUtf8WithLen: pointer
|
stringParseUtf8WithLen: pointer
|
||||||
stringCharsToUtf8: pointer
|
stringCharsToUtf8: proc (str: cstring): GodotString
|
||||||
stringCharsToUtf8WithLen: pointer
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
|
stringCharsToUtf8WithLen: proc (str: cstring, len: cint): GodotString
|
||||||
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringHash: pointer
|
stringHash: pointer
|
||||||
stringHash64: pointer
|
stringHash64: pointer
|
||||||
stringHashChars: pointer
|
stringHashChars: pointer
|
||||||
|
|
@ -2541,14 +2549,16 @@ type
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
|
|
||||||
# String API
|
# 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)
|
stringNew*: proc (dest: var GodotString)
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringNewCopy*: proc (dest: var GodotString, src: GodotString)
|
stringNewCopy*: proc (dest: var GodotString, src: GodotString)
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.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
|
stringOperatorEqual*: proc (self, other: GodotString): bool
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringOperatorLess*: proc (self, other: GodotString): bool
|
stringOperatorLess*: proc (self, other: GodotString): bool
|
||||||
|
|
@ -2559,6 +2569,12 @@ type
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
||||||
stringDestroy*: proc (self: var GodotString)
|
stringDestroy*: proc (self: var GodotString)
|
||||||
{.noconv, raises: [], gcsafe, tags: [], locks: 0.}
|
{.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
|
# Misc API
|
||||||
objectDestroy*: proc (self: ptr GodotObject)
|
objectDestroy*: proc (self: ptr GodotObject)
|
||||||
|
|
@ -3120,15 +3136,20 @@ proc setGDNativeAPI*(apiStruct: pointer, initOptions: ptr GDNativeInitOptions) =
|
||||||
variantDestroy
|
variantDestroy
|
||||||
|
|
||||||
# String API
|
# String API
|
||||||
|
charStringLength
|
||||||
|
charStringGetData
|
||||||
|
charStringDestroy
|
||||||
|
|
||||||
stringNew
|
stringNew
|
||||||
stringNewCopy
|
stringNewCopy
|
||||||
stringNewData
|
|
||||||
stringGetData
|
|
||||||
stringOperatorEqual
|
stringOperatorEqual
|
||||||
stringOperatorLess
|
stringOperatorLess
|
||||||
stringOperatorPlus
|
stringOperatorPlus
|
||||||
stringLength
|
stringLength
|
||||||
stringDestroy
|
stringDestroy
|
||||||
|
stringUtf8
|
||||||
|
stringCharsToUtf8
|
||||||
|
stringCharsToUtf8WithLen
|
||||||
|
|
||||||
# Misc API
|
# Misc API
|
||||||
objectDestroy
|
objectDestroy
|
||||||
|
|
|
||||||
|
|
@ -697,10 +697,14 @@ proc makeMethod(types: Table[string, GodotType], tree: PNode,
|
||||||
toNimType(types, methodObj["return_type"].str)
|
toNimType(types, methodObj["return_type"].str)
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
for prop in typ.jsonNode["properties"]:
|
if not typ.isSingleton:
|
||||||
if prop["getter"].str == methodObj["name"].str or
|
# for singletons we don't generate Nim setters/getters,
|
||||||
prop["setter"].str == methodObj["name"].str:
|
# but use plain procedures instead. That's because setter syntax is
|
||||||
return
|
# 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 args = newSeqOfCap[MethodArg](methodObj["arguments"].len + 1)
|
||||||
var origArgs = methodObj["arguments"]
|
var origArgs = methodObj["arguments"]
|
||||||
|
|
@ -924,16 +928,18 @@ proc genApi*(targetDir: string, apiJsonFile: string) =
|
||||||
|
|
||||||
# first, generate declarations only for ease of
|
# first, generate declarations only for ease of
|
||||||
# human readability of the file
|
# human readability of the file
|
||||||
for property in obj["properties"]:
|
if not typ.isSingleton:
|
||||||
makeProperty(types, tree, methodBindRegsitry, typ, property,
|
for property in obj["properties"]:
|
||||||
withImplementation = false)
|
makeProperty(types, tree, methodBindRegsitry, typ, property,
|
||||||
|
withImplementation = false)
|
||||||
for meth in obj["methods"]:
|
for meth in obj["methods"]:
|
||||||
makeMethod(types, tree, methodBindRegsitry, typ,
|
makeMethod(types, tree, methodBindRegsitry, typ,
|
||||||
meth, withImplementation = false)
|
meth, withImplementation = false)
|
||||||
|
|
||||||
for property in obj["properties"]:
|
if not typ.isSingleton:
|
||||||
makeProperty(types, tree, methodBindRegsitry, typ,
|
for property in obj["properties"]:
|
||||||
property, withImplementation = true)
|
makeProperty(types, tree, methodBindRegsitry, typ,
|
||||||
|
property, withImplementation = true)
|
||||||
for meth in obj["methods"]:
|
for meth in obj["methods"]:
|
||||||
makeMethod(types, tree, methodBindRegsitry, typ, meth,
|
makeMethod(types, tree, methodBindRegsitry, typ, meth,
|
||||||
withImplementation = true)
|
withImplementation = true)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ type
|
||||||
GodotString* {.byref.} = object
|
GodotString* {.byref.} = object
|
||||||
data: array[sizeof(int), byte]
|
data: array[sizeof(int), byte]
|
||||||
|
|
||||||
|
GodotCharString* {.byref.} = object
|
||||||
|
data: array[sizeof(int), byte]
|
||||||
|
|
||||||
VariantType* {.size: sizeof(cint), pure.} = enum
|
VariantType* {.size: sizeof(cint), pure.} = enum
|
||||||
Nil, ## atomic types
|
Nil, ## atomic types
|
||||||
Bool,
|
Bool,
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,7 @@ proc initGodotString(dest: var GodotString) {.inline, raises: [].} =
|
||||||
proc initGodotString(dest: var GodotString; contents: cstring;
|
proc initGodotString(dest: var GodotString; contents: cstring;
|
||||||
size: cint) {.inline.} =
|
size: cint) {.inline.} =
|
||||||
## Initializes ``dest`` from UTF-8 ``contents``
|
## Initializes ``dest`` from UTF-8 ``contents``
|
||||||
getGDNativeAPI().stringNewData(dest, contents, size)
|
dest = getGDNativeAPI().stringCharsToUtf8WithLen(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)
|
|
||||||
|
|
||||||
proc `==`*(self, b: GodotString): bool {.inline.} =
|
proc `==`*(self, b: GodotString): bool {.inline.} =
|
||||||
getGDNativeAPI().stringOperatorEqual(self, b)
|
getGDNativeAPI().stringOperatorEqual(self, b)
|
||||||
|
|
@ -33,10 +24,11 @@ proc deinit*(self: var GodotString) {.inline.} =
|
||||||
|
|
||||||
proc `$`*(self: GodotString): string =
|
proc `$`*(self: GodotString): string =
|
||||||
## Converts the ``GodotString`` into Nim string
|
## Converts the ``GodotString`` into Nim string
|
||||||
var length = self.len
|
var charStr = getGDNativeAPI().stringUtf8(self)
|
||||||
result = newStringOfCap(length)
|
let length = getGDNativeAPI().charStringLength(charStr)
|
||||||
getData(self, addr result[0], length)
|
result = newString(length)
|
||||||
result.setLen(length)
|
copyMem(addr result[0], getGDNativeAPI().charStringGetData(charStr), length)
|
||||||
|
getGDNativeAPI().charStringDestroy(charStr)
|
||||||
assert(result[length] == '\0')
|
assert(result[length] == '\0')
|
||||||
|
|
||||||
proc toGodotString*(s: string): GodotString {.inline.} =
|
proc toGodotString*(s: string): GodotString {.inline.} =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue