Skip to content

Commit c0e8ef1

Browse files
committed
Test internal classes for work on PR godotengine/godot#111090
1 parent d502d8e commit c0e8ef1

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

test/project/main.gd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ func _ready():
291291
var przykład = ExamplePrzykład.new()
292292
assert_equal(przykład.get_the_word(), "słowo to przykład")
293293

294+
print("ClassDB.class_exists: ", ClassDB.class_exists("ExampleInternal"))
295+
print("ClassDB.can_instantiate: ", ClassDB.can_instantiate("ExampleInternal"))
296+
print("ClassDB.instantiate: ", ClassDB.instantiate("ExampleInternal"))
297+
print("ClassDB.class_get_property_default_value: ", ClassDB.class_get_property_default_value("ExampleInternal", "value"))
298+
294299
exit_with_status()
295300

296301
func _on_Example_custom_signal(signal_name, value):

test/project/project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="GDExtension Test Project"
1414
run/main_scene="res://main.tscn"
15-
config/features=PackedStringArray("4.4")
15+
config/features=PackedStringArray("4.5")
1616
config/icon="res://icon.png"
1717

1818
[native_extensions]

test/src/example.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,3 +779,13 @@ void ExamplePrzykład::_bind_methods() {
779779
String ExamplePrzykład::get_the_word() const {
780780
return U"słowo to przykład";
781781
}
782+
783+
void ExampleInternal::_bind_methods() {
784+
ClassDB::bind_method(D_METHOD("get_value"), &ExampleInternal::get_value);
785+
ClassDB::bind_method(D_METHOD("set_value", "value"), &ExampleInternal::set_value);
786+
ADD_PROPERTY(PropertyInfo(Variant::INT, "value"), "set_value", "get_value");
787+
}
788+
789+
ExampleInternal::ExampleInternal() {
790+
print_line("Example internal is created!");
791+
}

test/src/example.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,18 @@ class ExamplePrzykład : public RefCounted {
288288
public:
289289
String get_the_word() const;
290290
};
291+
292+
class ExampleInternal : public Object {
293+
GDCLASS(ExampleInternal, Object);
294+
295+
int value = 33;
296+
297+
protected:
298+
static void _bind_methods();
299+
300+
public:
301+
int get_value() { return value; }
302+
void set_value(int p_value) { value = p_value; }
303+
304+
ExampleInternal();
305+
};

test/src/register_types.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void initialize_example_module(ModuleInitializationLevel p_level) {
3131
GDREGISTER_CLASS(ExampleChild);
3232
GDREGISTER_RUNTIME_CLASS(ExampleRuntime);
3333
GDREGISTER_CLASS(ExamplePrzykład);
34+
GDREGISTER_INTERNAL_CLASS(ExampleInternal);
3435
}
3536

3637
void uninitialize_example_module(ModuleInitializationLevel p_level) {

0 commit comments

Comments
 (0)