Skip to content

Commit 5cbffab

Browse files
authored
Merge pull request godotengine#1780 from piiertho/expose-object-set-script-instance
Expose gdextension_object_get_script_instance method from engine
2 parents 86e32ce + 0871c7a commit 5cbffab

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

gdextension/gdextension_interface.h

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@
3434
* Together with the JSON file, you should be able to generate any binder.
3535
*/
3636

37+
#ifndef __cplusplus
3738
#include <stddef.h>
3839
#include <stdint.h>
3940

40-
#ifndef __cplusplus
4141
typedef uint32_t char32_t;
4242
typedef uint16_t char16_t;
43-
#endif
43+
#else
44+
#include <cstddef>
45+
#include <cstdint>
4446

45-
#ifdef __cplusplus
4647
extern "C" {
4748
#endif
4849

@@ -792,16 +793,39 @@ typedef struct {
792793
const char *string;
793794
} GDExtensionGodotVersion;
794795

796+
typedef struct {
797+
uint32_t major;
798+
uint32_t minor;
799+
uint32_t patch;
800+
uint32_t hex; // Full version encoded as hexadecimal with one byte (2 hex digits) per number (e.g. for "3.1.12" it would be 0x03010C)
801+
const char *status; // (e.g. "stable", "beta", "rc1", "rc2")
802+
const char *build; // (e.g. "custom_build")
803+
const char *hash; // Full Git commit hash.
804+
uint64_t timestamp; // Git commit date UNIX timestamp in seconds, or 0 if unavailable.
805+
const char *string; // (e.g. "Godot v3.1.4.stable.official.mono")
806+
} GDExtensionGodotVersion2;
807+
795808
/**
796809
* @name get_godot_version
797810
* @since 4.1
811+
* @deprecated in Godot 4.5. Use `get_godot_version2` instead.
798812
*
799813
* Gets the Godot version that the GDExtension was loaded into.
800814
*
801815
* @param r_godot_version A pointer to the structure to write the version information into.
802816
*/
803817
typedef void (*GDExtensionInterfaceGetGodotVersion)(GDExtensionGodotVersion *r_godot_version);
804818

819+
/**
820+
* @name get_godot_version2
821+
* @since 4.5
822+
*
823+
* Gets the Godot version that the GDExtension was loaded into.
824+
*
825+
* @param r_godot_version A pointer to the structure to write the version information into.
826+
*/
827+
typedef void (*GDExtensionInterfaceGetGodotVersion2)(GDExtensionGodotVersion2 *r_godot_version);
828+
805829
/* INTERFACE: Memory */
806830

807831
/**
@@ -2723,6 +2747,17 @@ typedef void (*GDExtensionInterfacePlaceHolderScriptInstanceUpdate)(GDExtensionS
27232747
*/
27242748
typedef GDExtensionScriptInstanceDataPtr (*GDExtensionInterfaceObjectGetScriptInstance)(GDExtensionConstObjectPtr p_object, GDExtensionObjectPtr p_language);
27252749

2750+
/**
2751+
* @name object_set_script_instance
2752+
* @since 4.5
2753+
*
2754+
* Set the script instance data attached to this object.
2755+
*
2756+
* @param p_object A pointer to the Object.
2757+
* @param p_script_instance A pointer to the script instance data to attach to this object.
2758+
*/
2759+
typedef void (*GDExtensionInterfaceObjectSetScriptInstance)(GDExtensionObjectPtr p_object, GDExtensionScriptInstanceDataPtr p_script_instance);
2760+
27262761
/* INTERFACE: Callable */
27272762

27282763
/**
@@ -3086,7 +3121,7 @@ typedef void (*GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen)(const
30863121
*
30873122
* Registers a callback that Godot can call to get the list of all classes (from ClassDB) that may be used by the calling GDExtension.
30883123
*
3089-
* This is used by the editor to generate a build profiles (in "Tools" > "Engine Compilation Configuration Editor..." > "Detect from project"),
3124+
* This is used by the editor to generate a build profile (in "Tools" > "Engine Compilation Configuration Editor..." > "Detect from project"),
30903125
* in order to recompile Godot with only the classes used.
30913126
* In the provided callback, the GDExtension should provide the list of classes that _may_ be used statically, thus the time of invocation shouldn't matter.
30923127
* If a GDExtension doesn't register a callback, Godot will assume that it could be using any classes.

include/godot_cpp/godot.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ extern "C" GDExtensionInterfaceRefSetObject gdextension_interface_ref_set_object
181181
extern "C" GDExtensionInterfaceScriptInstanceCreate3 gdextension_interface_script_instance_create3;
182182
extern "C" GDExtensionInterfacePlaceHolderScriptInstanceCreate gdextension_interface_placeholder_script_instance_create;
183183
extern "C" GDExtensionInterfacePlaceHolderScriptInstanceUpdate gdextension_interface_placeholder_script_instance_update;
184+
extern "C" GDExtensionInterfaceObjectGetScriptInstance gdextension_interface_object_get_script_instance;
185+
extern "C" GDExtensionInterfaceObjectSetScriptInstance gdextension_interface_object_set_script_instance;
184186
extern "C" GDExtensionInterfaceClassdbConstructObject2 gdextension_interface_classdb_construct_object2;
185187
extern "C" GDExtensionInterfaceClassdbGetMethodBind gdextension_interface_classdb_get_method_bind;
186188
extern "C" GDExtensionInterfaceClassdbGetClassTag gdextension_interface_classdb_get_class_tag;

src/godot.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ GDExtensionInterfaceRefSetObject gdextension_interface_ref_set_object = nullptr;
188188
GDExtensionInterfaceScriptInstanceCreate3 gdextension_interface_script_instance_create3 = nullptr;
189189
GDExtensionInterfacePlaceHolderScriptInstanceCreate gdextension_interface_placeholder_script_instance_create = nullptr;
190190
GDExtensionInterfacePlaceHolderScriptInstanceUpdate gdextension_interface_placeholder_script_instance_update = nullptr;
191+
GDExtensionInterfaceObjectGetScriptInstance gdextension_interface_object_get_script_instance = nullptr;
192+
GDExtensionInterfaceObjectSetScriptInstance gdextension_interface_object_set_script_instance = nullptr;
191193
GDExtensionInterfaceClassdbConstructObject2 gdextension_interface_classdb_construct_object2 = nullptr;
192194
GDExtensionInterfaceClassdbGetMethodBind gdextension_interface_classdb_get_method_bind = nullptr;
193195
GDExtensionInterfaceClassdbGetClassTag gdextension_interface_classdb_get_class_tag = nullptr;
@@ -471,6 +473,8 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
471473
LOAD_PROC_ADDRESS(script_instance_create3, GDExtensionInterfaceScriptInstanceCreate3);
472474
LOAD_PROC_ADDRESS(placeholder_script_instance_create, GDExtensionInterfacePlaceHolderScriptInstanceCreate);
473475
LOAD_PROC_ADDRESS(placeholder_script_instance_update, GDExtensionInterfacePlaceHolderScriptInstanceUpdate);
476+
LOAD_PROC_ADDRESS(object_get_script_instance, GDExtensionInterfaceObjectGetScriptInstance);
477+
LOAD_PROC_ADDRESS(object_set_script_instance, GDExtensionInterfaceObjectSetScriptInstance);
474478
LOAD_PROC_ADDRESS(classdb_construct_object2, GDExtensionInterfaceClassdbConstructObject2);
475479
LOAD_PROC_ADDRESS(classdb_get_method_bind, GDExtensionInterfaceClassdbGetMethodBind);
476480
LOAD_PROC_ADDRESS(classdb_get_class_tag, GDExtensionInterfaceClassdbGetClassTag);

0 commit comments

Comments
 (0)