Applied latest gdnative structural changes to our simple demo

This commit is contained in:
BastiaanOlij
2017-11-23 18:52:08 +11:00
parent e5baf07bbd
commit 1f6b8d9ce5
6 changed files with 45 additions and 26 deletions

View File

@@ -1,22 +0,0 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[sub_resource type="GDNativeLibrary" id=1]
platform/X11_32bit = "res://bin/libsimple.so"
platform/X11_64bit = "res://bin/libsimple.so"
platform/Windows_32bit = "res://bin/simple.dll"
platform/Windows_64bit = "res://bin/simple.dll"
platform/OSX = "res://bin/libsimple.dylib"
platform/Android = ""
platform/iOS_32bit = ""
platform/iOS_64bit = ""
platform/WebAssembly = ""
_sections_unfolded = [ "platform" ]
[resource]
resource_name = "SIMPLE"
class_name = "SIMPLE"
library = SubResource( 1 )
_sections_unfolded = [ "Resource" ]

View File

@@ -0,0 +1,18 @@
[general]
singleton=false
load_once=true
symbol_prefix="godot_"
[entry]
X11.64="res://bin/libsimple.so"
Windows.64="res://bin/simple.dll"
OSX.64="res://bin/libsimple.dylib"
[dependencies]
X11.64=[]
Windows=[]
OSX.64=[]

View File

@@ -0,0 +1,11 @@
[gd_resource type="NativeScript" load_steps=2 format=2]
[ext_resource path="res://bin/simple.gdnlib" type="GDNativeLibrary" id=1]
[resource]
resource_name = "SIMPLE"
class_name = "SIMPLE"
library = ExtResource( 1 )
_sections_unfolded = [ "Resource" ]

View File

@@ -1,7 +1,7 @@
extends Control
# load the SIMPLE library
onready var data = preload("res://SIMPLE.gdns").new()
onready var data = preload("res://bin/SIMPLE.gdns").new()
func _on_Button_pressed():
$Label.text = "Data = " + data.get_data()

Binary file not shown.

View File

@@ -7,7 +7,8 @@ typedef struct user_data_struct {
char data[256];
} user_data_struct;
const godot_gdnative_api_struct *api = NULL;
const godot_gdnative_core_api_struct *api = NULL;
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = NULL;
GDCALLINGCONV void *simple_constructor(godot_object *p_instance, void *p_method_data);
GDCALLINGCONV void simple_destructor(godot_object *p_instance, void *p_method_data, void *p_user_data);
@@ -15,10 +16,21 @@ godot_variant simple_get_data(godot_object *p_instance, void *p_method_data, voi
void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *p_options) {
api = p_options->api_struct;
// now find our extensions
for (int i = 0; i < api->num_extensions; i++) {
switch (api->extensions[i]->type) {
case GDNATIVE_EXT_NATIVESCRIPT: {
nativescript_api = (godot_gdnative_ext_nativescript_api_struct *)api->extensions[i];
}; break;
default: break;
};
};
}
void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *p_options) {
api = NULL;
nativescript_api = NULL;
}
void GDN_EXPORT godot_nativescript_init(void *p_handle) {
@@ -28,14 +40,14 @@ void GDN_EXPORT godot_nativescript_init(void *p_handle) {
godot_instance_destroy_func destroy = { NULL, NULL, NULL };
destroy.destroy_func = &simple_destructor;
api->godot_nativescript_register_class(p_handle, "SIMPLE", "Reference", create, destroy);
nativescript_api->godot_nativescript_register_class(p_handle, "SIMPLE", "Reference", create, destroy);
godot_instance_method get_data = { NULL, NULL, NULL };
get_data.method = &simple_get_data;
godot_method_attributes attributes = { GODOT_METHOD_RPC_MODE_DISABLED };
api->godot_nativescript_register_method(p_handle, "SIMPLE", "get_data", attributes, get_data);
nativescript_api->godot_nativescript_register_method(p_handle, "SIMPLE", "get_data", attributes, get_data);
}
GDCALLINGCONV void *simple_constructor(godot_object *p_instance, void *p_method_data) {