summaryrefslogtreecommitdiff
path: root/platform/javascript/js
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-06-17 18:13:14 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2021-06-18 17:47:48 +0200
commitad5bdaf5aa5e7299536959fc840c291e7fb26592 (patch)
tree83c7dc8aa665028f559dabae11c12de977083440 /platform/javascript/js
parent92f20fd70e6957cd65ccb7837fdc28f9b1e4a315 (diff)
[HTML5] JS callback functions now returns passed value.
JavaScript callbacks created via the `JavaScript.create_callback` method used to always return void. With this patch they return the value returned by the Godot function as one would expect.
Diffstat (limited to 'platform/javascript/js')
-rw-r--r--platform/javascript/js/libs/library_godot_javascript_singleton.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/platform/javascript/js/libs/library_godot_javascript_singleton.js b/platform/javascript/js/libs/library_godot_javascript_singleton.js
index cb80273ca8..22ce003cd2 100644
--- a/platform/javascript/js/libs/library_godot_javascript_singleton.js
+++ b/platform/javascript/js/libs/library_godot_javascript_singleton.js
@@ -34,6 +34,7 @@ const GodotJSWrapper = {
$GodotJSWrapper__postset: 'GodotJSWrapper.proxies = new Map();',
$GodotJSWrapper: {
proxies: null,
+ cb_ret: null,
MyProxy: function (val) {
const id = IDHandler.add(this);
@@ -202,15 +203,27 @@ const GodotJSWrapper = {
let id = 0;
const cb = function () {
if (!GodotJSWrapper.get_proxied_value(id)) {
- return;
+ return undefined;
}
+ // The callback will store the returned value in this variable via
+ // "godot_js_wrapper_object_set_cb_ret" upon calling the user function.
+ // This is safe! JavaScript is single threaded (and using it in threads is not a good idea anyway).
+ GodotJSWrapper.cb_ret = null;
const args = Array.from(arguments);
func(p_ref, GodotJSWrapper.get_proxied(args), args.length);
+ const ret = GodotJSWrapper.cb_ret;
+ GodotJSWrapper.cb_ret = null;
+ return ret;
};
id = GodotJSWrapper.get_proxied(cb);
return id;
},
+ godot_js_wrapper_object_set_cb_ret__sig: 'vii',
+ godot_js_wrapper_object_set_cb_ret: function (p_val_type, p_val_ex) {
+ GodotJSWrapper.cb_ret = GodotJSWrapper.variant2js(p_val_type, p_val_ex);
+ },
+
godot_js_wrapper_object_getvar__sig: 'iiii',
godot_js_wrapper_object_getvar: function (p_id, p_type, p_exchange) {
const obj = GodotJSWrapper.get_proxied_value(p_id);