Allow GDExtensions to register virtual methods and call them on scripts

This commit is contained in:
David Snopek
2024-01-30 11:25:25 -06:00
parent 36847f6af0
commit 8fbb7cf795
14 changed files with 316 additions and 2 deletions

5
test/project/example.gd Normal file
View File

@@ -0,0 +1,5 @@
extends Example
func _do_something_virtual(p_name, p_value):
custom_signal.emit(p_name, p_value)
return "Implemented"

View File

@@ -241,6 +241,10 @@ func _ready():
assert_equal(new_example_ref.was_post_initialized(), true)
assert_equal(example.test_post_initialize(), true)
# Test a virtual method defined in GDExtension and implemented in script.
assert_equal(example.test_virtual_implemented_in_script("Virtual", 939), "Implemented")
assert_equal(custom_signal_emitted, ["Virtual", 939])
exit_with_status()
func _on_Example_custom_signal(signal_name, value):

View File

@@ -1,11 +1,13 @@
[gd_scene load_steps=2 format=3 uid="uid://dmx2xuigcpvt4"]
[gd_scene load_steps=3 format=3 uid="uid://dmx2xuigcpvt4"]
[ext_resource type="Script" path="res://main.gd" id="1_qesh5"]
[ext_resource type="Script" path="res://example.gd" id="2_jju25"]
[node name="Node" type="Node"]
script = ExtResource("1_qesh5")
[node name="Example" type="Example" parent="."]
script = ExtResource("2_jju25")
[node name="ExampleMin" type="ExampleMin" parent="Example"]
layout_mode = 0