summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-06-21 19:34:45 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-06-21 19:36:22 -0300
commitd57b09e47bb229b164ac34a408207882635b541b (patch)
tree2ffb77e6bf83c367333fb19ff358ce0a1785fbaf /core
parent3b5b893a0ea489585ba98361911fa210b7864a43 (diff)
Better support in ScriptLanguage for GC based scripts
Diffstat (limited to 'core')
-rw-r--r--core/reference.cpp14
-rw-r--r--core/script_language.h3
2 files changed, 15 insertions, 2 deletions
diff --git a/core/reference.cpp b/core/reference.cpp
index 90bafd0a9c..34f36a5735 100644
--- a/core/reference.cpp
+++ b/core/reference.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "reference.h"
-
+#include "script_language.h"
bool Reference::init_ref() {
@@ -66,11 +66,21 @@ int Reference::reference_get_count() const {
void Reference::reference(){
refcount.ref();
+ if (get_script_instance()) {
+ get_script_instance()->refcount_incremented();
+ }
}
bool Reference::unreference(){
- return refcount.unref();
+ bool die = refcount.unref();
+
+ if (get_script_instance()) {
+ die = die && get_script_instance()->refcount_decremented();
+ }
+
+ return die;
+
}
Reference::Reference() {
diff --git a/core/script_language.h b/core/script_language.h
index 478ebd88ed..ceaa862463 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -129,6 +129,9 @@ public:
virtual void notification(int p_notification)=0;
+ virtual void refcount_incremented() {}
+ virtual bool refcount_decremented() { return true; } //return true if it can die
+
virtual Ref<Script> get_script() const=0;
virtual bool is_placeholder() const { return false; }