File: JavaScriptObject.xml

package info (click to toggle)
godot 3.6%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 270,588 kB
  • sloc: cpp: 971,579; ansic: 617,953; xml: 80,302; asm: 17,498; cs: 14,559; python: 11,744; java: 9,681; javascript: 4,654; pascal: 1,176; sh: 896; objc: 529; makefile: 176
file content (42 lines) | stat: -rw-r--r-- 1,721 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?xml version="1.0" encoding="UTF-8" ?>
<class name="JavaScriptObject" inherits="Reference" version="3.6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
	<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]
		[b]Note:[/b] Only available in the HTML5 platform.
	</description>
	<tutorials>
	</tutorials>
	<methods>
	</methods>
	<constants>
	</constants>
</class>