-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48691 from Faless/js/3.x_interfaces
[HTML5] [3.x] Implement Godot <-> JavaScript interface.
- Loading branch information
Showing
9 changed files
with
797 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="JavaScriptObject" inherits="Reference" version="3.4"> | ||
<brief_description> | ||
A wrapper class for native JavaScript objects. | ||
</brief_description> | ||
<description> | ||
JavaScriptObject is used to interact with JavaScript objects retrieved or created via [method JavaScript.get_interface], [method JavaScript.create_object], or [method JavaScript.create_callback]. | ||
Example: | ||
[codeblock] | ||
extends Node | ||
|
||
var _my_js_callback = JavaScript.create_callback(self, "myCallback") # This reference must be kept | ||
var console = JavaScript.get_interface("console") | ||
|
||
func _init(): | ||
var buf = JavaScript.create_object("ArrayBuffer", 10) # new ArrayBuffer(10) | ||
print(buf) # prints [JavaScriptObject:OBJECT_ID] | ||
var uint8arr = JavaScript.create_object("Uint8Array", buf) # new Uint8Array(buf) | ||
uint8arr[1] = 255 | ||
prints(uint8arr[1], uint8arr.byteLength) # prints 255 10 | ||
console.log(uint8arr) # prints in browser console "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]" | ||
|
||
# Equivalent of JavaScript: Array.from(uint8arr).forEach(myCallback) | ||
JavaScript.get_interface("Array").from(uint8arr).forEach(_my_js_callback) | ||
|
||
func myCallback(args): | ||
# Will be called with the parameters passed to the "forEach" callback | ||
# [0, 0, [JavaScriptObject:1173]] | ||
# [255, 1, [JavaScriptObject:1173]] | ||
# ... | ||
# [0, 9, [JavaScriptObject:1180]] | ||
print(args) | ||
[/codeblock] | ||
Note: Only available in the "HTML5" platform. | ||
</description> | ||
<tutorials> | ||
</tutorials> | ||
<methods> | ||
</methods> | ||
<constants> | ||
</constants> | ||
</class> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.