Skip to content

Commit

Permalink
Merge pull request #16514 from karroffel/nativescript-extension-1
Browse files Browse the repository at this point in the history
add NativeScript extension 1
  • Loading branch information
karroffel authored Feb 9, 2018
2 parents cbdd410 + 0b2afa2 commit 68f2774
Show file tree
Hide file tree
Showing 8 changed files with 635 additions and 21 deletions.
58 changes: 43 additions & 15 deletions modules/gdnative/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,30 @@ def _build_gdnative_api_struct_header(api):

out += ['};', '']

for name in api['extensions']:
out += [
'typedef struct godot_gdnative_ext_' + name + '_api_struct {',

def generate_extension_struct(name, ext, include_version=True):
ret_val = []
if ext['next']:
ret_val += generate_extension_struct(name, ext['next'])

ret_val += [
'typedef struct godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct {',
'\tunsigned int type;',
'\tgodot_gdnative_api_version version;',
'\tconst godot_gdnative_api_struct *next;'
]

for funcdef in api['extensions'][name]['api']:
for funcdef in ext['api']:
args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']])
out.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))
ret_val.append('\t%s(*%s)(%s);' % (_spaced(funcdef['return_type']), funcdef['name'], args))

ret_val += ['} godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct;', '']

return ret_val

out += ['} godot_gdnative_ext_' + name + '_api_struct;', '']

for name in api['extensions']:
out += generate_extension_struct(name, api['extensions'][name], False)

out += [
'typedef struct godot_gdnative_core_api_struct {',
Expand Down Expand Up @@ -113,18 +124,35 @@ def _build_gdnative_api_struct_source(api):
''
]

for name in api['extensions']:
out += [
'extern const godot_gdnative_ext_' + name + '_api_struct api_extension_' + name + '_struct = {',
'\tGDNATIVE_EXT_' + api['extensions'][name]['type'] + ',',
'\t{' + str(api['extensions'][name]['version']['major']) + ', ' + str(api['extensions'][name]['version']['minor']) + '},',
'\tNULL,'
def get_extension_struct_name(name, ext, include_version=True):
return 'godot_gdnative_ext_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_api_struct'

def get_extension_struct_instance_name(name, ext, include_version=True):
return 'api_extension_' + name + ('' if not include_version else ('_{0}_{1}'.format(ext['version']['major'], ext['version']['minor']))) + '_struct'

def get_extension_struct_definition(name, ext, include_version=True):

ret_val = []

if ext['next']:
ret_val += get_extension_struct_definition(name, ext['next'])

ret_val += [
'extern const ' + get_extension_struct_name(name, ext, include_version) + ' ' + get_extension_struct_instance_name(name, ext, include_version) + ' = {',
'\tGDNATIVE_EXT_' + ext['type'] + ',',
'\t{' + str(ext['version']['major']) + ', ' + str(ext['version']['minor']) + '},',
'\t' + ('NULL' if not ext['next'] else ('(const godot_gdnative_api_struct *)&' + get_extension_struct_instance_name(name, ext['next']))) + ','
]

for funcdef in api['extensions'][name]['api']:
out.append('\t%s,' % funcdef['name'])
for funcdef in ext['api']:
ret_val.append('\t%s,' % funcdef['name'])

ret_val += ['};\n']

out += ['};\n']
return ret_val

for name in api['extensions']:
out += get_extension_struct_definition(name, api['extensions'][name], False)

out += ['', 'const godot_gdnative_api_struct *gdnative_extensions_pointers[] = {']

Expand Down
38 changes: 37 additions & 1 deletion modules/gdnative/doc_classes/NativeScript.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="NativeScript" inherits="Script" category="Core" version="3.0-stable">
<class name="NativeScript" inherits="Script" category="Core" version="3.1-dev">
<brief_description>
</brief_description>
<description>
Expand All @@ -9,10 +9,46 @@
<demos>
</demos>
<methods>
<method name="get_class_documentation" qualifiers="const">
<return type="String">
</return>
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_class_documentation[/code].
</description>
</method>
<method name="get_method_documentation" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="method" type="String">
</argument>
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_method_documentation[/code].
</description>
</method>
<method name="get_property_documentation" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="path" type="String">
</argument>
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_property_documentation[/code].
</description>
</method>
<method name="get_signal_documentation" qualifiers="const">
<return type="String">
</return>
<argument index="0" name="signal_name" type="String">
</argument>
<description>
Returns the documentation string that was previously set with [code]godot_nativescript_set_signal_documentation[/code].
</description>
</method>
<method name="new" qualifiers="vararg">
<return type="Object">
</return>
<description>
Constructs a new object of the base type with a script of this type already attached.
[i]Note[/i]: Any arguments passed to this function will be ignored and not passed to the native constructor function. This will change with in a future API extension.
</description>
</method>
</methods>
Expand Down
101 changes: 101 additions & 0 deletions modules/gdnative/gdnative_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"major": 1,
"minor": 0
},
"next": null,
"api": [
{
"name": "godot_color_new_rgba",
Expand Down Expand Up @@ -5762,6 +5763,104 @@
"major": 1,
"minor": 0
},
"next": {
"type": "NATIVESCRIPT",
"version": {
"major": 1,
"minor": 1
},
"next": null,
"api": [
{
"name": "godot_nativescript_set_method_argument_information",
"return_type": "void",
"arguments": [
["void *", "p_gdnative_handle"],
["const char *", "p_name"],
["const char *", "p_function_name"],
["int", "p_num_args"],
["const godot_method_arg *", "p_args"]
]
},
{
"name": "godot_nativescript_set_class_documentation",
"return_type": "void",
"arguments": [
["void *", "p_gdnative_handle"],
["const char *", "p_name"],
["godot_string", "p_documentation"]
]
},
{
"name": "godot_nativescript_set_method_documentation",
"return_type": "void",
"arguments": [
["void *", "p_gdnative_handle"],
["const char *", "p_name"],
["const char *", "p_function_name"],
["godot_string", "p_documentation"]
]
},
{
"name": "godot_nativescript_set_property_documentation",
"return_type": "void",
"arguments": [
["void *", "p_gdnative_handle"],
["const char *", "p_name"],
["const char *", "p_path"],
["godot_string", "p_documentation"]
]
},
{
"name": "godot_nativescript_set_signal_documentation",
"return_type": "void",
"arguments": [
["void *", "p_gdnative_handle"],
["const char *", "p_name"],
["const char *", "p_signal_name"],
["godot_string", "p_documentation"]
]
},
{
"name": "godot_nativescript_set_type_tag",
"return_type": "void",
"arguments": [
["void *", "p_gdnative_handle"],
["const char *", "p_name"],
["const void *", "p_type_tag"]
]
},
{
"name": "godot_nativescript_get_type_tag",
"return_type": "const void *",
"arguments": [
["const godot_object *", "p_object"]
]
},
{
"name": "godot_nativescript_register_instance_binding_data_functions",
"return_type": "int",
"arguments": [
["godot_instance_binding_functions", "p_binding_functions"]
]
},
{
"name": "godot_nativescript_unregister_instance_binding_data_functions",
"return_type": "void",
"arguments": [
["int", "p_idx"]
]
},
{
"name": "godot_nativescript_get_instance_binding_data",
"return_type": "void *",
"arguments": [
["int", "p_idx"],
["godot_object *", "p_object"]
]
}
]
},
"api": [
{
"name": "godot_nativescript_register_class",
Expand Down Expand Up @@ -5832,6 +5931,7 @@
"major": 1,
"minor": 0
},
"next": null,
"api": [
{
"name": "godot_pluginscript_register_language",
Expand All @@ -5848,6 +5948,7 @@
"major": 1,
"minor": 0
},
"next": null,
"api": [
{
"name": "godot_arvr_register_interface",
Expand Down
46 changes: 46 additions & 0 deletions modules/gdnative/include/nativescript/godot_nativescript.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,52 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha

void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance);

/*
*
*
* NativeScript 1.1
*
*
*/

// method registering with argument names

typedef struct {
godot_string name;

godot_variant_type type;
godot_property_hint hint;
godot_string hint_string;
} godot_method_arg;

void GDAPI godot_nativescript_set_method_argument_information(void *p_gdnative_handle, const char *p_name, const char *p_function_name, int p_num_args, const godot_method_arg *p_args);

// documentation

void GDAPI godot_nativescript_set_class_documentation(void *p_gdnative_handle, const char *p_name, godot_string p_documentation);
void GDAPI godot_nativescript_set_method_documentation(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_string p_documentation);
void GDAPI godot_nativescript_set_property_documentation(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_string p_documentation);
void GDAPI godot_nativescript_set_signal_documentation(void *p_gdnative_handle, const char *p_name, const char *p_signal_name, godot_string p_documentation);

// type tag API

void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char *p_name, const void *p_type_tag);
const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object);

// instance binding API

typedef struct {
void *(*alloc_instance_binding_data)(void *, godot_object *);
void (*free_instance_binding_data)(void *, void *);
void *data;
void (*free_func)(void *);
} godot_instance_binding_functions;

int GDAPI godot_nativescript_register_instance_binding_data_functions(godot_instance_binding_functions p_binding_functions);
void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_idx);

void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 68f2774

Please sign in to comment.