Migrate to NativeScript+GDNative

This commit is contained in:
Ruslan Mustakov 2017-07-25 12:37:05 +07:00
commit b41a37681f
22 changed files with 608 additions and 611 deletions

View file

@ -13,36 +13,37 @@ export godotbase, strings, vector2, rect2, vector3, transform2d, plane, quat,
type
GodotMethodBind* {.importc: "godot_method_bind",
header: "../godot.h".} = object
header: "godot/gdnative.h".} = object
proc getMethod*(className: cstring; methodName: cstring): ptr GodotMethodBind {.
importc: "godot_method_bind_get_method", header: "../godot.h".}
importc: "godot_method_bind_get_method", header: "godot/gdnative.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".}
importc: "godot_method_bind_ptrcall", header: "godot/gdnative.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".}
importc: "godot_method_bind_call", header: "godot/gdnative.h".}
# Script API
type
GodotNativeInitOptions* {.importc: "godot_native_init_options",
header: "../godot.h".} = object
GodotNativeInitOptions* {.importc: "godot_gdnative_init_options",
header: "godot/gdnative.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
GodotNativeTerminateOptions* {.importc: "godot_gdnative_terminate_options",
header: "godot/gdnative.h".} = object
inEditor* {.importc: "in_editor".}: bool
GodotMethodRPCMode* {.importc: "godot_method_rpc_mode", header: "../godot.h",
GodotMethodRPCMode* {.importc: "godot_method_rpc_mode",
header: "godot_nativescript.h",
size: sizeof(cint), pure.} = enum
Disabled,
Remote,
@ -51,10 +52,11 @@ type
Slave
GodotMethodAttributes* {.importc: "godot_method_attributes",
header: "../godot.h".} = object
header: "godot_nativescript.h".} = object
rpcMode* {.importc: "rpc_type".}: GodotMethodRPCMode
GodotPropertyHint* {.importc: "godot_property_hint", header: "../godot.h",
GodotPropertyHint* {.importc: "godot_property_hint",
header: "godot_nativescript.h",
size: sizeof(cint), pure.} = enum
None, ## no hint provided.
Range, ## hint_text = "min,max,step,slider; // slider is optional"
@ -125,7 +127,7 @@ const
type
GodotPropertyUsageFlags* {.importc: "godot_property_usage_flags",
header: "../godot.h", size: sizeof(cint),
header: "godot_nativescript.h", size: sizeof(cint),
pure.} = enum
Storage = GODOT_PROPERTY_USAGE_STORAGE_VALUE
Editor = GODOT_PROPERTY_USAGE_EDITOR_VALUE
@ -155,7 +157,7 @@ type
UpdateAllIfModified = GODOT_PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED_VALUE
GodotPropertyAttributes* {.importc: "godot_property_attributes",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.h", bycopy.} = object
rsetType* {.importc: "rset_type".}: GodotMethodRPCMode
typ* {.importc: "type".}: cint
hint* {.importc: "hint".}: GodotPropertyHint
@ -164,7 +166,7 @@ type
defaultValue* {.importc: "default_value".}: Variant
GodotInstanceCreateFunc* {.importc: "godot_instance_create_func",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.h", bycopy.} = object
createFunc* {.importc: "create_func".}:
proc (obj: ptr GodotObject; methodData: pointer): pointer {.noconv.}
## returns user data
@ -172,24 +174,26 @@ type
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
GodotInstanceDestroyFunc* {.importc: "godot_instance_destroy_func",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.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;
proc godotScriptRegisterClass*(libHandle: pointer; name, base: cstring;
create_func: GodotInstanceCreateFunc;
destroy_func: GodotInstanceDestroyFunc) {.
importc: "godot_script_register_class", header: "../godot.h".}
proc godotScriptRegisterToolClass*(name, base: cstring;
importc: "godot_nativescript_register_class",
header: "godot_nativescript.h".}
proc godotScriptRegisterToolClass*(libHandle: pointer; name, base: cstring;
createFunc: GodotInstanceCreateFunc;
destroyFunc: GodotInstanceDestroyFunc) {.
importc: "godot_script_register_tool_class", header: "../godot.h".}
importc: "godot_nativescript_register_tool_class",
header: "godot_nativescript.h".}
type
GodotInstanceMethod* {.importc: "godot_instance_method",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.h", bycopy.} = object
meth* {.importc: "method".}:
proc (obj: ptr GodotObject; methodData: pointer;
userData: pointer; numArgs: cint;
@ -197,13 +201,15 @@ type
methodData* {.importc: "method_data".}: pointer
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
proc godotScriptRegisterMethod*(name: cstring; function_name: cstring;
proc godotScriptRegisterMethod*(libHandle: pointer;
name: cstring; function_name: cstring;
attr: GodotMethodAttributes;
meth: GodotInstanceMethod) {.
importc: "godot_script_register_method", header: "../godot.h".}
importc: "godot_nativescript_register_method",
header: "godot_nativescript.h".}
type
GodotPropertySetFunc* {.importc: "godot_property_set_func",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.h", bycopy.} = object
setFunc* {.importc: "set_func".}: proc (obj: ptr GodotObject;
methodData: pointer;
userData: pointer;
@ -212,22 +218,24 @@ type
freeFunc* {.importc: "free_func".}: proc (a2: pointer) {.noconv.}
GodotPropertyGetFunc* {.importc: "godot_property_get_func",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.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;
proc godotScriptRegisterProperty*(libHandle: pointer;
name: cstring; path: cstring;
attr: var GodotPropertyAttributes;
setFunc: GodotPropertySetFunc;
getFunc: GodotPropertyGetFunc) {.
importc: "godot_script_register_property", header: "../godot.h".}
importc: "godot_nativescript_register_property",
header: "godot_nativescript.h".}
type
GodotSignalArgument* {.importc: "godot_signal_argument",
header: "../godot.h", bycopy.} = object
header: "godot_nativescript.h", bycopy.} = object
name* {.importc: "name".}: GodotString
typ* {.importc: "type".}: cint
hint* {.importc: "hint".}: GodotPropertyHint
@ -235,45 +243,43 @@ type
usage* {.importc: "usage".}: GodotPropertyUsageFlags
defaultValue* {.importc: "default_value".}: Variant
GodotSignal* {.importc: "godot_signal", header: "../godot.h".} = object
GodotSignal* {.importc: "godot_signal",
header: "godot_nativescript.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 godotScriptRegisterSignal*(libHandle: pointer; name: cstring;
signal: GodotSignal) {.
importc: "godot_nativescript_register_signal",
header: "godot_nativescript.h".}
proc getUserdata*(instance: ptr GodotObject): pointer {.
importc: "godot_native_get_userdata", header: "../godot.h".}
importc: "godot_nativescript_get_userdata", header: "godot_nativescript.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".}
importc: "godot_nativescript_new", header: "godot_nativescript.h".}
proc godotStackBottom*(): pointer {.
importc: "godot_get_stack_bottom", header: "../godot.h".}
importc: "godot_get_stack_bottom", header: "godot/gdnative.h".}
proc deinit*(o: ptr GodotObject) {.
importc: "godot_object_destroy", header: "../godot.h".}
importc: "godot_object_destroy", header: "godot/gdnative.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".}
importc: "godot_print_error", header: "godot/gdnative.h".}
proc godotPrintWarning(description: cstring; function: cstring;
file: cstring; line: cint) {.
importc: "godot_print_warning", header: "../godot.h".}
importc: "godot_print_warning", header: "godot/gdnative.h".}
proc godotPrint(message: GodotString) {.
importc: "godot_print", header: "../godot.h".}
importc: "godot_print", header: "godot/gdnative.h".}
proc print*(message: string) {.inline.} =
let s = message.toGodotString()