Skip to content

Commit

Permalink
Add NativeScript support for script classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
willnationsdev committed Aug 15, 2018
1 parent d006aa0 commit 05f7173
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
40 changes: 40 additions & 0 deletions modules/gdnative/nativescript/nativescript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ void NativeScript::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_library", "library"), &NativeScript::set_library);
ClassDB::bind_method(D_METHOD("get_library"), &NativeScript::get_library);

ClassDB::bind_method(D_METHOD("set_script_class_name", "class_name"), &NativeScript::set_script_class_name);
ClassDB::bind_method(D_METHOD("get_script_class_name"), &NativeScript::get_script_class_name);
ClassDB::bind_method(D_METHOD("set_script_class_icon_path", "icon_path"), &NativeScript::set_script_class_icon_path);
ClassDB::bind_method(D_METHOD("get_script_class_icon_path"), &NativeScript::get_script_class_icon_path);

ClassDB::bind_method(D_METHOD("get_class_documentation"), &NativeScript::get_class_documentation);
ClassDB::bind_method(D_METHOD("get_method_documentation", "method"), &NativeScript::get_method_documentation);
ClassDB::bind_method(D_METHOD("get_signal_documentation", "signal_name"), &NativeScript::get_signal_documentation);
ClassDB::bind_method(D_METHOD("get_property_documentation", "path"), &NativeScript::get_property_documentation);

ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "class_name"), "set_class_name", "get_class_name");
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "library", PROPERTY_HINT_RESOURCE_TYPE, "GDNativeLibrary"), "set_library", "get_library");
ADD_GROUP("Script Class", "script_class_");
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "script_class_name"), "set_script_class_name", "get_script_class_name");
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "script_class_icon_path", PROPERTY_HINT_FILE), "set_script_class_icon_path", "get_script_class_icon_path");

ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &NativeScript::_new, MethodInfo(Variant::OBJECT, "new"));
}
Expand Down Expand Up @@ -131,6 +139,22 @@ Ref<GDNativeLibrary> NativeScript::get_library() const {
return library;
}

void NativeScript::set_script_class_name(String p_type) {
script_class_name = p_type;
}

String NativeScript::get_script_class_name() const {
return script_class_name;
}

void NativeScript::set_script_class_icon_path(String p_icon_path) {
script_class_icon_path = p_icon_path;
}

String NativeScript::get_script_class_icon_path() const {
return script_class_icon_path;
}

bool NativeScript::can_instance() const {

NativeScriptDesc *script_data = get_script_desc();
Expand Down Expand Up @@ -1396,6 +1420,22 @@ void NativeScriptLanguage::thread_exit() {

#endif // NO_THREADS

bool NativeScriptLanguage::handles_global_class_type(const String &p_type) const {
return p_type == "NativeScript";
}

String NativeScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript");
if (script.is_valid()) {
*r_base_type = script->get_instance_base_type();
*r_icon_path = script->get_script_class_icon_path();
return script->get_script_class_name();
}
*r_base_type = String();
*r_icon_path = String();
return String();
}

void NativeReloadNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_notification"), &NativeReloadNode::_notification);
}
Expand Down
11 changes: 11 additions & 0 deletions modules/gdnative/nativescript/nativescript.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class NativeScript : public Script {

String class_name;

String script_class_name;
String script_class_icon_path;

#ifndef NO_THREADS
Mutex *owners_lock;
#endif
Expand All @@ -135,6 +138,11 @@ class NativeScript : public Script {
void set_library(Ref<GDNativeLibrary> p_library);
Ref<GDNativeLibrary> get_library() const;

void set_script_class_name(String p_type);
String get_script_class_name() const;
void set_script_class_icon_path(String p_icon_path);
String get_script_class_icon_path() const;

virtual bool can_instance() const;

virtual Ref<Script> get_base_script() const; //for script inheritance
Expand Down Expand Up @@ -332,6 +340,9 @@ class NativeScriptLanguage : public ScriptLanguage {

void set_global_type_tag(int p_idx, StringName p_class_name, const void *p_type_tag);
const void *get_global_type_tag(int p_idx, StringName p_class_name) const;

virtual bool handles_global_class_type(const String &p_type) const;
virtual String get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const;
};

inline NativeScriptDesc *NativeScript::get_script_desc() const {
Expand Down

0 comments on commit 05f7173

Please sign in to comment.