miggor-StreamGraph/classes/deck/nodes/expression_node.gd

37 lines
627 B
GDScript3
Raw Normal View History

extends DeckNode
var expr = Expression.new()
func _init():
name = "Expression"
node_type = name.to_snake_case()
description = "A Node holding a block of executable GDScript code."
category = "general"
props_to_serialize = []
2023-12-04 15:16:39 +01:00
add_output_port(DeckType.Types.ANY, "Expression Text", "codeblock")
2023-12-04 15:16:39 +01:00
func _value_request(_from_port : int) -> Variant:
var text = get_output_ports()[0].value_callback.call()
2023-12-04 15:16:39 +01:00
var err = expr.parse(text)
if err != OK:
2023-12-04 15:16:39 +01:00
printerr(err)
return null
2023-12-04 15:16:39 +01:00
var res = expr.execute()
if expr.has_execute_failed():
2023-12-04 15:16:39 +01:00
printerr("Expression Execution Failed: ", text)
return null
2023-12-04 15:16:39 +01:00
return res
2023-12-04 15:16:39 +01:00