Skip to content

Commit

Permalink
Add static method to get godot-cpp version from GDScript (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaloney authored Dec 16, 2023
1 parent 0a4625e commit a20ca27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/GDExtensionTemplate.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Unlicense

#include "godot_cpp/core/class_db.hpp"
#include "godot_cpp/core/version.hpp"

#include "GDExtensionTemplate.h"
#include "Version.h"
Expand All @@ -24,9 +25,27 @@ godot::String GDExtensionTemplate::version()
return VersionInfo::VERSION_STR.data();
}

/*!
@brief Get the godot-cpp version string for this extension.
@details
The version string is generated using godot-cpp's core/version.hpp.
@return The version string (e.g. "godot-cpp v4.2.0-stable").
*/
godot::String GDExtensionTemplate::godotCPPVersion()
{
return "godot-cpp v" + godot::uitos( GODOT_VERSION_MAJOR ) + "." +
godot::uitos( GODOT_VERSION_MINOR ) + "." + godot::uitos( GODOT_VERSION_PATCH ) + "-" +
GODOT_VERSION_STATUS;
}

/// Bind our methods so GDScript can access them.
void GDExtensionTemplate::_bind_methods()
{
godot::ClassDB::bind_static_method( "GDExtensionTemplate", godot::D_METHOD( "version" ),
&GDExtensionTemplate::version );
godot::ClassDB::bind_static_method( "GDExtensionTemplate",
godot::D_METHOD( "godot_cpp_version" ),
&GDExtensionTemplate::godotCPPVersion );
}
1 change: 1 addition & 0 deletions src/GDExtensionTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GDExtensionTemplate : public godot::Object

public:
static godot::String version();
static godot::String godotCPPVersion();

private:
static void _bind_methods();
Expand Down

0 comments on commit a20ca27

Please sign in to comment.