Skip to content

Add an example class to the project. #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions demo/example.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends Node


func _ready() -> void:
var example := ExampleClass.new()
example.print_type(example)
6 changes: 6 additions & 0 deletions demo/example.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dh0oj81pufivs"]

[ext_resource type="Script" path="res://example.gd" id="1_jdh55"]

[node name="Node" type="Node"]
script = ExtResource("1_jdh55")
20 changes: 20 additions & 0 deletions doc_classes/ExampleClass.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<brief_description>
Example class.
</brief_description>
<description>
An example class.
</description>
<tutorials>
</tutorials>
<methods>
<method name="print_type" qualifiers="const">
<return type="void" />
<param index="0" name="variant" type="Variant" />
<description>
Print the type of the variant.
</description>
</method>
</methods>
</class>
9 changes: 9 additions & 0 deletions src/example_class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "example_class.h"

void ExampleClass::_bind_methods() {
godot::ClassDB::bind_method(D_METHOD("print_type", "variant"), &ExampleClass::print_type);
}

void ExampleClass::print_type(const Variant &p_variant) const {
print_line(vformat("Type: %d", p_variant.get_type()));
}
20 changes: 20 additions & 0 deletions src/example_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "godot_cpp/classes/ref_counted.hpp"
#include "godot_cpp/classes/wrapped.hpp"
#include "godot_cpp/variant/variant.hpp"

using namespace godot;

class ExampleClass : public RefCounted {
GDCLASS(ExampleClass, RefCounted)

protected:
static void _bind_methods();

public:
ExampleClass() = default;
~ExampleClass() override = default;

void print_type(const Variant &p_variant) const;
};
5 changes: 4 additions & 1 deletion src/register_types.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include "register_types.h"

#include <gdextension_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

#include "example_class.h"

using namespace godot;

void initialize_gdextension_types(ModuleInitializationLevel p_level)
{
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}
//GDREGISTER_CLASS(YourClass);
GDREGISTER_CLASS(ExampleClass);
}

void uninitialize_gdextension_types(ModuleInitializationLevel p_level) {
Expand Down