summaryrefslogtreecommitdiffstats
path: root/modules/nativescript/nativescript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/nativescript/nativescript.cpp')
-rw-r--r--modules/nativescript/nativescript.cpp69
1 files changed, 28 insertions, 41 deletions
diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp
index c4cbfcce51..fb334e573c 100644
--- a/modules/nativescript/nativescript.cpp
+++ b/modules/nativescript/nativescript.cpp
@@ -213,11 +213,6 @@ ScriptInstance *NativeScript::instance_create(Object *p_this) {
owners_lock->unlock();
#endif
- // try to call _init
- // we don't care if it doesn't exist, so we ignore errors.
- Variant::CallError err;
- call("_init", NULL, 0, err);
-
return nsi;
}
@@ -288,9 +283,13 @@ ScriptLanguage *NativeScript::get_language() const {
bool NativeScript::has_script_signal(const StringName &p_signal) const {
NativeScriptDesc *script_data = get_script_desc();
- if (!script_data)
- return false;
- return script_data->signals_.has(p_signal);
+
+ while (script_data) {
+ if (script_data->signals_.has(p_signal))
+ return true;
+ script_data = script_data->base_data;
+ }
+ return false;
}
void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
@@ -1053,9 +1052,23 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
#endif
}
-#ifndef NO_THREADS
+void NativeScriptLanguage::call_libraries_cb(const StringName &name) {
+ // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
+ for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
+ if (L->get()->is_initialized()) {
+ L->get()->call_native_raw(
+ _noarg_call_type,
+ name,
+ NULL,
+ 0,
+ NULL,
+ NULL);
+ }
+ }
+}
void NativeScriptLanguage::frame() {
+#ifndef NO_THREADS
if (has_objects_to_register) {
MutexLock lock(mutex);
for (Set<Ref<GDNativeLibrary> >::Element *L = libs_to_init.front(); L; L = L->next()) {
@@ -1068,44 +1081,18 @@ void NativeScriptLanguage::frame() {
scripts_to_register.clear();
has_objects_to_register = false;
}
+#endif
+ call_libraries_cb(_frame_call_name);
}
+#ifndef NO_THREADS
+
void NativeScriptLanguage::thread_enter() {
- Vector<Ref<GDNative> > libs;
- {
- MutexLock lock(mutex);
- for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
- libs.push_back(L->get());
- }
- }
- for (int i = 0; i < libs.size(); ++i) {
- libs[i]->call_native_raw(
- _thread_cb_call_type,
- _thread_enter_call_name,
- NULL,
- 0,
- NULL,
- NULL);
- }
+ call_libraries_cb(_thread_enter_call_name);
}
void NativeScriptLanguage::thread_exit() {
- Vector<Ref<GDNative> > libs;
- {
- MutexLock lock(mutex);
- for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
- libs.push_back(L->get());
- }
- }
- for (int i = 0; i < libs.size(); ++i) {
- libs[i]->call_native_raw(
- _thread_cb_call_type,
- _thread_exit_call_name,
- NULL,
- 0,
- NULL,
- NULL);
- }
+ call_libraries_cb(_thread_exit_call_name);
}
#endif // NO_THREADS