-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gd
44 lines (32 loc) · 1005 Bytes
/
main.gd
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
43
extends Node
const void_value = []
var callback: JavaScriptObject
@onready var expression: = Expression.new()
func _ready() -> void:
if OS.get_name() != "Web":
on_parse_snippet(["print(\"not web\")"])
return
var window: = JavaScriptBridge.get_interface("window")
callback = JavaScriptBridge.create_callback(on_parse_snippet)
window.parseGDScriptSnippet = callback
func on_parse_snippet(args: Array) -> void:
if args == null or args.size() == 0:
return
var CustomNode = GDScript.new()
CustomNode.source_code = """extends Node
func _ready() -> void:
%s
pass
""" % args[0].indent("\t")
CustomNode.reload()
var node = CustomNode.new()
add_child(node)
node.queue_free()
func parse_expression(expr: String) -> void:
expression.parse(expr, [])
if expression.get_error_text() != "":
printerr(expression.get_error_text())
func execute_expression() -> void:
expression.execute([], self, true, false)
if expression.has_execute_failed():
printerr(expression.get_error_text())