Skip to content

Commit 0649bae

Browse files
committed
Add an example class to the project.
1 parent 7ef3bea commit 0649bae

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

doc_classes/ExampleClass.xml

+20
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

+9
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 &variant) const {
8+
print_line(vformat("Type: %d", variant.get_type()));
9+
}

src/example_class.h

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

src/register_types.cpp

+4-1
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)