Use GDNative API struct

This commit is contained in:
Ruslan Mustakov 2017-10-04 23:41:15 +07:00
commit b62db02d8f
32 changed files with 2846 additions and 1535 deletions

View file

@ -349,11 +349,11 @@ template registerGodotClass(classNameIdent, classNameLit; isRefClass: bool;
)
registerClass(classNameIdent, classNameLit, false)
when isTool:
godotScriptRegisterToolClass(getNativeLibHandle(), classNameLit, baseNameLit,
createFuncObj, destroyFuncObj)
nativeScriptRegisterToolClass(getNativeLibHandle(), classNameLit,
baseNameLit, createFuncObj, destroyFuncObj)
else:
godotScriptRegisterClass(getNativeLibHandle(), classNameLit, baseNameLit,
createFuncObj, destroyFuncObj)
nativeScriptRegisterClass(getNativeLibHandle(), classNameLit,
baseNameLit, createFuncObj, destroyFuncObj)
template registerGodotField(classNameLit, classNameIdent, propNameLit,
propNameIdent, propTypeLit, propTypeIdent,
@ -415,8 +415,8 @@ template registerGodotField(classNameLit, classNameIdent, propNameLit,
{.push warning[ProveInit]: on.}
when hasDefaultValue:
attr.defaultValue = (defaultValueNode).toVariant().godotVariant[]
godotScriptRegisterProperty(getNativeLibHandle(), classNameLit, propNameLit,
unsafeAddr attr, setFunc, getFunc)
nativeScriptRegisterProperty(getNativeLibHandle(), classNameLit, propNameLit,
unsafeAddr attr, setFunc, getFunc)
hintStrGodot.deinit()
static:
@ -568,8 +568,8 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
let meth = GodotInstanceMethod(
meth: methFuncIdent
)
godotScriptRegisterMethod(getNativeLibHandle(), classNameLit, methodNameLit,
GodotMethodAttributes(), meth)
nativeScriptRegisterMethod(getNativeLibHandle(), classNameLit,
methodNameLit, GodotMethodAttributes(), meth)
for meth in obj.methods:
if meth.isNoGodot: continue
@ -605,12 +605,12 @@ proc genType(obj: ObjectDecl): NimNode {.compileTime.} =
let refDec = GodotInstanceMethod(
meth: refcountDecremented
)
godotScriptRegisterMethod(getNativeLibHandle(), classNameLit,
cstring"_refcount_incremented",
GodotMethodAttributes(), refInc)
godotScriptRegisterMethod(getNativeLibHandle(), classNameLit,
cstring"_refcount_decremented",
GodotMethodAttributes(), refDec)
nativeScriptRegisterMethod(getNativeLibHandle(), classNameLit,
cstring"_refcount_incremented",
GodotMethodAttributes(), refInc)
nativeScriptRegisterMethod(getNativeLibHandle(), classNameLit,
cstring"_refcount_decremented",
GodotMethodAttributes(), refDec)
result.add(getAst(registerRefIncDec(classNameLit)))
{.push warning[Deprecated]: off.}

View file

@ -1,7 +1,8 @@
# Copyright 2017 Xored Software, Inc.
import tables, typetraits, macros, asyncdispatch
import core.godotbase
import gdnativeapi
import core.godotcoretypes
import core.vector2, core.rect2,
core.vector3, core.transform2d,
core.planes, core.quats, core.rect3,
@ -94,12 +95,12 @@ proc isFinalized*(obj: NimGodotObject): bool {.inline.} =
template printWarning*(warning: typed) =
## Prints ``warning`` to Godot log, adding filename and line information.
let (filename, line) = instantiationInfo()
godotPrintWarning(cstring($warning), nil, cstring(filename), line.cint)
godotPrintWarning(cstring($warning), cstring"", cstring(filename), line.cint)
template printError*(error: typed) =
## Prints ``error`` to Godot log, adding filename and line information.
let (filename, line) = instantiationInfo()
godotPrintError(cstring($error), nil, cstring(filename), line.cint)
godotPrintError(cstring($error), cstring"", cstring(filename), line.cint)
proc print*(parts: varargs[string, `$`]) =
## Prints concatenated ``parts`` to Godot log.
@ -292,8 +293,6 @@ proc `of`*[T: NimGodotObject](obj: NimGodotObject,
## Godot-specific inheritance check.
not obj.isNil and (system.`of`(obj, T) or system.`of`(obj.linkedObject, T))
{.deprecated: [`~`: `of`].}
proc newRStrLit(s: string): NimNode {.compileTime.} =
result = newNimNode(nnkRStrLit)
result.strVal = s
@ -805,6 +804,7 @@ proc godot_nativescript_init(handle: pointer) {.
proc godot_gdnative_init(options: ptr GodotNativeInitOptions) {.
cdecl, exportc, dynlib.} =
gdNativeLibraryObj = options.gdNativeLibrary
setGDNativeAPI(options.gdNativeAPIStruct)
proc godot_gdnative_terminate(options: ptr GodotNativeTerminateOptions) {.
cdecl, exportc, dynlib.} =