Skip to content

Commit 3eb2751

Browse files
authored
Merge pull request #87 from Ivorforce/example-class
2 parents c0f558d + 65ca91b commit 3eb2751

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

demo/example.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends Node
2+
3+
4+
func _ready() -> void:
5+
var example := ExampleClass.new()
6+
example.print_type(example)

demo/example.tscn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[gd_scene load_steps=2 format=3 uid="uid://dh0oj81pufivs"]
2+
3+
[ext_resource type="Script" path="res://example.gd" id="1_jdh55"]
4+
5+
[node name="Node" type="Node"]
6+
script = ExtResource("1_jdh55")

doc_classes/ExampleClass.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="ExampleClass" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
3+
<brief_description>
4+
Example class.
5+
</brief_description>
6+
<description>
7+
An example class.
8+
</description>
9+
<tutorials>
10+
</tutorials>
11+
<methods>
12+
<method name="print_type" qualifiers="const">
13+
<return type="void" />
14+
<param index="0" name="variant" type="Variant" />
15+
<description>
16+
Print the type of the variant.
17+
</description>
18+
</method>
19+
</methods>
20+
</class>

src/example_class.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "example_class.h"
2+
3+
void ExampleClass::_bind_methods() {
4+
godot::ClassDB::bind_method(D_METHOD("print_type", "variant"), &ExampleClass::print_type);
5+
}
6+
7+
void ExampleClass::print_type(const Variant &p_variant) const {
8+
print_line(vformat("Type: %d", p_variant.get_type()));
9+
}

src/example_class.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include "godot_cpp/classes/ref_counted.hpp"
4+
#include "godot_cpp/classes/wrapped.hpp"
5+
#include "godot_cpp/variant/variant.hpp"
6+
7+
using namespace godot;
8+
9+
class ExampleClass : public RefCounted {
10+
GDCLASS(ExampleClass, RefCounted)
11+
12+
protected:
13+
static void _bind_methods();
14+
15+
public:
16+
ExampleClass() = default;
17+
~ExampleClass() override = default;
18+
19+
void print_type(const Variant &p_variant) const;
20+
};

src/register_types.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
#include "register_types.h"
2+
23
#include <gdextension_interface.h>
34
#include <godot_cpp/core/class_db.hpp>
45
#include <godot_cpp/core/defs.hpp>
56
#include <godot_cpp/godot.hpp>
67

8+
#include "example_class.h"
9+
710
using namespace godot;
811

912
void initialize_gdextension_types(ModuleInitializationLevel p_level)
1013
{
1114
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
1215
return;
1316
}
14-
//GDREGISTER_CLASS(YourClass);
17+
GDREGISTER_CLASS(ExampleClass);
1518
}
1619

1720
void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {

0 commit comments

Comments
 (0)