summaryrefslogtreecommitdiffstats
path: root/modules/dlscript/godot.cpp
diff options
context:
space:
mode:
authorKarroffel <therzog@mail.de>2017-04-04 19:38:46 +0200
committerKarroffel <therzog@mail.de>2017-04-04 23:02:46 +0200
commit6c49fe9c62b3401323a6497447679fdfded6f116 (patch)
tree8ba50859dedf9ef940d37ccd132234a20abb7818 /modules/dlscript/godot.cpp
parent46bc14e66fe90430f1d74cdab6cca6acb5b2a3f6 (diff)
downloadredot-engine-6c49fe9c62b3401323a6497447679fdfded6f116.tar.gz
[DLScript] added variant constructor and a function to get userdata of a script
The godot_dlinstance_get_userdata() function can be used to get the DLScript userdata pointer of any object that has a DLScript attached to it. This is particularly useful and even required for language bindings to work properly. This also fixes non-tool builds.
Diffstat (limited to 'modules/dlscript/godot.cpp')
-rw-r--r--modules/dlscript/godot.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/dlscript/godot.cpp b/modules/dlscript/godot.cpp
index e987e8cf18..2851ed5ef6 100644
--- a/modules/dlscript/godot.cpp
+++ b/modules/dlscript/godot.cpp
@@ -175,6 +175,16 @@ void GDAPI godot_script_register_signal(const char *p_name, const godot_signal *
library->_register_script_signal(p_name, p_signal);
}
+void GDAPI *godot_dlinstance_get_userdata(godot_object *p_instance) {
+ Object *instance = (Object *)p_instance;
+ if (!instance)
+ return NULL;
+ if (instance->get_script_instance() && instance->get_script_instance()->get_language() == DLScriptLanguage::get_singleton()) {
+ return ((DLInstance *)instance->get_script_instance())->get_userdata();
+ }
+ return NULL;
+}
+
// System functions
void GDAPI *godot_alloc(int p_bytes) {
return memalloc(p_bytes);