From 0428927f5f59d65428440d238f1d41d7c59e3adb Mon Sep 17 00:00:00 2001 From: MaidOpi Date: Sun, 10 May 2026 22:29:56 +0800 Subject: [PATCH] init --- .clang-format | 80 + .gitignore | 60 + .gitmodules | 3 + CMakeLists.txt | 133 + LICENSE | 21 + README.md | 52 + gdextension_interface.h | 3118 +++++++++ .../CallableDelegateRegistry.cs | 116 + managed/GodotSharpCompat/ExportAttribute.cs | 34 + managed/GodotSharpCompat/GD.cs | 15 + managed/GodotSharpCompat/GodotObject.cs | 73 + .../GodotSharpCompat/GodotSharpCompat.csproj | 26 + managed/GodotSharpCompat/NativeCalls.cs | 9 + managed/GodotSharpCompat/Node.cs | 13 + project/Game.csproj | 30 + project/LeanCLRGodot.sln | 21 + project/icon.svg | 1 + project/icon.svg.import | 43 + project/leanclr.gdextension | 14 + project/leanclr.gdextension.uid | 1 + project/main.gd | 11 + project/main.gd.uid | 1 + project/main.tscn | 20 + project/project.godot | 19 + project/runtime_csharp_editor.tscn | 39 + project/runtime_hot_reload_demo.tscn | 78 + project/scripts/ClassDbMain.cs | 11 + project/scripts/ClassDbMain.cs.uid | 1 + project/scripts/HotReloadInputRelay.gd | 10 + project/scripts/HotReloadInputRelay.gd.uid | 1 + project/scripts/HotReloadSmoke.cs | 270 + project/scripts/HotReloadSmoke.cs.uid | 1 + project/scripts/RuntimeCSharpEditor.gd | 162 + project/scripts/RuntimeCSharpEditor.gd.uid | 1 + project/scripts/ScriptMain.cs | 546 ++ project/scripts/ScriptMain.cs.uid | 1 + src/leanclr_hot_reload_host.cpp | 174 + src/leanclr_hot_reload_host.h | 31 + src/leanclr_main_node.cpp | 40 + src/leanclr_main_node.h | 27 + src/leanclr_runtime_bridge.cpp | 2248 +++++++ src/leanclr_runtime_bridge.h | 59 + src/leanclr_script.cpp | 773 +++ src/leanclr_script.h | 71 + src/leanclr_script_language.cpp | 457 ++ src/leanclr_script_language.h | 83 + src/leanclr_script_loader.cpp | 54 + src/leanclr_script_loader.h | 22 + src/leanclr_script_saver.cpp | 79 + src/leanclr_script_saver.h | 23 + src/register_types.cpp | 96 + src/register_types.h | 11 + thirdparty/leanclr | 1 + tools/binding_generator/generate_bindings.py | 5916 +++++++++++++++++ 54 files changed, 15200 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 README.md create mode 100644 gdextension_interface.h create mode 100644 managed/GodotSharpCompat/CallableDelegateRegistry.cs create mode 100644 managed/GodotSharpCompat/ExportAttribute.cs create mode 100644 managed/GodotSharpCompat/GD.cs create mode 100644 managed/GodotSharpCompat/GodotObject.cs create mode 100644 managed/GodotSharpCompat/GodotSharpCompat.csproj create mode 100644 managed/GodotSharpCompat/NativeCalls.cs create mode 100644 managed/GodotSharpCompat/Node.cs create mode 100644 project/Game.csproj create mode 100644 project/LeanCLRGodot.sln create mode 100644 project/icon.svg create mode 100644 project/icon.svg.import create mode 100644 project/leanclr.gdextension create mode 100644 project/leanclr.gdextension.uid create mode 100644 project/main.gd create mode 100644 project/main.gd.uid create mode 100644 project/main.tscn create mode 100644 project/project.godot create mode 100644 project/runtime_csharp_editor.tscn create mode 100644 project/runtime_hot_reload_demo.tscn create mode 100644 project/scripts/ClassDbMain.cs create mode 100644 project/scripts/ClassDbMain.cs.uid create mode 100644 project/scripts/HotReloadInputRelay.gd create mode 100644 project/scripts/HotReloadInputRelay.gd.uid create mode 100644 project/scripts/HotReloadSmoke.cs create mode 100644 project/scripts/HotReloadSmoke.cs.uid create mode 100644 project/scripts/RuntimeCSharpEditor.gd create mode 100644 project/scripts/RuntimeCSharpEditor.gd.uid create mode 100644 project/scripts/ScriptMain.cs create mode 100644 project/scripts/ScriptMain.cs.uid create mode 100644 src/leanclr_hot_reload_host.cpp create mode 100644 src/leanclr_hot_reload_host.h create mode 100644 src/leanclr_main_node.cpp create mode 100644 src/leanclr_main_node.h create mode 100644 src/leanclr_runtime_bridge.cpp create mode 100644 src/leanclr_runtime_bridge.h create mode 100644 src/leanclr_script.cpp create mode 100644 src/leanclr_script.h create mode 100644 src/leanclr_script_language.cpp create mode 100644 src/leanclr_script_language.h create mode 100644 src/leanclr_script_loader.cpp create mode 100644 src/leanclr_script_loader.h create mode 100644 src/leanclr_script_saver.cpp create mode 100644 src/leanclr_script_saver.h create mode 100644 src/register_types.cpp create mode 100644 src/register_types.h create mode 160000 thirdparty/leanclr create mode 100644 tools/binding_generator/generate_bindings.py diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b535131 --- /dev/null +++ b/.clang-format @@ -0,0 +1,80 @@ +--- +# Based on LLVM style with custom modifications +BasedOnStyle: LLVM + +# Basic settings +Language: Cpp +Standard: c++17 + +# Indentation +IndentWidth: 4 +TabWidth: 4 +UseTab: Never +ColumnLimit: 160 + +# Braces +BreakBeforeBraces: Allman +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + +# Alignment +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true + +# Spacing +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false + +# Line breaks +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes + +# Pointers and references +DerivePointerAlignment: false +PointerAlignment: Left + +# Includes +SortIncludes: false +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^".*\.h"' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 + - Regex: '^<.*' + Priority: 3 + +# Other +KeepEmptyLinesAtTheStartOfBlocks: false +# Keep at most one consecutive empty line (avoids stacked blanks). +MaxEmptyLinesToKeep: 1 +# Always insert one empty line between adjacent top-level definitions (functions, +# classes, etc.) so function boundaries stay readable; does not target `if`/`for` bodies. +SeparateDefinitionBlocks: Always +NamespaceIndentation: None +ReflowComments: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b0774f --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Local editor state +.vscode/ +.vs/ +*.suo +*.user +*.userosscache +*.sln.docstates +*.rsuser + +# Secrets and local environment +*.env +.env* +!.env.example + +# Build output +[Bb]uild/ +build*/ +[Dd]ebug/ +[Rr]elease/ +[Rr]elWithDebInfo/ +[Mm]in[Ss]ize[Rr]el/ +out/ +bin/ +obj/ +godot/build*/ +godot/project/bin/ + +# CMake / native build scratch +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +compile_commands.json +*.ilk +*.lib +*.exp +*.pdb +*.obj +*.idb +*.iobj +*.ipdb +*.pch +*.tlog +*.log + +# OS files +.DS_Store +Thumbs.db + +.godot +project/leanclr/*.dll +managed/GodotSharpCompat/Generated/ +tools/binding_generator/unsupported_api_report.json + +src/generated +extension_api.json +tools/binding_generator/__pycache__/generate_bindings.cpython-314.pyc +tools/binding_generator/binding_statistics_report.md + +.cache +project/leanclr/live_reload.txt diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7f0f3e4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "thirdparty/leanclr"] + path = thirdparty/leanclr + url = https://github.com/focus-creative-games/leanclr.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..712727d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,133 @@ +cmake_minimum_required(VERSION 3.19) +project(leanclr_godot LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + +option(LEANCLR_GODOT_FETCH_GODOT_CPP "Fetch godot-cpp when GODOT_CPP_ROOT is not provided" ON) +set(GODOT_CPP_ROOT "" CACHE PATH "Path to a checked-out godot-cpp tree") +set(GODOT_CPP_LIBRARY "" CACHE FILEPATH "Path to a prebuilt godot-cpp static library. When set, godot-cpp is imported instead of built.") +set(GODOT_CPP_GEN_INCLUDE_DIR "" CACHE PATH "Path to godot-cpp generated headers, for example /gen/include") +set(GODOT_CPP_BRANCH "4.4" CACHE STRING "godot-cpp branch or tag to use when fetching") + +if(MSVC) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" CACHE STRING "Select the MSVC runtime library for GDExtension binaries." FORCE) +endif() + +function(configure_size_optimized_native_target target_name) + if(NOT TARGET ${target_name}) + return() + endif() + + set_target_properties(${target_name} PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN YES + ) + + if(NOT MSVC) + target_compile_options(${target_name} PRIVATE -ffunction-sections -fdata-sections) + endif() +endfunction() + +set(LEANCLR_ROOT "${CMAKE_CURRENT_LIST_DIR}/thirdparty/leanclr" CACHE PATH "Path to the LeanCLR source tree") +add_subdirectory(${LEANCLR_ROOT}/src/runtime leanclr_runtime) +configure_size_optimized_native_target(leanclr) + +if(MSVC) + set_target_properties(leanclr PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +endif() + +if(GODOT_CPP_LIBRARY) + if(NOT GODOT_CPP_ROOT) + message(FATAL_ERROR "GODOT_CPP_ROOT is required when GODOT_CPP_LIBRARY is set") + endif() + if(NOT GODOT_CPP_GEN_INCLUDE_DIR) + message(FATAL_ERROR "GODOT_CPP_GEN_INCLUDE_DIR is required when GODOT_CPP_LIBRARY is set") + endif() + + add_library(godot-cpp STATIC IMPORTED GLOBAL) + set_target_properties(godot-cpp PROPERTIES + IMPORTED_LOCATION "${GODOT_CPP_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GODOT_CPP_GEN_INCLUDE_DIR};${GODOT_CPP_ROOT}/include" + INTERFACE_COMPILE_FEATURES cxx_std_17 + INTERFACE_COMPILE_DEFINITIONS "GDEXTENSION;$<$:DEBUG_ENABLED>;THREADS_ENABLED;WINDOWS_ENABLED;TYPED_METHOD_BIND;NOMINMAX" + ) + + if(MSVC) + target_compile_definitions(godot-cpp INTERFACE _HAS_EXCEPTIONS=0) + target_compile_options(godot-cpp INTERFACE /utf-8) + target_link_options(godot-cpp INTERFACE $<$:/DEBUG:FULL>) + endif() +elseif(GODOT_CPP_ROOT) + add_subdirectory(${GODOT_CPP_ROOT} godot_cpp) +else() + if(NOT LEANCLR_GODOT_FETCH_GODOT_CPP) + message(FATAL_ERROR "Set GODOT_CPP_ROOT or enable LEANCLR_GODOT_FETCH_GODOT_CPP") + endif() + + include(FetchContent) + FetchContent_Declare( + godot-cpp + GIT_REPOSITORY https://github.com/godotengine/godot-cpp.git + GIT_TAG ${GODOT_CPP_BRANCH} + ) + FetchContent_MakeAvailable(godot-cpp) +endif() +configure_size_optimized_native_target(godot-cpp) + +add_library(leanclr_godot SHARED + src/generated/godot_api.generated.cpp + src/leanclr_main_node.cpp + src/leanclr_hot_reload_host.cpp + src/leanclr_runtime_bridge.cpp + src/leanclr_script.cpp + src/leanclr_script_language.cpp + src/leanclr_script_loader.cpp + src/leanclr_script_saver.cpp + src/register_types.cpp +) + +target_include_directories(leanclr_godot PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/src +) + +target_link_libraries(leanclr_godot PRIVATE + godot-cpp + leanclr +) + +if(MSVC) + target_compile_options(leanclr_godot PRIVATE /W4 /MP /bigobj) + set_target_properties(leanclr_godot PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL") +else() + target_compile_options(leanclr_godot PRIVATE -Wall -Wextra -Wpedantic) + target_compile_options(leanclr_godot PRIVATE -ffunction-sections -fdata-sections) + if(APPLE) + set(LEANCLR_GODOT_EXPORTED_SYMBOLS "${CMAKE_CURRENT_BINARY_DIR}/leanclr_godot.exports") + file(WRITE "${LEANCLR_GODOT_EXPORTED_SYMBOLS}" "_leanclr_godot_library_init\n") + target_link_options(leanclr_godot PRIVATE + -Wl,-dead_strip + -Wl,-exported_symbols_list,${LEANCLR_GODOT_EXPORTED_SYMBOLS} + ) + elseif(UNIX) + target_link_options(leanclr_godot PRIVATE -Wl,--gc-sections) + endif() +endif() + +set_target_properties(leanclr_godot PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN YES +) + +set_target_properties(leanclr_godot PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/project/bin/$" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/project/bin/$" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/project/bin/$" + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_LIST_DIR}/project/bin/Debug" + LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_LIST_DIR}/project/bin/Debug" + ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_LIST_DIR}/project/bin/Debug" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_LIST_DIR}/project/bin/Release" + LIBRARY_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_LIST_DIR}/project/bin/Release" + ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_LIST_DIR}/project/bin/Release" +) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b53cc22 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 MaidOpi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..70c0240 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# LeanCLR Godot + +浅尝一下 LeanCLR 跑 Godot 4 脚本。 + +原版Godot加载GDExtension,C# 代码交给 LeanCLR 解释执行。现在 demo 里可以把 `.cs` 直接挂到节点上,也可以在游戏窗口里的 CodeEdit 改 C#,点运行后编译一个新 assembly,然后不重启切过去。 + +已完成: + +- Godot API 绑定尽量全量生成,热更代码后面会直接用 +- C# 脚本资源能在编辑器里加载、保存、挂节点 +- 运行时热重载保留字段状态,接近 Python/Lua 那种 reload 手感 +- demo 是一个简单 Flappy Bird,用来测输入、Process、状态迁移和重载 + +先拉子模块: + +```bash +git submodule update --init --recursive +``` + +编 native 扩展: + +```bash +cmake -S . -B build-master +cmake --build build-master --config Debug --target leanclr_godot +``` + +编 demo 的 C#: + +```bash +dotnet msbuild project/Game.csproj /p:Configuration=Debug +``` + +运行项目: + +```bash +/Applications/Godot.app/Contents/MacOS/Godot --path project +``` + +几个常看的文件: + +`src/` : GDExtension 和 bridge。 + +`managed/GodotSharpCompat/` : 给 C# 用的 Godot API 外观。 + +`project/runtime_hot_reload_demo.tscn` : 现在的主 demo。 + +`project/scripts/HotReloadSmoke.cs` : Flappy 的 C# 脚本。 + +`project/scripts/RuntimeCSharpEditor.gd` : 游戏里的 C# 编辑器窗口。 + +`project/leanclr/live_reload.txt` : 热重载 marker。写 `Game` 就回到默认 `Game.dll`,写别的 assembly 名就切到那个 dll。 + diff --git a/gdextension_interface.h b/gdextension_interface.h new file mode 100644 index 0000000..73f2951 --- /dev/null +++ b/gdextension_interface.h @@ -0,0 +1,3118 @@ +/**************************************************************************/ +/* gdextension_interface.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#pragma once + +/* This is a C class header, you can copy it and use it directly in your own binders. + * Together with the `extension_api.json` file, you should be able to generate any binder. + */ + +#ifndef __cplusplus +#include +#include + +typedef uint32_t char32_t; +typedef uint16_t char16_t; +#else +#include +#include + +extern "C" { +#endif + +typedef enum { + GDEXTENSION_VARIANT_TYPE_NIL = 0, + GDEXTENSION_VARIANT_TYPE_BOOL = 1, + GDEXTENSION_VARIANT_TYPE_INT = 2, + GDEXTENSION_VARIANT_TYPE_FLOAT = 3, + GDEXTENSION_VARIANT_TYPE_STRING = 4, + GDEXTENSION_VARIANT_TYPE_VECTOR2 = 5, + GDEXTENSION_VARIANT_TYPE_VECTOR2I = 6, + GDEXTENSION_VARIANT_TYPE_RECT2 = 7, + GDEXTENSION_VARIANT_TYPE_RECT2I = 8, + GDEXTENSION_VARIANT_TYPE_VECTOR3 = 9, + GDEXTENSION_VARIANT_TYPE_VECTOR3I = 10, + GDEXTENSION_VARIANT_TYPE_TRANSFORM2D = 11, + GDEXTENSION_VARIANT_TYPE_VECTOR4 = 12, + GDEXTENSION_VARIANT_TYPE_VECTOR4I = 13, + GDEXTENSION_VARIANT_TYPE_PLANE = 14, + GDEXTENSION_VARIANT_TYPE_QUATERNION = 15, + GDEXTENSION_VARIANT_TYPE_AABB = 16, + GDEXTENSION_VARIANT_TYPE_BASIS = 17, + GDEXTENSION_VARIANT_TYPE_TRANSFORM3D = 18, + GDEXTENSION_VARIANT_TYPE_PROJECTION = 19, + GDEXTENSION_VARIANT_TYPE_COLOR = 20, + GDEXTENSION_VARIANT_TYPE_STRING_NAME = 21, + GDEXTENSION_VARIANT_TYPE_NODE_PATH = 22, + GDEXTENSION_VARIANT_TYPE_RID = 23, + GDEXTENSION_VARIANT_TYPE_OBJECT = 24, + GDEXTENSION_VARIANT_TYPE_CALLABLE = 25, + GDEXTENSION_VARIANT_TYPE_SIGNAL = 26, + GDEXTENSION_VARIANT_TYPE_DICTIONARY = 27, + GDEXTENSION_VARIANT_TYPE_ARRAY = 28, + GDEXTENSION_VARIANT_TYPE_PACKED_BYTE_ARRAY = 29, + GDEXTENSION_VARIANT_TYPE_PACKED_INT32_ARRAY = 30, + GDEXTENSION_VARIANT_TYPE_PACKED_INT64_ARRAY = 31, + GDEXTENSION_VARIANT_TYPE_PACKED_FLOAT32_ARRAY = 32, + GDEXTENSION_VARIANT_TYPE_PACKED_FLOAT64_ARRAY = 33, + GDEXTENSION_VARIANT_TYPE_PACKED_STRING_ARRAY = 34, + GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR2_ARRAY = 35, + GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR3_ARRAY = 36, + GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY = 37, + GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY = 38, + GDEXTENSION_VARIANT_TYPE_VARIANT_MAX = 39, +} GDExtensionVariantType; + +typedef enum { + GDEXTENSION_VARIANT_OP_EQUAL = 0, + GDEXTENSION_VARIANT_OP_NOT_EQUAL = 1, + GDEXTENSION_VARIANT_OP_LESS = 2, + GDEXTENSION_VARIANT_OP_LESS_EQUAL = 3, + GDEXTENSION_VARIANT_OP_GREATER = 4, + GDEXTENSION_VARIANT_OP_GREATER_EQUAL = 5, + GDEXTENSION_VARIANT_OP_ADD = 6, + GDEXTENSION_VARIANT_OP_SUBTRACT = 7, + GDEXTENSION_VARIANT_OP_MULTIPLY = 8, + GDEXTENSION_VARIANT_OP_DIVIDE = 9, + GDEXTENSION_VARIANT_OP_NEGATE = 10, + GDEXTENSION_VARIANT_OP_POSITIVE = 11, + GDEXTENSION_VARIANT_OP_MODULE = 12, + GDEXTENSION_VARIANT_OP_POWER = 13, + GDEXTENSION_VARIANT_OP_SHIFT_LEFT = 14, + GDEXTENSION_VARIANT_OP_SHIFT_RIGHT = 15, + GDEXTENSION_VARIANT_OP_BIT_AND = 16, + GDEXTENSION_VARIANT_OP_BIT_OR = 17, + GDEXTENSION_VARIANT_OP_BIT_XOR = 18, + GDEXTENSION_VARIANT_OP_BIT_NEGATE = 19, + GDEXTENSION_VARIANT_OP_AND = 20, + GDEXTENSION_VARIANT_OP_OR = 21, + GDEXTENSION_VARIANT_OP_XOR = 22, + GDEXTENSION_VARIANT_OP_NOT = 23, + GDEXTENSION_VARIANT_OP_IN = 24, + GDEXTENSION_VARIANT_OP_MAX = 25, +} GDExtensionVariantOperator; + +/* In this API there are multiple functions which expect the caller to pass a pointer + * on return value as parameter. + * In order to make it clear if the caller should initialize the return value or not + * we have two flavor of types: + * - `GDExtensionXXXPtr` for pointer on an initialized value + * - `GDExtensionUninitializedXXXPtr` for pointer on uninitialized value + * + * Notes: + * - Not respecting those requirements can seems harmless, but will lead to unexpected + * segfault or memory leak (for instance with a specific compiler/OS, or when two + * native extensions start doing ptrcall on each other). + * - Initialization must be done with the function pointer returned by `variant_get_ptr_constructor`, + * zero-initializing the variable should not be considered a valid initialization method here ! + * - Some types have no destructor (see `extension_api.json`'s `has_destructor` field), for + * them it is always safe to skip the constructor for the return value if you are in a hurry ;-) + */ +typedef void *GDExtensionVariantPtr; +typedef const void *GDExtensionConstVariantPtr; +typedef void *GDExtensionUninitializedVariantPtr; +typedef void *GDExtensionStringNamePtr; +typedef const void *GDExtensionConstStringNamePtr; +typedef void *GDExtensionUninitializedStringNamePtr; +typedef void *GDExtensionStringPtr; +typedef const void *GDExtensionConstStringPtr; +typedef void *GDExtensionUninitializedStringPtr; +typedef void *GDExtensionObjectPtr; +typedef const void *GDExtensionConstObjectPtr; +typedef void *GDExtensionUninitializedObjectPtr; +typedef void *GDExtensionTypePtr; +typedef const void *GDExtensionConstTypePtr; +typedef void *GDExtensionUninitializedTypePtr; +typedef const void *GDExtensionMethodBindPtr; +typedef int64_t GDExtensionInt; +typedef uint8_t GDExtensionBool; +typedef uint64_t GDObjectInstanceID; +typedef void *GDExtensionRefPtr; +typedef const void *GDExtensionConstRefPtr; +typedef enum { + GDEXTENSION_CALL_OK = 0, + GDEXTENSION_CALL_ERROR_INVALID_METHOD = 1, + /* Expected a different variant type. */ + GDEXTENSION_CALL_ERROR_INVALID_ARGUMENT = 2, + /* Expected lower number of arguments. */ + GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS = 3, + /* Expected higher number of arguments. */ + GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS = 4, + GDEXTENSION_CALL_ERROR_INSTANCE_IS_NULL = 5, + /* Used for const call. */ + GDEXTENSION_CALL_ERROR_METHOD_NOT_CONST = 6, +} GDExtensionCallErrorType; + +typedef struct { + GDExtensionCallErrorType error; + int32_t argument; + int32_t expected; +} GDExtensionCallError; + +typedef void (*GDExtensionVariantFromTypeConstructorFunc)(GDExtensionUninitializedVariantPtr, GDExtensionTypePtr); +typedef void (*GDExtensionTypeFromVariantConstructorFunc)(GDExtensionUninitializedTypePtr, GDExtensionVariantPtr); +typedef void *(*GDExtensionVariantGetInternalPtrFunc)(GDExtensionVariantPtr); +typedef void (*GDExtensionPtrOperatorEvaluator)(GDExtensionConstTypePtr p_left, GDExtensionConstTypePtr p_right, GDExtensionTypePtr r_result); +typedef void (*GDExtensionPtrBuiltInMethod)(GDExtensionTypePtr p_base, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_return, int32_t p_argument_count); +typedef void (*GDExtensionPtrConstructor)(GDExtensionUninitializedTypePtr p_base, const GDExtensionConstTypePtr *p_args); +typedef void (*GDExtensionPtrDestructor)(GDExtensionTypePtr p_base); +typedef void (*GDExtensionPtrSetter)(GDExtensionTypePtr p_base, GDExtensionConstTypePtr p_value); +typedef void (*GDExtensionPtrGetter)(GDExtensionConstTypePtr p_base, GDExtensionTypePtr r_value); +typedef void (*GDExtensionPtrIndexedSetter)(GDExtensionTypePtr p_base, GDExtensionInt p_index, GDExtensionConstTypePtr p_value); +typedef void (*GDExtensionPtrIndexedGetter)(GDExtensionConstTypePtr p_base, GDExtensionInt p_index, GDExtensionTypePtr r_value); +typedef void (*GDExtensionPtrKeyedSetter)(GDExtensionTypePtr p_base, GDExtensionConstTypePtr p_key, GDExtensionConstTypePtr p_value); +typedef void (*GDExtensionPtrKeyedGetter)(GDExtensionConstTypePtr p_base, GDExtensionConstTypePtr p_key, GDExtensionTypePtr r_value); +typedef uint32_t (*GDExtensionPtrKeyedChecker)(GDExtensionConstVariantPtr p_base, GDExtensionConstVariantPtr p_key); +typedef void (*GDExtensionPtrUtilityFunction)(GDExtensionTypePtr r_return, const GDExtensionConstTypePtr *p_args, int32_t p_argument_count); +typedef GDExtensionObjectPtr (*GDExtensionClassConstructor)(); +typedef void *(*GDExtensionInstanceBindingCreateCallback)(void *p_token, void *p_instance); +typedef void (*GDExtensionInstanceBindingFreeCallback)(void *p_token, void *p_instance, void *p_binding); +typedef GDExtensionBool (*GDExtensionInstanceBindingReferenceCallback)(void *p_token, void *p_binding, GDExtensionBool p_reference); +typedef struct { + GDExtensionInstanceBindingCreateCallback create_callback; + GDExtensionInstanceBindingFreeCallback free_callback; + GDExtensionInstanceBindingReferenceCallback reference_callback; +} GDExtensionInstanceBindingCallbacks; + +typedef void *GDExtensionClassInstancePtr; +typedef GDExtensionBool (*GDExtensionClassSet)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value); +typedef GDExtensionBool (*GDExtensionClassGet)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret); +typedef uint64_t (*GDExtensionClassGetRID)(GDExtensionClassInstancePtr p_instance); +typedef struct { + GDExtensionVariantType type; + GDExtensionStringNamePtr name; + GDExtensionStringNamePtr class_name; + /* Bitfield of `PropertyHint` (defined in `extension_api.json`). */ + uint32_t hint; + GDExtensionStringPtr hint_string; + /* Bitfield of `PropertyUsageFlags` (defined in `extension_api.json`). */ + uint32_t usage; +} GDExtensionPropertyInfo; + +typedef struct { + GDExtensionStringNamePtr name; + GDExtensionPropertyInfo return_value; + /* Bitfield of `GDExtensionClassMethodFlags`. */ + uint32_t flags; + int32_t id; + /* Arguments: `default_arguments` is an array of size `argument_count`. */ + uint32_t argument_count; + GDExtensionPropertyInfo *arguments; + /* Default arguments: `default_arguments` is an array of size `default_argument_count`. */ + uint32_t default_argument_count; + GDExtensionVariantPtr *default_arguments; +} GDExtensionMethodInfo; + +typedef const GDExtensionPropertyInfo *(*GDExtensionClassGetPropertyList)(GDExtensionClassInstancePtr p_instance, uint32_t *r_count); +typedef void (*GDExtensionClassFreePropertyList)(GDExtensionClassInstancePtr p_instance, const GDExtensionPropertyInfo *p_list); +typedef void (*GDExtensionClassFreePropertyList2)(GDExtensionClassInstancePtr p_instance, const GDExtensionPropertyInfo *p_list, uint32_t p_count); +typedef GDExtensionBool (*GDExtensionClassPropertyCanRevert)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name); +typedef GDExtensionBool (*GDExtensionClassPropertyGetRevert)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret); +typedef GDExtensionBool (*GDExtensionClassValidateProperty)(GDExtensionClassInstancePtr p_instance, GDExtensionPropertyInfo *p_property); +typedef void (*GDExtensionClassNotification)(GDExtensionClassInstancePtr p_instance, int32_t p_what); /* Deprecated in Godot 4.2. Use `GDExtensionClassNotification2` instead. */ +typedef void (*GDExtensionClassNotification2)(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed); +typedef void (*GDExtensionClassToString)(GDExtensionClassInstancePtr p_instance, GDExtensionBool *r_is_valid, GDExtensionStringPtr p_out); +typedef void (*GDExtensionClassReference)(GDExtensionClassInstancePtr p_instance); +typedef void (*GDExtensionClassUnreference)(GDExtensionClassInstancePtr p_instance); +typedef void (*GDExtensionClassCallVirtual)(GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret); +typedef GDExtensionObjectPtr (*GDExtensionClassCreateInstance)(void *p_class_userdata); +typedef GDExtensionObjectPtr (*GDExtensionClassCreateInstance2)(void *p_class_userdata, GDExtensionBool p_notify_postinitialize); +typedef void (*GDExtensionClassFreeInstance)(void *p_class_userdata, GDExtensionClassInstancePtr p_instance); +typedef GDExtensionClassInstancePtr (*GDExtensionClassRecreateInstance)(void *p_class_userdata, GDExtensionObjectPtr p_object); +typedef GDExtensionClassCallVirtual (*GDExtensionClassGetVirtual)(void *p_class_userdata, GDExtensionConstStringNamePtr p_name); +typedef GDExtensionClassCallVirtual (*GDExtensionClassGetVirtual2)(void *p_class_userdata, GDExtensionConstStringNamePtr p_name, uint32_t p_hash); +typedef void *(*GDExtensionClassGetVirtualCallData)(void *p_class_userdata, GDExtensionConstStringNamePtr p_name); +typedef void *(*GDExtensionClassGetVirtualCallData2)(void *p_class_userdata, GDExtensionConstStringNamePtr p_name, uint32_t p_hash); +typedef void (*GDExtensionClassCallVirtualWithData)(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, void *p_virtual_call_userdata, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret); +typedef struct { + GDExtensionBool is_virtual; + GDExtensionBool is_abstract; + GDExtensionClassSet set_func; + GDExtensionClassGet get_func; + GDExtensionClassGetPropertyList get_property_list_func; + GDExtensionClassFreePropertyList free_property_list_func; + GDExtensionClassPropertyCanRevert property_can_revert_func; + GDExtensionClassPropertyGetRevert property_get_revert_func; + GDExtensionClassNotification notification_func; + GDExtensionClassToString to_string_func; + GDExtensionClassReference reference_func; + GDExtensionClassUnreference unreference_func; + /* (Default) constructor; mandatory. If the class is not instantiable, consider making it virtual or abstract. */ + GDExtensionClassCreateInstance create_instance_func; + /* Destructor; mandatory. */ + GDExtensionClassFreeInstance free_instance_func; + /* Queries a virtual function by name and returns a callback to invoke the requested virtual function. */ + GDExtensionClassGetVirtual get_virtual_func; + GDExtensionClassGetRID get_rid_func; + /* Per-class user data, later accessible in instance bindings. */ + void *class_userdata; +} GDExtensionClassCreationInfo; /* Deprecated in Godot 4.2. Use `GDExtensionClassCreationInfo4` instead. */ + +typedef struct { + GDExtensionBool is_virtual; + GDExtensionBool is_abstract; + GDExtensionBool is_exposed; + GDExtensionClassSet set_func; + GDExtensionClassGet get_func; + GDExtensionClassGetPropertyList get_property_list_func; + GDExtensionClassFreePropertyList free_property_list_func; + GDExtensionClassPropertyCanRevert property_can_revert_func; + GDExtensionClassPropertyGetRevert property_get_revert_func; + GDExtensionClassValidateProperty validate_property_func; + GDExtensionClassNotification2 notification_func; + GDExtensionClassToString to_string_func; + GDExtensionClassReference reference_func; + GDExtensionClassUnreference unreference_func; + /* (Default) constructor; mandatory. If the class is not instantiable, consider making it virtual or abstract. */ + GDExtensionClassCreateInstance create_instance_func; + /* Destructor; mandatory. */ + GDExtensionClassFreeInstance free_instance_func; + GDExtensionClassRecreateInstance recreate_instance_func; + /* Queries a virtual function by name and returns a callback to invoke the requested virtual function. */ + GDExtensionClassGetVirtual get_virtual_func; + /* Paired with `call_virtual_with_data_func`, this is an alternative to `get_virtual_func` for extensions that + * need or benefit from extra data when calling virtual functions. + * Returns user data that will be passed to `call_virtual_with_data_func`. + * Returning `NULL` from this function signals to Godot that the virtual function is not overridden. + * Data returned from this function should be managed by the extension and must be valid until the extension is deinitialized. + * You should supply either `get_virtual_func`, or `get_virtual_call_data_func` with `call_virtual_with_data_func`. + */ + GDExtensionClassGetVirtualCallData get_virtual_call_data_func; + /* Used to call virtual functions when `get_virtual_call_data_func` is not null. */ + GDExtensionClassCallVirtualWithData call_virtual_with_data_func; + GDExtensionClassGetRID get_rid_func; + /* Per-class user data, later accessible in instance bindings. */ + void *class_userdata; +} GDExtensionClassCreationInfo2; /* Deprecated in Godot 4.3. Use `GDExtensionClassCreationInfo4` instead. */ + +typedef struct { + GDExtensionBool is_virtual; + GDExtensionBool is_abstract; + GDExtensionBool is_exposed; + GDExtensionBool is_runtime; + GDExtensionClassSet set_func; + GDExtensionClassGet get_func; + GDExtensionClassGetPropertyList get_property_list_func; + GDExtensionClassFreePropertyList2 free_property_list_func; + GDExtensionClassPropertyCanRevert property_can_revert_func; + GDExtensionClassPropertyGetRevert property_get_revert_func; + GDExtensionClassValidateProperty validate_property_func; + GDExtensionClassNotification2 notification_func; + GDExtensionClassToString to_string_func; + GDExtensionClassReference reference_func; + GDExtensionClassUnreference unreference_func; + /* (Default) constructor; mandatory. If the class is not instantiable, consider making it virtual or abstract. */ + GDExtensionClassCreateInstance create_instance_func; + /* Destructor; mandatory. */ + GDExtensionClassFreeInstance free_instance_func; + GDExtensionClassRecreateInstance recreate_instance_func; + /* Queries a virtual function by name and returns a callback to invoke the requested virtual function. */ + GDExtensionClassGetVirtual get_virtual_func; + /* Paired with `call_virtual_with_data_func`, this is an alternative to `get_virtual_func` for extensions that + * need or benefit from extra data when calling virtual functions. + * Returns user data that will be passed to `call_virtual_with_data_func`. + * Returning `NULL` from this function signals to Godot that the virtual function is not overridden. + * Data returned from this function should be managed by the extension and must be valid until the extension is deinitialized. + * You should supply either `get_virtual_func`, or `get_virtual_call_data_func` with `call_virtual_with_data_func`. + */ + GDExtensionClassGetVirtualCallData get_virtual_call_data_func; + /* Used to call virtual functions when `get_virtual_call_data_func` is not null. */ + GDExtensionClassCallVirtualWithData call_virtual_with_data_func; + GDExtensionClassGetRID get_rid_func; + /* Per-class user data, later accessible in instance bindings. */ + void *class_userdata; +} GDExtensionClassCreationInfo3; /* Deprecated in Godot 4.4. Use `GDExtensionClassCreationInfo4` instead. */ + +typedef struct { + GDExtensionBool is_virtual; + GDExtensionBool is_abstract; + GDExtensionBool is_exposed; + GDExtensionBool is_runtime; + GDExtensionConstStringPtr icon_path; + GDExtensionClassSet set_func; + GDExtensionClassGet get_func; + GDExtensionClassGetPropertyList get_property_list_func; + GDExtensionClassFreePropertyList2 free_property_list_func; + GDExtensionClassPropertyCanRevert property_can_revert_func; + GDExtensionClassPropertyGetRevert property_get_revert_func; + GDExtensionClassValidateProperty validate_property_func; + GDExtensionClassNotification2 notification_func; + GDExtensionClassToString to_string_func; + GDExtensionClassReference reference_func; + GDExtensionClassUnreference unreference_func; + /* (Default) constructor; mandatory. If the class is not instantiable, consider making it virtual or abstract. */ + GDExtensionClassCreateInstance2 create_instance_func; + /* Destructor; mandatory. */ + GDExtensionClassFreeInstance free_instance_func; + GDExtensionClassRecreateInstance recreate_instance_func; + /* Queries a virtual function by name and returns a callback to invoke the requested virtual function. */ + GDExtensionClassGetVirtual2 get_virtual_func; + /* Paired with `call_virtual_with_data_func`, this is an alternative to `get_virtual_func` for extensions that + * need or benefit from extra data when calling virtual functions. + * Returns user data that will be passed to `call_virtual_with_data_func`. + * Returning `NULL` from this function signals to Godot that the virtual function is not overridden. + * Data returned from this function should be managed by the extension and must be valid until the extension is deinitialized. + * You should supply either `get_virtual_func`, or `get_virtual_call_data_func` with `call_virtual_with_data_func`. + */ + GDExtensionClassGetVirtualCallData2 get_virtual_call_data_func; + /* Used to call virtual functions when `get_virtual_call_data_func` is not null. */ + GDExtensionClassCallVirtualWithData call_virtual_with_data_func; + /* Per-class user data, later accessible in instance bindings. */ + void *class_userdata; +} GDExtensionClassCreationInfo4; + +typedef GDExtensionClassCreationInfo4 GDExtensionClassCreationInfo5; +typedef void *GDExtensionClassLibraryPtr; +/* Passed a pointer to a PackedStringArray that should be filled with the classes that may be used by the GDExtension. */ +typedef void (*GDExtensionEditorGetClassesUsedCallback)(GDExtensionTypePtr p_packed_string_array); +typedef enum { + GDEXTENSION_METHOD_FLAG_NORMAL = 1, + GDEXTENSION_METHOD_FLAG_EDITOR = 2, + GDEXTENSION_METHOD_FLAG_CONST = 4, + GDEXTENSION_METHOD_FLAG_VIRTUAL = 8, + GDEXTENSION_METHOD_FLAG_VARARG = 16, + GDEXTENSION_METHOD_FLAG_STATIC = 32, + GDEXTENSION_METHOD_FLAG_VIRTUAL_REQUIRED = 128, + GDEXTENSION_METHOD_FLAGS_DEFAULT = 1, +} GDExtensionClassMethodFlags; + +typedef enum { + GDEXTENSION_METHOD_ARGUMENT_METADATA_NONE = 0, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT8 = 1, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT16 = 2, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT32 = 3, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_INT64 = 4, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT8 = 5, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT16 = 6, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT32 = 7, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_UINT64 = 8, + GDEXTENSION_METHOD_ARGUMENT_METADATA_REAL_IS_FLOAT = 9, + GDEXTENSION_METHOD_ARGUMENT_METADATA_REAL_IS_DOUBLE = 10, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_CHAR16 = 11, + GDEXTENSION_METHOD_ARGUMENT_METADATA_INT_IS_CHAR32 = 12, + GDEXTENSION_METHOD_ARGUMENT_METADATA_OBJECT_IS_REQUIRED = 13, +} GDExtensionClassMethodArgumentMetadata; + +typedef void (*GDExtensionClassMethodCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error); +typedef void (*GDExtensionClassMethodValidatedCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionVariantPtr r_return); +typedef void (*GDExtensionClassMethodPtrCall)(void *method_userdata, GDExtensionClassInstancePtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret); +typedef struct { + GDExtensionStringNamePtr name; + void *method_userdata; + GDExtensionClassMethodCall call_func; + GDExtensionClassMethodPtrCall ptrcall_func; + /* Bitfield of `GDExtensionClassMethodFlags`. */ + uint32_t method_flags; + /* If `has_return_value` is false, `return_value_info` and `return_value_metadata` are ignored. + * + * @todo Consider dropping `has_return_value` and making the other two properties match `GDExtensionMethodInfo` and `GDExtensionClassVirtualMethod` for consistency in future version of this struct. + */ + GDExtensionBool has_return_value; + GDExtensionPropertyInfo *return_value_info; + GDExtensionClassMethodArgumentMetadata return_value_metadata; + /* Arguments: `arguments_info` and `arguments_metadata` are array of size `argument_count`. + * Name and hint information for the argument can be omitted in release builds. Class name should always be present if it applies. + * + * @todo Consider renaming `arguments_info` to `arguments` for consistency in future version of this struct. + */ + uint32_t argument_count; + GDExtensionPropertyInfo *arguments_info; + GDExtensionClassMethodArgumentMetadata *arguments_metadata; + /* Default arguments: `default_arguments` is an array of size `default_argument_count`. */ + uint32_t default_argument_count; + GDExtensionVariantPtr *default_arguments; +} GDExtensionClassMethodInfo; + +typedef struct { + GDExtensionStringNamePtr name; + /* Bitfield of `GDExtensionClassMethodFlags`. */ + uint32_t method_flags; + GDExtensionPropertyInfo return_value; + GDExtensionClassMethodArgumentMetadata return_value_metadata; + uint32_t argument_count; + GDExtensionPropertyInfo *arguments; + GDExtensionClassMethodArgumentMetadata *arguments_metadata; +} GDExtensionClassVirtualMethodInfo; + +typedef void (*GDExtensionCallableCustomCall)(void *callable_userdata, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error); +typedef GDExtensionBool (*GDExtensionCallableCustomIsValid)(void *callable_userdata); +typedef void (*GDExtensionCallableCustomFree)(void *callable_userdata); +typedef uint32_t (*GDExtensionCallableCustomHash)(void *callable_userdata); +typedef GDExtensionBool (*GDExtensionCallableCustomEqual)(void *callable_userdata_a, void *callable_userdata_b); +typedef GDExtensionBool (*GDExtensionCallableCustomLessThan)(void *callable_userdata_a, void *callable_userdata_b); +typedef void (*GDExtensionCallableCustomToString)(void *callable_userdata, GDExtensionBool *r_is_valid, GDExtensionStringPtr r_out); +typedef GDExtensionInt (*GDExtensionCallableCustomGetArgumentCount)(void *callable_userdata, GDExtensionBool *r_is_valid); +/* Only `call_func` and `token` are strictly required, however, `object_id` should be passed if its not a static method. + * + * `token` should point to an address that uniquely identifies the GDExtension (for example, the + * `GDExtensionClassLibraryPtr` passed to the entry symbol function. + * + * `hash_func`, `equal_func`, and `less_than_func` are optional. If not provided both `call_func` and + * `callable_userdata` together are used as the identity of the callable for hashing and comparison purposes. + * + * The hash returned by `hash_func` is cached, `hash_func` will not be called more than once per callable. + * + * `is_valid_func` is necessary if the validity of the callable can change before destruction. + * + * `free_func` is necessary if `callable_userdata` needs to be cleaned up when the callable is freed. + */ +typedef struct { + void *callable_userdata; + void *token; + GDObjectInstanceID object_id; + GDExtensionCallableCustomCall call_func; + GDExtensionCallableCustomIsValid is_valid_func; + GDExtensionCallableCustomFree free_func; + GDExtensionCallableCustomHash hash_func; + GDExtensionCallableCustomEqual equal_func; + GDExtensionCallableCustomLessThan less_than_func; + GDExtensionCallableCustomToString to_string_func; +} GDExtensionCallableCustomInfo; /* Deprecated in Godot 4.3. Use `GDExtensionCallableCustomInfo2` instead. */ + +/* Only `call_func` and `token` are strictly required, however, `object_id` should be passed if its not a static method. + * + * `token` should point to an address that uniquely identifies the GDExtension (for example, the + * `GDExtensionClassLibraryPtr` passed to the entry symbol function. + * + * `hash_func`, `equal_func`, and `less_than_func` are optional. If not provided both `call_func` and + * `callable_userdata` together are used as the identity of the callable for hashing and comparison purposes. + * + * The hash returned by `hash_func` is cached, `hash_func` will not be called more than once per callable. + * + * `is_valid_func` is necessary if the validity of the callable can change before destruction. + * + * `free_func` is necessary if `callable_userdata` needs to be cleaned up when the callable is freed. + */ +typedef struct { + void *callable_userdata; + void *token; + GDObjectInstanceID object_id; + GDExtensionCallableCustomCall call_func; + GDExtensionCallableCustomIsValid is_valid_func; + GDExtensionCallableCustomFree free_func; + GDExtensionCallableCustomHash hash_func; + GDExtensionCallableCustomEqual equal_func; + GDExtensionCallableCustomLessThan less_than_func; + GDExtensionCallableCustomToString to_string_func; + GDExtensionCallableCustomGetArgumentCount get_argument_count_func; +} GDExtensionCallableCustomInfo2; + +/* Pointer to custom ScriptInstance native implementation. */ +typedef void *GDExtensionScriptInstanceDataPtr; +typedef GDExtensionBool (*GDExtensionScriptInstanceSet)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value); +typedef GDExtensionBool (*GDExtensionScriptInstanceGet)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret); +typedef const GDExtensionPropertyInfo *(*GDExtensionScriptInstanceGetPropertyList)(GDExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count); +typedef void (*GDExtensionScriptInstanceFreePropertyList)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionPropertyInfo *p_list); /* Deprecated in Godot 4.3. Use `GDExtensionScriptInstanceFreePropertyList2` instead. */ +typedef void (*GDExtensionScriptInstanceFreePropertyList2)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionPropertyInfo *p_list, uint32_t p_count); +typedef GDExtensionBool (*GDExtensionScriptInstanceGetClassCategory)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_class_category); +typedef GDExtensionVariantType (*GDExtensionScriptInstanceGetPropertyType)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionBool *r_is_valid); +typedef GDExtensionBool (*GDExtensionScriptInstanceValidateProperty)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionPropertyInfo *p_property); +typedef GDExtensionBool (*GDExtensionScriptInstancePropertyCanRevert)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name); +typedef GDExtensionBool (*GDExtensionScriptInstancePropertyGetRevert)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret); +typedef GDExtensionObjectPtr (*GDExtensionScriptInstanceGetOwner)(GDExtensionScriptInstanceDataPtr p_instance); +typedef void (*GDExtensionScriptInstancePropertyStateAdd)(GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value, void *p_userdata); +typedef void (*GDExtensionScriptInstanceGetPropertyState)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionScriptInstancePropertyStateAdd p_add_func, void *p_userdata); +typedef const GDExtensionMethodInfo *(*GDExtensionScriptInstanceGetMethodList)(GDExtensionScriptInstanceDataPtr p_instance, uint32_t *r_count); +typedef void (*GDExtensionScriptInstanceFreeMethodList)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionMethodInfo *p_list); /* Deprecated in Godot 4.3. Use `GDExtensionScriptInstanceFreeMethodList2` instead. */ +typedef void (*GDExtensionScriptInstanceFreeMethodList2)(GDExtensionScriptInstanceDataPtr p_instance, const GDExtensionMethodInfo *p_list, uint32_t p_count); +typedef GDExtensionBool (*GDExtensionScriptInstanceHasMethod)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name); +typedef GDExtensionInt (*GDExtensionScriptInstanceGetMethodArgumentCount)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionBool *r_is_valid); +typedef void (*GDExtensionScriptInstanceCall)(GDExtensionScriptInstanceDataPtr p_self, GDExtensionConstStringNamePtr p_method, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionVariantPtr r_return, GDExtensionCallError *r_error); +typedef void (*GDExtensionScriptInstanceNotification)(GDExtensionScriptInstanceDataPtr p_instance, int32_t p_what); /* Deprecated in Godot 4.2. Use `GDExtensionScriptInstanceNotification2` instead. */ +typedef void (*GDExtensionScriptInstanceNotification2)(GDExtensionScriptInstanceDataPtr p_instance, int32_t p_what, GDExtensionBool p_reversed); +typedef void (*GDExtensionScriptInstanceToString)(GDExtensionScriptInstanceDataPtr p_instance, GDExtensionBool *r_is_valid, GDExtensionStringPtr r_out); +typedef void (*GDExtensionScriptInstanceRefCountIncremented)(GDExtensionScriptInstanceDataPtr p_instance); +typedef GDExtensionBool (*GDExtensionScriptInstanceRefCountDecremented)(GDExtensionScriptInstanceDataPtr p_instance); +typedef GDExtensionObjectPtr (*GDExtensionScriptInstanceGetScript)(GDExtensionScriptInstanceDataPtr p_instance); +typedef GDExtensionBool (*GDExtensionScriptInstanceIsPlaceholder)(GDExtensionScriptInstanceDataPtr p_instance); +typedef void *GDExtensionScriptLanguagePtr; +typedef GDExtensionScriptLanguagePtr (*GDExtensionScriptInstanceGetLanguage)(GDExtensionScriptInstanceDataPtr p_instance); +typedef void (*GDExtensionScriptInstanceFree)(GDExtensionScriptInstanceDataPtr p_instance); +/* Pointer to ScriptInstance. */ +typedef void *GDExtensionScriptInstancePtr; +typedef struct { + GDExtensionScriptInstanceSet set_func; + GDExtensionScriptInstanceGet get_func; + GDExtensionScriptInstanceGetPropertyList get_property_list_func; + GDExtensionScriptInstanceFreePropertyList free_property_list_func; + GDExtensionScriptInstancePropertyCanRevert property_can_revert_func; + GDExtensionScriptInstancePropertyGetRevert property_get_revert_func; + GDExtensionScriptInstanceGetOwner get_owner_func; + GDExtensionScriptInstanceGetPropertyState get_property_state_func; + GDExtensionScriptInstanceGetMethodList get_method_list_func; + GDExtensionScriptInstanceFreeMethodList free_method_list_func; + GDExtensionScriptInstanceGetPropertyType get_property_type_func; + GDExtensionScriptInstanceHasMethod has_method_func; + GDExtensionScriptInstanceCall call_func; + GDExtensionScriptInstanceNotification notification_func; + GDExtensionScriptInstanceToString to_string_func; + GDExtensionScriptInstanceRefCountIncremented refcount_incremented_func; + GDExtensionScriptInstanceRefCountDecremented refcount_decremented_func; + GDExtensionScriptInstanceGetScript get_script_func; + GDExtensionScriptInstanceIsPlaceholder is_placeholder_func; + GDExtensionScriptInstanceSet set_fallback_func; + GDExtensionScriptInstanceGet get_fallback_func; + GDExtensionScriptInstanceGetLanguage get_language_func; + GDExtensionScriptInstanceFree free_func; +} GDExtensionScriptInstanceInfo; /* Deprecated in Godot 4.2. Use `GDExtensionScriptInstanceInfo3` instead. */ + +typedef struct { + GDExtensionScriptInstanceSet set_func; + GDExtensionScriptInstanceGet get_func; + GDExtensionScriptInstanceGetPropertyList get_property_list_func; + GDExtensionScriptInstanceFreePropertyList free_property_list_func; + /* Optional. Set to NULL for the default behavior. */ + GDExtensionScriptInstanceGetClassCategory get_class_category_func; + GDExtensionScriptInstancePropertyCanRevert property_can_revert_func; + GDExtensionScriptInstancePropertyGetRevert property_get_revert_func; + GDExtensionScriptInstanceGetOwner get_owner_func; + GDExtensionScriptInstanceGetPropertyState get_property_state_func; + GDExtensionScriptInstanceGetMethodList get_method_list_func; + GDExtensionScriptInstanceFreeMethodList free_method_list_func; + GDExtensionScriptInstanceGetPropertyType get_property_type_func; + GDExtensionScriptInstanceValidateProperty validate_property_func; + GDExtensionScriptInstanceHasMethod has_method_func; + GDExtensionScriptInstanceCall call_func; + GDExtensionScriptInstanceNotification2 notification_func; + GDExtensionScriptInstanceToString to_string_func; + GDExtensionScriptInstanceRefCountIncremented refcount_incremented_func; + GDExtensionScriptInstanceRefCountDecremented refcount_decremented_func; + GDExtensionScriptInstanceGetScript get_script_func; + GDExtensionScriptInstanceIsPlaceholder is_placeholder_func; + GDExtensionScriptInstanceSet set_fallback_func; + GDExtensionScriptInstanceGet get_fallback_func; + GDExtensionScriptInstanceGetLanguage get_language_func; + GDExtensionScriptInstanceFree free_func; +} GDExtensionScriptInstanceInfo2; /* Deprecated in Godot 4.3. Use `GDExtensionScriptInstanceInfo3` instead. */ + +typedef struct { + GDExtensionScriptInstanceSet set_func; + GDExtensionScriptInstanceGet get_func; + GDExtensionScriptInstanceGetPropertyList get_property_list_func; + GDExtensionScriptInstanceFreePropertyList2 free_property_list_func; + /* Optional. Set to NULL for the default behavior. */ + GDExtensionScriptInstanceGetClassCategory get_class_category_func; + GDExtensionScriptInstancePropertyCanRevert property_can_revert_func; + GDExtensionScriptInstancePropertyGetRevert property_get_revert_func; + GDExtensionScriptInstanceGetOwner get_owner_func; + GDExtensionScriptInstanceGetPropertyState get_property_state_func; + GDExtensionScriptInstanceGetMethodList get_method_list_func; + GDExtensionScriptInstanceFreeMethodList2 free_method_list_func; + GDExtensionScriptInstanceGetPropertyType get_property_type_func; + GDExtensionScriptInstanceValidateProperty validate_property_func; + GDExtensionScriptInstanceHasMethod has_method_func; + GDExtensionScriptInstanceGetMethodArgumentCount get_method_argument_count_func; + GDExtensionScriptInstanceCall call_func; + GDExtensionScriptInstanceNotification2 notification_func; + GDExtensionScriptInstanceToString to_string_func; + GDExtensionScriptInstanceRefCountIncremented refcount_incremented_func; + GDExtensionScriptInstanceRefCountDecremented refcount_decremented_func; + GDExtensionScriptInstanceGetScript get_script_func; + GDExtensionScriptInstanceIsPlaceholder is_placeholder_func; + GDExtensionScriptInstanceSet set_fallback_func; + GDExtensionScriptInstanceGet get_fallback_func; + GDExtensionScriptInstanceGetLanguage get_language_func; + GDExtensionScriptInstanceFree free_func; +} GDExtensionScriptInstanceInfo3; + +typedef void (*GDExtensionWorkerThreadPoolGroupTask)(void *, uint32_t); +typedef void (*GDExtensionWorkerThreadPoolTask)(void *); +typedef enum { + GDEXTENSION_INITIALIZATION_CORE = 0, + GDEXTENSION_INITIALIZATION_SERVERS = 1, + GDEXTENSION_INITIALIZATION_SCENE = 2, + GDEXTENSION_INITIALIZATION_EDITOR = 3, + GDEXTENSION_MAX_INITIALIZATION_LEVEL = 4, +} GDExtensionInitializationLevel; + +typedef void (*GDExtensionInitializeCallback)(void *p_userdata, GDExtensionInitializationLevel p_level); +typedef void (*GDExtensionDeinitializeCallback)(void *p_userdata, GDExtensionInitializationLevel p_level); +typedef struct { + /* Minimum initialization level required. + * If Core or Servers, the extension needs editor or game restart to take effect + */ + GDExtensionInitializationLevel minimum_initialization_level; + /* Up to the user to supply when initializing */ + void *userdata; + /* This function will be called multiple times for each initialization level. */ + GDExtensionInitializeCallback initialize; + GDExtensionDeinitializeCallback deinitialize; +} GDExtensionInitialization; + +typedef void (*GDExtensionInterfaceFunctionPtr)(); +typedef GDExtensionInterfaceFunctionPtr (*GDExtensionInterfaceGetProcAddress)(const char *p_function_name); +/* Each GDExtension should define a C function that matches the signature of GDExtensionInitializationFunction, + * and export it so that it can be loaded via dlopen() or equivalent for the given platform. + * + * For example: + * + * GDExtensionBool my_extension_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization); + * + * This function's name must be specified as the 'entry_symbol' in the .gdextension file. + * + * This makes it the entry point of the GDExtension and will be called on initialization. + * + * The GDExtension can then modify the r_initialization structure, setting the minimum initialization level, + * and providing pointers to functions that will be called at various stages of initialization/shutdown. + * + * The rest of the GDExtension's interface to Godot consists of function pointers that can be loaded + * by calling p_get_proc_address("...") with the name of the function. + * + * For example: + * + * GDExtensionInterfaceGetGodotVersion get_godot_version = (GDExtensionInterfaceGetGodotVersion)p_get_proc_address("get_godot_version"); + * + * (Note that snippet may cause "cast between incompatible function types" on some compilers, you can + * silence this by adding an intermediary `void*` cast.) + * + * You can then call it like a normal function: + * + * GDExtensionGodotVersion godot_version; + * get_godot_version(&godot_version); + * printf("Godot v%d.%d.%d\n", godot_version.major, godot_version.minor, godot_version.patch); + * + * All of these interface functions are described below, together with the name that's used to load it, + * and the function pointer typedef that shows its signature. + */ +typedef GDExtensionBool (*GDExtensionInitializationFunction)(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization); +typedef struct { + uint32_t major; + uint32_t minor; + uint32_t patch; + const char *string; +} GDExtensionGodotVersion; + +typedef struct { + uint32_t major; + uint32_t minor; + uint32_t patch; + /* Full version encoded as hexadecimal with one byte (2 hex digits) per number (e.g. for "3.1.12" it would be 0x03010C) */ + uint32_t hex; + /* (e.g. "stable", "beta", "rc1", "rc2") */ + const char *status; + /* (e.g. "custom_build") */ + const char *build; + /* Full Git commit hash. */ + const char *hash; + /* Git commit date UNIX timestamp in seconds, or 0 if unavailable. */ + uint64_t timestamp; + /* (e.g. "Godot v3.1.4.stable.official.mono") */ + const char *string; +} GDExtensionGodotVersion2; + +/* Called when starting the main loop. */ +typedef void (*GDExtensionMainLoopStartupCallback)(); +/* Called when shutting down the main loop. */ +typedef void (*GDExtensionMainLoopShutdownCallback)(); +/* Called for every frame iteration of the main loop. */ +typedef void (*GDExtensionMainLoopFrameCallback)(); +typedef struct { + /* Will be called after Godot is started and is fully initialized. */ + GDExtensionMainLoopStartupCallback startup_func; + /* Will be called before Godot is shutdown when it is still fully initialized. */ + GDExtensionMainLoopShutdownCallback shutdown_func; + /* Will be called for each process frame. This will run after all `_process()` methods on Node, and before `ScriptServer::frame()`. + * This is intended to be the equivalent of `ScriptLanguage::frame()` for GDExtension language bindings that don't use the script API. + */ + GDExtensionMainLoopFrameCallback frame_func; +} GDExtensionMainLoopCallbacks; + +/** + * @name get_godot_version + * @since 4.1 + * @deprecated Deprecated in Godot 4.5. Use `get_godot_version2` instead. + * + * Gets the Godot version that the GDExtension was loaded into. + * + * @param r_godot_version A pointer to the structure to write the version information into. + */ +typedef void (*GDExtensionInterfaceGetGodotVersion)(GDExtensionGodotVersion *r_godot_version); + +/** + * @name get_godot_version2 + * @since 4.5 + * + * Gets the Godot version that the GDExtension was loaded into. + * + * @param r_godot_version A pointer to the structure to write the version information into. + */ +typedef void (*GDExtensionInterfaceGetGodotVersion2)(GDExtensionGodotVersion2 *r_godot_version); + +/** + * @name mem_alloc + * @since 4.1 + * @deprecated Deprecated in Godot 4.6. Does not allow explicitly requesting padding. Use `mem_alloc2` instead. + * + * Allocates memory. + * + * @param p_bytes The amount of memory to allocate in bytes. + * + * @return A pointer to the allocated memory, or NULL if unsuccessful. + */ +typedef void *(*GDExtensionInterfaceMemAlloc)(size_t p_bytes); + +/** + * @name mem_realloc + * @since 4.1 + * @deprecated Deprecated in Godot 4.6. Does not allow explicitly requesting padding. Use `mem_realloc2` instead. + * + * Reallocates memory. + * + * @param p_ptr A pointer to the previously allocated memory. + * @param p_bytes The number of bytes to resize the memory block to. + * + * @return A pointer to the allocated memory, or NULL if unsuccessful. + */ +typedef void *(*GDExtensionInterfaceMemRealloc)(void *p_ptr, size_t p_bytes); + +/** + * @name mem_free + * @since 4.1 + * @deprecated Deprecated in Godot 4.6. Does not allow explicitly requesting padding. Use `mem_free2` instead. + * + * Frees memory. + * + * @param p_ptr A pointer to the previously allocated memory. + */ +typedef void (*GDExtensionInterfaceMemFree)(void *p_ptr); + +/** + * @name mem_alloc2 + * @since 4.6 + * + * Allocates memory. + * + * @param p_bytes The amount of memory to allocate in bytes. + * @param p_pad_align If true, the returned memory will have prepadding of at least 8 bytes. + * + * @return A pointer to the allocated memory, or NULL if unsuccessful. + */ +typedef void *(*GDExtensionInterfaceMemAlloc2)(size_t p_bytes, GDExtensionBool p_pad_align); + +/** + * @name mem_realloc2 + * @since 4.6 + * + * Reallocates memory. + * + * @param p_ptr A pointer to the previously allocated memory. + * @param p_bytes The number of bytes to resize the memory block to. + * @param p_pad_align If true, the returned memory will have prepadding of at least 8 bytes. + * + * @return A pointer to the allocated memory, or NULL if unsuccessful. + */ +typedef void *(*GDExtensionInterfaceMemRealloc2)(void *p_ptr, size_t p_bytes, GDExtensionBool p_pad_align); + +/** + * @name mem_free2 + * @since 4.6 + * + * Frees memory. + * + * @param p_ptr A pointer to the previously allocated memory. + * @param p_pad_align If true, the given memory was allocated with prepadding. + */ +typedef void (*GDExtensionInterfaceMemFree2)(void *p_ptr, GDExtensionBool p_pad_align); + +/** + * @name print_error + * @since 4.1 + * + * Logs an error to Godot's built-in debugger and to the OS terminal. + * + * @param p_description The code triggering the error. + * @param p_function The function name where the error occurred. + * @param p_file The file where the error occurred. + * @param p_line The line where the error occurred. + * @param p_editor_notify Whether or not to notify the editor. + */ +typedef void (*GDExtensionInterfacePrintError)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify); + +/** + * @name print_error_with_message + * @since 4.1 + * + * Logs an error with a message to Godot's built-in debugger and to the OS terminal. + * + * @param p_description The code triggering the error. + * @param p_message The message to show along with the error. + * @param p_function The function name where the error occurred. + * @param p_file The file where the error occurred. + * @param p_line The line where the error occurred. + * @param p_editor_notify Whether or not to notify the editor. + */ +typedef void (*GDExtensionInterfacePrintErrorWithMessage)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify); + +/** + * @name print_warning + * @since 4.1 + * + * Logs a warning to Godot's built-in debugger and to the OS terminal. + * + * @param p_description The code triggering the warning. + * @param p_function The function name where the warning occurred. + * @param p_file The file where the warning occurred. + * @param p_line The line where the warning occurred. + * @param p_editor_notify Whether or not to notify the editor. + */ +typedef void (*GDExtensionInterfacePrintWarning)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify); + +/** + * @name print_warning_with_message + * @since 4.1 + * + * Logs a warning with a message to Godot's built-in debugger and to the OS terminal. + * + * @param p_description The code triggering the warning. + * @param p_message The message to show along with the warning. + * @param p_function The function name where the warning occurred. + * @param p_file The file where the warning occurred. + * @param p_line The line where the warning occurred. + * @param p_editor_notify Whether or not to notify the editor. + */ +typedef void (*GDExtensionInterfacePrintWarningWithMessage)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify); + +/** + * @name print_script_error + * @since 4.1 + * + * Logs a script error to Godot's built-in debugger and to the OS terminal. + * + * @param p_description The code triggering the error. + * @param p_function The function name where the error occurred. + * @param p_file The file where the error occurred. + * @param p_line The line where the error occurred. + * @param p_editor_notify Whether or not to notify the editor. + */ +typedef void (*GDExtensionInterfacePrintScriptError)(const char *p_description, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify); + +/** + * @name print_script_error_with_message + * @since 4.1 + * + * Logs a script error with a message to Godot's built-in debugger and to the OS terminal. + * + * @param p_description The code triggering the error. + * @param p_message The message to show along with the error. + * @param p_function The function name where the error occurred. + * @param p_file The file where the error occurred. + * @param p_line The line where the error occurred. + * @param p_editor_notify Whether or not to notify the editor. + */ +typedef void (*GDExtensionInterfacePrintScriptErrorWithMessage)(const char *p_description, const char *p_message, const char *p_function, const char *p_file, int32_t p_line, GDExtensionBool p_editor_notify); + +/** + * @name get_native_struct_size + * @since 4.1 + * + * Gets the size of a native struct (ex. ObjectID) in bytes. + * + * @param p_name A pointer to a StringName identifying the struct name. + * + * @return The size in bytes. + */ +typedef uint64_t (*GDExtensionInterfaceGetNativeStructSize)(GDExtensionConstStringNamePtr p_name); + +/** + * @name variant_new_copy + * @since 4.1 + * + * Copies one Variant into a another. + * + * @param r_dest A pointer to the destination Variant. + * @param p_src A pointer to the source Variant. + */ +typedef void (*GDExtensionInterfaceVariantNewCopy)(GDExtensionUninitializedVariantPtr r_dest, GDExtensionConstVariantPtr p_src); + +/** + * @name variant_new_nil + * @since 4.1 + * + * Creates a new Variant containing nil. + * + * @param r_dest A pointer to the destination Variant. + */ +typedef void (*GDExtensionInterfaceVariantNewNil)(GDExtensionUninitializedVariantPtr r_dest); + +/** + * @name variant_destroy + * @since 4.1 + * + * Destroys a Variant. + * + * @param p_self A pointer to the Variant to destroy. + */ +typedef void (*GDExtensionInterfaceVariantDestroy)(GDExtensionVariantPtr p_self); + +/** + * @name variant_call + * @since 4.1 + * + * Calls a method on a Variant. + * + * @param p_self A pointer to the Variant. + * @param p_method A pointer to a StringName identifying the method. + * @param p_args A pointer to a C array of Variant. + * @param p_argument_count The number of arguments. + * @param r_return A pointer a Variant which will be assigned the return value. + * @param r_error A pointer the structure which will hold error information. + * + * @see Variant::callp() + */ +typedef void (*GDExtensionInterfaceVariantCall)(GDExtensionVariantPtr p_self, GDExtensionConstStringNamePtr p_method, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionUninitializedVariantPtr r_return, GDExtensionCallError *r_error); + +/** + * @name variant_call_static + * @since 4.1 + * + * Calls a static method on a Variant. + * + * @param p_type The variant type. + * @param p_method A pointer to a StringName identifying the method. + * @param p_args A pointer to a C array of Variant. + * @param p_argument_count The number of arguments. + * @param r_return A pointer a Variant which will be assigned the return value. + * @param r_error A pointer the structure which will be updated with error information. + * + * @see Variant::call_static() + */ +typedef void (*GDExtensionInterfaceVariantCallStatic)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_method, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionUninitializedVariantPtr r_return, GDExtensionCallError *r_error); + +/** + * @name variant_evaluate + * @since 4.1 + * + * Evaluate an operator on two Variants. + * + * @param p_op The operator to evaluate. + * @param p_a The first Variant. + * @param p_b The second Variant. + * @param r_return A pointer a Variant which will be assigned the return value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @see Variant::evaluate() + */ +typedef void (*GDExtensionInterfaceVariantEvaluate)(GDExtensionVariantOperator p_op, GDExtensionConstVariantPtr p_a, GDExtensionConstVariantPtr p_b, GDExtensionUninitializedVariantPtr r_return, GDExtensionBool *r_valid); + +/** + * @name variant_set + * @since 4.1 + * + * Sets a key on a Variant to a value. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a Variant representing the key. + * @param p_value A pointer to a Variant representing the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @see Variant::set() + */ +typedef void (*GDExtensionInterfaceVariantSet)(GDExtensionVariantPtr p_self, GDExtensionConstVariantPtr p_key, GDExtensionConstVariantPtr p_value, GDExtensionBool *r_valid); + +/** + * @name variant_set_named + * @since 4.1 + * + * Sets a named key on a Variant to a value. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a StringName representing the key. + * @param p_value A pointer to a Variant representing the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @see Variant::set_named() + */ +typedef void (*GDExtensionInterfaceVariantSetNamed)(GDExtensionVariantPtr p_self, GDExtensionConstStringNamePtr p_key, GDExtensionConstVariantPtr p_value, GDExtensionBool *r_valid); + +/** + * @name variant_set_keyed + * @since 4.1 + * + * Sets a keyed property on a Variant to a value. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a Variant representing the key. + * @param p_value A pointer to a Variant representing the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @see Variant::set_keyed() + */ +typedef void (*GDExtensionInterfaceVariantSetKeyed)(GDExtensionVariantPtr p_self, GDExtensionConstVariantPtr p_key, GDExtensionConstVariantPtr p_value, GDExtensionBool *r_valid); + +/** + * @name variant_set_indexed + * @since 4.1 + * + * Sets an index on a Variant to a value. + * + * @param p_self A pointer to the Variant. + * @param p_index The index. + * @param p_value A pointer to a Variant representing the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * @param r_oob A pointer to a boolean which will be set to true if the index is out of bounds. + */ +typedef void (*GDExtensionInterfaceVariantSetIndexed)(GDExtensionVariantPtr p_self, GDExtensionInt p_index, GDExtensionConstVariantPtr p_value, GDExtensionBool *r_valid, GDExtensionBool *r_oob); + +/** + * @name variant_get + * @since 4.1 + * + * Gets the value of a key from a Variant. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a Variant representing the key. + * @param r_ret A pointer to a Variant which will be assigned the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + */ +typedef void (*GDExtensionInterfaceVariantGet)(GDExtensionConstVariantPtr p_self, GDExtensionConstVariantPtr p_key, GDExtensionUninitializedVariantPtr r_ret, GDExtensionBool *r_valid); + +/** + * @name variant_get_named + * @since 4.1 + * + * Gets the value of a named key from a Variant. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a StringName representing the key. + * @param r_ret A pointer to a Variant which will be assigned the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + */ +typedef void (*GDExtensionInterfaceVariantGetNamed)(GDExtensionConstVariantPtr p_self, GDExtensionConstStringNamePtr p_key, GDExtensionUninitializedVariantPtr r_ret, GDExtensionBool *r_valid); + +/** + * @name variant_get_keyed + * @since 4.1 + * + * Gets the value of a keyed property from a Variant. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a Variant representing the key. + * @param r_ret A pointer to a Variant which will be assigned the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + */ +typedef void (*GDExtensionInterfaceVariantGetKeyed)(GDExtensionConstVariantPtr p_self, GDExtensionConstVariantPtr p_key, GDExtensionUninitializedVariantPtr r_ret, GDExtensionBool *r_valid); + +/** + * @name variant_get_indexed + * @since 4.1 + * + * Gets the value of an index from a Variant. + * + * @param p_self A pointer to the Variant. + * @param p_index The index. + * @param r_ret A pointer to a Variant which will be assigned the value. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * @param r_oob A pointer to a boolean which will be set to true if the index is out of bounds. + */ +typedef void (*GDExtensionInterfaceVariantGetIndexed)(GDExtensionConstVariantPtr p_self, GDExtensionInt p_index, GDExtensionUninitializedVariantPtr r_ret, GDExtensionBool *r_valid, GDExtensionBool *r_oob); + +/** + * @name variant_iter_init + * @since 4.1 + * + * Initializes an iterator over a Variant. + * + * @param p_self A pointer to the Variant. + * @param r_iter A pointer to a Variant which will be assigned the iterator. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @return true if the operation is valid; otherwise false. + * + * @see Variant::iter_init() + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantIterInit)(GDExtensionConstVariantPtr p_self, GDExtensionUninitializedVariantPtr r_iter, GDExtensionBool *r_valid); + +/** + * @name variant_iter_next + * @since 4.1 + * + * Gets the next value for an iterator over a Variant. + * + * @param p_self A pointer to the Variant. + * @param r_iter A pointer to a Variant which will be assigned the iterator. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @return true if the operation is valid; otherwise false. + * + * @see Variant::iter_next() + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantIterNext)(GDExtensionConstVariantPtr p_self, GDExtensionVariantPtr r_iter, GDExtensionBool *r_valid); + +/** + * @name variant_iter_get + * @since 4.1 + * + * Gets the next value for an iterator over a Variant. + * + * @param p_self A pointer to the Variant. + * @param r_iter A pointer to a Variant which will be assigned the iterator. + * @param r_ret A pointer to a Variant which will be assigned false if the operation is invalid. + * @param r_valid A pointer to a boolean which will be set to false if the operation is invalid. + * + * @see Variant::iter_get() + */ +typedef void (*GDExtensionInterfaceVariantIterGet)(GDExtensionConstVariantPtr p_self, GDExtensionVariantPtr r_iter, GDExtensionUninitializedVariantPtr r_ret, GDExtensionBool *r_valid); + +/** + * @name variant_hash + * @since 4.1 + * + * Gets the hash of a Variant. + * + * @param p_self A pointer to the Variant. + * + * @return The hash value. + * + * @see Variant::hash() + */ +typedef GDExtensionInt (*GDExtensionInterfaceVariantHash)(GDExtensionConstVariantPtr p_self); + +/** + * @name variant_recursive_hash + * @since 4.1 + * + * Gets the recursive hash of a Variant. + * + * @param p_self A pointer to the Variant. + * @param p_recursion_count The number of recursive loops so far. + * + * @return The hash value. + * + * @see Variant::recursive_hash() + */ +typedef GDExtensionInt (*GDExtensionInterfaceVariantRecursiveHash)(GDExtensionConstVariantPtr p_self, GDExtensionInt p_recursion_count); + +/** + * @name variant_hash_compare + * @since 4.1 + * + * Compares two Variants by their hash. + * + * @param p_self A pointer to the Variant. + * @param p_other A pointer to the other Variant to compare it to. + * + * @return The hash value. + * + * @see Variant::hash_compare() + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantHashCompare)(GDExtensionConstVariantPtr p_self, GDExtensionConstVariantPtr p_other); + +/** + * @name variant_booleanize + * @since 4.1 + * + * Converts a Variant to a boolean. + * + * @param p_self A pointer to the Variant. + * + * @return The boolean value of the Variant. + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantBooleanize)(GDExtensionConstVariantPtr p_self); + +/** + * @name variant_duplicate + * @since 4.1 + * + * Duplicates a Variant. + * + * @param p_self A pointer to the Variant. + * @param r_ret A pointer to a Variant to store the duplicated value. + * @param p_deep Whether or not to duplicate deeply (when supported by the Variant type). + */ +typedef void (*GDExtensionInterfaceVariantDuplicate)(GDExtensionConstVariantPtr p_self, GDExtensionVariantPtr r_ret, GDExtensionBool p_deep); + +/** + * @name variant_stringify + * @since 4.1 + * + * Converts a Variant to a string. + * + * @param p_self A pointer to the Variant. + * @param r_ret A pointer to a String to store the resulting value. + */ +typedef void (*GDExtensionInterfaceVariantStringify)(GDExtensionConstVariantPtr p_self, GDExtensionStringPtr r_ret); + +/** + * @name variant_get_type + * @since 4.1 + * + * Gets the type of a Variant. + * + * @param p_self A pointer to the Variant. + * + * @return The variant type. + */ +typedef GDExtensionVariantType (*GDExtensionInterfaceVariantGetType)(GDExtensionConstVariantPtr p_self); + +/** + * @name variant_has_method + * @since 4.1 + * + * Checks if a Variant has the given method. + * + * @param p_self A pointer to the Variant. + * @param p_method A pointer to a StringName with the method name. + * + * @return true if the variant has the given method; otherwise false. + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantHasMethod)(GDExtensionConstVariantPtr p_self, GDExtensionConstStringNamePtr p_method); + +/** + * @name variant_has_member + * @since 4.1 + * + * Checks if a type of Variant has the given member. + * + * @param p_type The Variant type. + * @param p_member A pointer to a StringName with the member name. + * + * @return true if the variant has the given method; otherwise false. + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantHasMember)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_member); + +/** + * @name variant_has_key + * @since 4.1 + * + * Checks if a Variant has a key. + * + * @param p_self A pointer to the Variant. + * @param p_key A pointer to a Variant representing the key. + * @param r_valid A pointer to a boolean which will be set to false if the key doesn't exist. + * + * @return true if the key exists; otherwise false. + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantHasKey)(GDExtensionConstVariantPtr p_self, GDExtensionConstVariantPtr p_key, GDExtensionBool *r_valid); + +/** + * @name variant_get_object_instance_id + * @since 4.4 + * + * Gets the object instance ID from a variant of type GDEXTENSION_VARIANT_TYPE_OBJECT. + * + * If the variant isn't of type GDEXTENSION_VARIANT_TYPE_OBJECT, then zero will be returned. + * The instance ID will be returned even if the object is no longer valid - use `object_get_instance_by_id()` to check if the object is still valid. + * + * @param p_self A pointer to the Variant. + * + * @return The instance ID for the contained object. + */ +typedef GDObjectInstanceID (*GDExtensionInterfaceVariantGetObjectInstanceId)(GDExtensionConstVariantPtr p_self); + +/** + * @name variant_get_type_name + * @since 4.1 + * + * Gets the name of a Variant type. + * + * @param p_type The Variant type. + * @param r_name A pointer to a String to store the Variant type name. + */ +typedef void (*GDExtensionInterfaceVariantGetTypeName)(GDExtensionVariantType p_type, GDExtensionUninitializedStringPtr r_name); + +/** + * @name variant_can_convert + * @since 4.1 + * + * Checks if Variants can be converted from one type to another. + * + * @param p_from The Variant type to convert from. + * @param p_to The Variant type to convert to. + * + * @return true if the conversion is possible; otherwise false. + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantCanConvert)(GDExtensionVariantType p_from, GDExtensionVariantType p_to); + +/** + * @name variant_can_convert_strict + * @since 4.1 + * + * Checks if Variant can be converted from one type to another using stricter rules. + * + * @param p_from The Variant type to convert from. + * @param p_to The Variant type to convert to. + * + * @return true if the conversion is possible; otherwise false. + */ +typedef GDExtensionBool (*GDExtensionInterfaceVariantCanConvertStrict)(GDExtensionVariantType p_from, GDExtensionVariantType p_to); + +/** + * @name get_variant_from_type_constructor + * @since 4.1 + * + * Gets a pointer to a function that can create a Variant of the given type from a raw value. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can create a Variant of the given type from a raw value. + */ +typedef GDExtensionVariantFromTypeConstructorFunc (*GDExtensionInterfaceGetVariantFromTypeConstructor)(GDExtensionVariantType p_type); + +/** + * @name get_variant_to_type_constructor + * @since 4.1 + * + * Gets a pointer to a function that can get the raw value from a Variant of the given type. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can get the raw value from a Variant of the given type. + */ +typedef GDExtensionTypeFromVariantConstructorFunc (*GDExtensionInterfaceGetVariantToTypeConstructor)(GDExtensionVariantType p_type); + +/** + * @name variant_get_ptr_internal_getter + * @since 4.4 + * + * Provides a function pointer for retrieving a pointer to a variant's internal value. + * + * Access to a variant's internal value can be used to modify it in-place, or to retrieve its value without the overhead of variant conversion functions. + * It is recommended to cache the getter for all variant types in a function table to avoid retrieval overhead upon use. + * + * Each function assumes the variant's type has already been determined and matches the function. + * Invoking the function with a variant of a mismatched type has undefined behavior, and may lead to a segmentation fault. + * + * @param p_type The Variant type. + * + * @return A pointer to a type-specific function that returns a pointer to the internal value of a variant. Check the implementation of this function (gdextension_variant_get_ptr_internal_getter) for pointee type info of each variant type. + */ +typedef GDExtensionVariantGetInternalPtrFunc (*GDExtensionInterfaceGetVariantGetInternalPtrFunc)(GDExtensionVariantType p_type); + +/** + * @name variant_get_ptr_operator_evaluator + * @since 4.1 + * + * Gets a pointer to a function that can evaluate the given Variant operator on the given Variant types. + * + * @param p_operator The variant operator. + * @param p_type_a The type of the first Variant. + * @param p_type_b The type of the second Variant. + * + * @return A pointer to a function that can evaluate the given Variant operator on the given Variant types. + */ +typedef GDExtensionPtrOperatorEvaluator (*GDExtensionInterfaceVariantGetPtrOperatorEvaluator)(GDExtensionVariantOperator p_operator, GDExtensionVariantType p_type_a, GDExtensionVariantType p_type_b); + +/** + * @name variant_get_ptr_builtin_method + * @since 4.1 + * + * Gets a pointer to a function that can call a builtin method on a type of Variant. + * + * @param p_type The Variant type. + * @param p_method A pointer to a StringName with the method name. + * @param p_hash A hash representing the method signature. + * + * @return A pointer to a function that can call a builtin method on a type of Variant. + */ +typedef GDExtensionPtrBuiltInMethod (*GDExtensionInterfaceVariantGetPtrBuiltinMethod)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_method, GDExtensionInt p_hash); + +/** + * @name variant_get_ptr_constructor + * @since 4.1 + * + * Gets a pointer to a function that can call one of the constructors for a type of Variant. + * + * @param p_type The Variant type. + * @param p_constructor The index of the constructor. + * + * @return A pointer to a function that can call one of the constructors for a type of Variant. + */ +typedef GDExtensionPtrConstructor (*GDExtensionInterfaceVariantGetPtrConstructor)(GDExtensionVariantType p_type, int32_t p_constructor); + +/** + * @name variant_get_ptr_destructor + * @since 4.1 + * + * Gets a pointer to a function than can call the destructor for a type of Variant. + * + * @param p_type The Variant type. + * + * @return A pointer to a function than can call the destructor for a type of Variant. + */ +typedef GDExtensionPtrDestructor (*GDExtensionInterfaceVariantGetPtrDestructor)(GDExtensionVariantType p_type); + +/** + * @name variant_construct + * @since 4.1 + * + * Constructs a Variant of the given type, using the first constructor that matches the given arguments. + * + * @param p_type The Variant type. + * @param r_base A pointer to a Variant to store the constructed value. + * @param p_args A pointer to a C array of Variant pointers representing the arguments for the constructor. + * @param p_argument_count The number of arguments to pass to the constructor. + * @param r_error A pointer the structure which will be updated with error information. + */ +typedef void (*GDExtensionInterfaceVariantConstruct)(GDExtensionVariantType p_type, GDExtensionUninitializedVariantPtr r_base, const GDExtensionConstVariantPtr *p_args, int32_t p_argument_count, GDExtensionCallError *r_error); + +/** + * @name variant_get_ptr_setter + * @since 4.1 + * + * Gets a pointer to a function that can call a member's setter on the given Variant type. + * + * @param p_type The Variant type. + * @param p_member A pointer to a StringName with the member name. + * + * @return A pointer to a function that can call a member's setter on the given Variant type. + */ +typedef GDExtensionPtrSetter (*GDExtensionInterfaceVariantGetPtrSetter)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_member); + +/** + * @name variant_get_ptr_getter + * @since 4.1 + * + * Gets a pointer to a function that can call a member's getter on the given Variant type. + * + * @param p_type The Variant type. + * @param p_member A pointer to a StringName with the member name. + * + * @return A pointer to a function that can call a member's getter on the given Variant type. + */ +typedef GDExtensionPtrGetter (*GDExtensionInterfaceVariantGetPtrGetter)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_member); + +/** + * @name variant_get_ptr_indexed_setter + * @since 4.1 + * + * Gets a pointer to a function that can set an index on the given Variant type. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can set an index on the given Variant type. + */ +typedef GDExtensionPtrIndexedSetter (*GDExtensionInterfaceVariantGetPtrIndexedSetter)(GDExtensionVariantType p_type); + +/** + * @name variant_get_ptr_indexed_getter + * @since 4.1 + * + * Gets a pointer to a function that can get an index on the given Variant type. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can get an index on the given Variant type. + */ +typedef GDExtensionPtrIndexedGetter (*GDExtensionInterfaceVariantGetPtrIndexedGetter)(GDExtensionVariantType p_type); + +/** + * @name variant_get_ptr_keyed_setter + * @since 4.1 + * + * Gets a pointer to a function that can set a key on the given Variant type. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can set a key on the given Variant type. + */ +typedef GDExtensionPtrKeyedSetter (*GDExtensionInterfaceVariantGetPtrKeyedSetter)(GDExtensionVariantType p_type); + +/** + * @name variant_get_ptr_keyed_getter + * @since 4.1 + * + * Gets a pointer to a function that can get a key on the given Variant type. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can get a key on the given Variant type. + */ +typedef GDExtensionPtrKeyedGetter (*GDExtensionInterfaceVariantGetPtrKeyedGetter)(GDExtensionVariantType p_type); + +/** + * @name variant_get_ptr_keyed_checker + * @since 4.1 + * + * Gets a pointer to a function that can check a key on the given Variant type. + * + * @param p_type The Variant type. + * + * @return A pointer to a function that can check a key on the given Variant type. + */ +typedef GDExtensionPtrKeyedChecker (*GDExtensionInterfaceVariantGetPtrKeyedChecker)(GDExtensionVariantType p_type); + +/** + * @name variant_get_constant_value + * @since 4.1 + * + * Gets the value of a constant from the given Variant type. + * + * @param p_type The Variant type. + * @param p_constant A pointer to a StringName with the constant name. + * @param r_ret A pointer to a Variant to store the value. + */ +typedef void (*GDExtensionInterfaceVariantGetConstantValue)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_constant, GDExtensionUninitializedVariantPtr r_ret); + +/** + * @name variant_get_ptr_utility_function + * @since 4.1 + * + * Gets a pointer to a function that can call a Variant utility function. + * + * @param p_function A pointer to a StringName with the function name. + * @param p_hash A hash representing the function signature. + * + * @return A pointer to a function that can call a Variant utility function. + */ +typedef GDExtensionPtrUtilityFunction (*GDExtensionInterfaceVariantGetPtrUtilityFunction)(GDExtensionConstStringNamePtr p_function, GDExtensionInt p_hash); + +/** + * @name string_new_with_latin1_chars + * @since 4.1 + * + * Creates a String from a Latin-1 encoded C string. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a Latin-1 encoded C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringNewWithLatin1Chars)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents); + +/** + * @name string_new_with_utf8_chars + * @since 4.1 + * + * Creates a String from a UTF-8 encoded C string. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-8 encoded C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringNewWithUtf8Chars)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents); + +/** + * @name string_new_with_utf16_chars + * @since 4.1 + * + * Creates a String from a UTF-16 encoded C string. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-16 encoded C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringNewWithUtf16Chars)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents); + +/** + * @name string_new_with_utf32_chars + * @since 4.1 + * + * Creates a String from a UTF-32 encoded C string. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-32 encoded C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringNewWithUtf32Chars)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents); + +/** + * @name string_new_with_wide_chars + * @since 4.1 + * + * Creates a String from a wide C string. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a wide C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringNewWithWideChars)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents); + +/** + * @name string_new_with_latin1_chars_and_len + * @since 4.1 + * + * Creates a String from a Latin-1 encoded C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a Latin-1 encoded C string. + * @param p_size The number of characters (= number of bytes). + */ +typedef void (*GDExtensionInterfaceStringNewWithLatin1CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size); + +/** + * @name string_new_with_utf8_chars_and_len + * @since 4.1 + * @deprecated Deprecated in Godot 4.3. Use `string_new_with_utf8_chars_and_len2` instead. + * + * Creates a String from a UTF-8 encoded C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-8 encoded C string. + * @param p_size The number of bytes (not code units). + */ +typedef void (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size); + +/** + * @name string_new_with_utf8_chars_and_len2 + * @since 4.3 + * + * Creates a String from a UTF-8 encoded C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-8 encoded C string. + * @param p_size The number of bytes (not code units). + * + * @return Error code signifying if the operation successful. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen2)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size); + +/** + * @name string_new_with_utf16_chars_and_len + * @since 4.1 + * @deprecated Deprecated in Godot 4.3. Use `string_new_with_utf16_chars_and_len2` instead. + * + * Creates a String from a UTF-16 encoded C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-16 encoded C string. + * @param p_char_count The number of characters (not bytes). + */ +typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count); + +/** + * @name string_new_with_utf16_chars_and_len2 + * @since 4.3 + * + * Creates a String from a UTF-16 encoded C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-16 encoded C string. + * @param p_char_count The number of characters (not bytes). + * @param p_default_little_endian If true, UTF-16 use little endian. + * + * @return Error code signifying if the operation successful. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen2)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count, GDExtensionBool p_default_little_endian); + +/** + * @name string_new_with_utf32_chars_and_len + * @since 4.1 + * + * Creates a String from a UTF-32 encoded C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a UTF-32 encoded C string. + * @param p_char_count The number of characters (not bytes). + */ +typedef void (*GDExtensionInterfaceStringNewWithUtf32CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_char_count); + +/** + * @name string_new_with_wide_chars_and_len + * @since 4.1 + * + * Creates a String from a wide C string with the given length. + * + * @param r_dest A pointer to a Variant to hold the newly created String. + * @param p_contents A pointer to a wide C string. + * @param p_char_count The number of characters (not bytes). + */ +typedef void (*GDExtensionInterfaceStringNewWithWideCharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_char_count); + +/** + * @name string_to_latin1_chars + * @since 4.1 + * + * Converts a String to a Latin-1 encoded C string. + * + * It doesn't write a null terminator. + * + * @param p_self A pointer to the String. + * @param r_text A pointer to the buffer to hold the resulting data. If NULL is passed in, only the length will be computed. + * @param p_max_write_length The maximum number of characters that can be written to r_text. It has no affect on the return value. + * + * @return The resulting encoded string length in characters (not bytes), not including a null terminator. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringToLatin1Chars)(GDExtensionConstStringPtr p_self, char *r_text, GDExtensionInt p_max_write_length); + +/** + * @name string_to_utf8_chars + * @since 4.1 + * + * Converts a String to a UTF-8 encoded C string. + * + * It doesn't write a null terminator. + * + * @param p_self A pointer to the String. + * @param r_text A pointer to the buffer to hold the resulting data. If NULL is passed in, only the length will be computed. + * @param p_max_write_length The maximum number of characters that can be written to r_text. It has no affect on the return value. + * + * @return The resulting encoded string length in characters (not bytes), not including a null terminator. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringToUtf8Chars)(GDExtensionConstStringPtr p_self, char *r_text, GDExtensionInt p_max_write_length); + +/** + * @name string_to_utf16_chars + * @since 4.1 + * + * Converts a String to a UTF-16 encoded C string. + * + * It doesn't write a null terminator. + * + * @param p_self A pointer to the String. + * @param r_text A pointer to the buffer to hold the resulting data. If NULL is passed in, only the length will be computed. + * @param p_max_write_length The maximum number of characters that can be written to r_text. It has no affect on the return value. + * + * @return The resulting encoded string length in characters (not bytes), not including a null terminator. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringToUtf16Chars)(GDExtensionConstStringPtr p_self, char16_t *r_text, GDExtensionInt p_max_write_length); + +/** + * @name string_to_utf32_chars + * @since 4.1 + * + * Converts a String to a UTF-32 encoded C string. + * + * It doesn't write a null terminator. + * + * @param p_self A pointer to the String. + * @param r_text A pointer to the buffer to hold the resulting data. If NULL is passed in, only the length will be computed. + * @param p_max_write_length The maximum number of characters that can be written to r_text. It has no affect on the return value. + * + * @return The resulting encoded string length in characters (not bytes), not including a null terminator. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringToUtf32Chars)(GDExtensionConstStringPtr p_self, char32_t *r_text, GDExtensionInt p_max_write_length); + +/** + * @name string_to_wide_chars + * @since 4.1 + * + * Converts a String to a wide C string. + * + * It doesn't write a null terminator. + * + * @param p_self A pointer to the String. + * @param r_text A pointer to the buffer to hold the resulting data. If NULL is passed in, only the length will be computed. + * @param p_max_write_length The maximum number of characters that can be written to r_text. It has no affect on the return value. + * + * @return The resulting encoded string length in characters (not bytes), not including a null terminator. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringToWideChars)(GDExtensionConstStringPtr p_self, wchar_t *r_text, GDExtensionInt p_max_write_length); + +/** + * @name string_operator_index + * @since 4.1 + * + * Gets a pointer to the character at the given index from a String. + * + * @param p_self A pointer to the String. + * @param p_index The index. + * + * @return A pointer to the requested character. + */ +typedef char32_t *(*GDExtensionInterfaceStringOperatorIndex)(GDExtensionStringPtr p_self, GDExtensionInt p_index); + +/** + * @name string_operator_index_const + * @since 4.1 + * + * Gets a const pointer to the character at the given index from a String. + * + * @param p_self A pointer to the String. + * @param p_index The index. + * + * @return A const pointer to the requested character. + */ +typedef const char32_t *(*GDExtensionInterfaceStringOperatorIndexConst)(GDExtensionConstStringPtr p_self, GDExtensionInt p_index); + +/** + * @name string_operator_plus_eq_string + * @since 4.1 + * + * Appends another String to a String. + * + * @param p_self A pointer to the String. + * @param p_b A pointer to the other String to append. + */ +typedef void (*GDExtensionInterfaceStringOperatorPlusEqString)(GDExtensionStringPtr p_self, GDExtensionConstStringPtr p_b); + +/** + * @name string_operator_plus_eq_char + * @since 4.1 + * + * Appends a character to a String. + * + * @param p_self A pointer to the String. + * @param p_b A pointer to the character to append. + */ +typedef void (*GDExtensionInterfaceStringOperatorPlusEqChar)(GDExtensionStringPtr p_self, char32_t p_b); + +/** + * @name string_operator_plus_eq_cstr + * @since 4.1 + * + * Appends a Latin-1 encoded C string to a String. + * + * @param p_self A pointer to the String. + * @param p_b A pointer to a Latin-1 encoded C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringOperatorPlusEqCstr)(GDExtensionStringPtr p_self, const char *p_b); + +/** + * @name string_operator_plus_eq_wcstr + * @since 4.1 + * + * Appends a wide C string to a String. + * + * @param p_self A pointer to the String. + * @param p_b A pointer to a wide C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringOperatorPlusEqWcstr)(GDExtensionStringPtr p_self, const wchar_t *p_b); + +/** + * @name string_operator_plus_eq_c32str + * @since 4.1 + * + * Appends a UTF-32 encoded C string to a String. + * + * @param p_self A pointer to the String. + * @param p_b A pointer to a UTF-32 encoded C string (null terminated). + */ +typedef void (*GDExtensionInterfaceStringOperatorPlusEqC32str)(GDExtensionStringPtr p_self, const char32_t *p_b); + +/** + * @name string_resize + * @since 4.2 + * + * Resizes the underlying string data to the given number of characters. + * + * Space needs to be allocated for the null terminating character ('\0') which + * also must be added manually, in order for all string functions to work correctly. + * + * Warning: This is an error-prone operation - only use it if there's no other + * efficient way to accomplish your goal. + * + * @param p_self A pointer to the String. + * @param p_resize The new length for the String. + * + * @return Error code signifying if the operation successful. + */ +typedef GDExtensionInt (*GDExtensionInterfaceStringResize)(GDExtensionStringPtr p_self, GDExtensionInt p_resize); + +/** + * @name string_name_new_with_latin1_chars + * @since 4.2 + * + * Creates a StringName from a Latin-1 encoded C string. + * + * If `p_is_static` is true, then: + * - The StringName will reuse the `p_contents` buffer instead of copying it. + * - You must guarantee that the buffer remains valid for the duration of the application (e.g. string literal). + * - You must not call a destructor for this StringName. Incrementing the initial reference once should achieve this. + * + * `p_is_static` is purely an optimization and can easily introduce undefined behavior if used wrong. In case of doubt, set it to false. + * + * @param r_dest A pointer to uninitialized storage, into which the newly created StringName is constructed. + * @param p_contents A pointer to a C string (null terminated and Latin-1 or ASCII encoded). + * @param p_is_static Whether the StringName reuses the buffer directly (see above). + */ +typedef void (*GDExtensionInterfaceStringNameNewWithLatin1Chars)(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents, GDExtensionBool p_is_static); + +/** + * @name string_name_new_with_utf8_chars + * @since 4.2 + * + * Creates a StringName from a UTF-8 encoded C string. + * + * @param r_dest A pointer to uninitialized storage, into which the newly created StringName is constructed. + * @param p_contents A pointer to a C string (null terminated and UTF-8 encoded). + */ +typedef void (*GDExtensionInterfaceStringNameNewWithUtf8Chars)(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents); + +/** + * @name string_name_new_with_utf8_chars_and_len + * @since 4.2 + * + * Creates a StringName from a UTF-8 encoded string with a given number of characters. + * + * @param r_dest A pointer to uninitialized storage, into which the newly created StringName is constructed. + * @param p_contents A pointer to a C string (null terminated and UTF-8 encoded). + * @param p_size The number of bytes (not UTF-8 code points). + */ +typedef void (*GDExtensionInterfaceStringNameNewWithUtf8CharsAndLen)(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents, GDExtensionInt p_size); + +/** + * @name xml_parser_open_buffer + * @since 4.1 + * + * Opens a raw XML buffer on an XMLParser instance. + * + * @param p_instance A pointer to an XMLParser object. + * @param p_buffer A pointer to the buffer. + * @param p_size The size of the buffer. + * + * @return A Godot error code (ex. OK, ERR_INVALID_DATA, etc). + * + * @see XMLParser::open_buffer() + */ +typedef GDExtensionInt (*GDExtensionInterfaceXmlParserOpenBuffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_buffer, size_t p_size); + +/** + * @name file_access_store_buffer + * @since 4.1 + * + * Stores the given buffer using an instance of FileAccess. + * + * @param p_instance A pointer to a FileAccess object. + * @param p_src A pointer to the buffer. + * @param p_length The size of the buffer. + * + * @see FileAccess::store_buffer() + */ +typedef void (*GDExtensionInterfaceFileAccessStoreBuffer)(GDExtensionObjectPtr p_instance, const uint8_t *p_src, uint64_t p_length); + +/** + * @name file_access_get_buffer + * @since 4.1 + * + * Reads the next p_length bytes into the given buffer using an instance of FileAccess. + * + * @param p_instance A pointer to a FileAccess object. + * @param p_dst A pointer to the buffer to store the data. + * @param p_length The requested number of bytes to read. + * + * @return The actual number of bytes read (may be less than requested). + */ +typedef uint64_t (*GDExtensionInterfaceFileAccessGetBuffer)(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length); + +/** + * @name image_ptrw + * @since 4.3 + * + * Returns writable pointer to internal Image buffer. + * + * @param p_instance A pointer to a Image object. + * + * @return Pointer to internal Image buffer. + * + * @see Image::ptrw() + */ +typedef uint8_t *(*GDExtensionInterfaceImagePtrw)(GDExtensionObjectPtr p_instance); + +/** + * @name image_ptr + * @since 4.3 + * + * Returns read only pointer to internal Image buffer. + * + * @param p_instance A pointer to a Image object. + * + * @return Pointer to internal Image buffer. + * + * @see Image::ptr() + */ +typedef const uint8_t *(*GDExtensionInterfaceImagePtr)(GDExtensionObjectPtr p_instance); + +/** + * @name worker_thread_pool_add_native_group_task + * @since 4.1 + * + * Adds a group task to an instance of WorkerThreadPool. + * + * @param p_instance A pointer to a WorkerThreadPool object. + * @param p_func A pointer to a function to run in the thread pool. + * @param p_userdata A pointer to arbitrary data which will be passed to p_func. + * @param p_elements The number of element needed in the group. + * @param p_tasks The number of tasks needed in the group. + * @param p_high_priority Whether or not this is a high priority task. + * @param p_description A pointer to a String with the task description. + * + * @return The task group ID. + * + * @see WorkerThreadPool::add_group_task() + */ +typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask)(GDExtensionObjectPtr p_instance, GDExtensionWorkerThreadPoolGroupTask p_func, void *p_userdata, int32_t p_elements, int32_t p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description); + +/** + * @name worker_thread_pool_add_native_task + * @since 4.1 + * + * Adds a task to an instance of WorkerThreadPool. + * + * @param p_instance A pointer to a WorkerThreadPool object. + * @param p_func A pointer to a function to run in the thread pool. + * @param p_userdata A pointer to arbitrary data which will be passed to p_func. + * @param p_high_priority Whether or not this is a high priority task. + * @param p_description A pointer to a String with the task description. + * + * @return The task ID. + */ +typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeTask)(GDExtensionObjectPtr p_instance, GDExtensionWorkerThreadPoolTask p_func, void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description); + +/** + * @name packed_byte_array_operator_index + * @since 4.1 + * + * Gets a pointer to a byte in a PackedByteArray. + * + * @param p_self A pointer to a PackedByteArray object. + * @param p_index The index of the byte to get. + * + * @return A pointer to the requested byte. + */ +typedef uint8_t *(*GDExtensionInterfacePackedByteArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_byte_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a byte in a PackedByteArray. + * + * @param p_self A const pointer to a PackedByteArray object. + * @param p_index The index of the byte to get. + * + * @return A const pointer to the requested byte. + */ +typedef const uint8_t *(*GDExtensionInterfacePackedByteArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_float32_array_operator_index + * @since 4.1 + * + * Gets a pointer to a 32-bit float in a PackedFloat32Array. + * + * @param p_self A pointer to a PackedFloat32Array object. + * @param p_index The index of the float to get. + * + * @return A pointer to the requested 32-bit float. + */ +typedef float *(*GDExtensionInterfacePackedFloat32ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_float32_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a 32-bit float in a PackedFloat32Array. + * + * @param p_self A const pointer to a PackedFloat32Array object. + * @param p_index The index of the float to get. + * + * @return A const pointer to the requested 32-bit float. + */ +typedef const float *(*GDExtensionInterfacePackedFloat32ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_float64_array_operator_index + * @since 4.1 + * + * Gets a pointer to a 64-bit float in a PackedFloat64Array. + * + * @param p_self A pointer to a PackedFloat64Array object. + * @param p_index The index of the float to get. + * + * @return A pointer to the requested 64-bit float. + */ +typedef double *(*GDExtensionInterfacePackedFloat64ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_float64_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a 64-bit float in a PackedFloat64Array. + * + * @param p_self A const pointer to a PackedFloat64Array object. + * @param p_index The index of the float to get. + * + * @return A const pointer to the requested 64-bit float. + */ +typedef const double *(*GDExtensionInterfacePackedFloat64ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_int32_array_operator_index + * @since 4.1 + * + * Gets a pointer to a 32-bit integer in a PackedInt32Array. + * + * @param p_self A pointer to a PackedInt32Array object. + * @param p_index The index of the integer to get. + * + * @return A pointer to the requested 32-bit integer. + */ +typedef int32_t *(*GDExtensionInterfacePackedInt32ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_int32_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a 32-bit integer in a PackedInt32Array. + * + * @param p_self A const pointer to a PackedInt32Array object. + * @param p_index The index of the integer to get. + * + * @return A const pointer to the requested 32-bit integer. + */ +typedef const int32_t *(*GDExtensionInterfacePackedInt32ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_int64_array_operator_index + * @since 4.1 + * + * Gets a pointer to a 64-bit integer in a PackedInt64Array. + * + * @param p_self A pointer to a PackedInt64Array object. + * @param p_index The index of the integer to get. + * + * @return A pointer to the requested 64-bit integer. + */ +typedef int64_t *(*GDExtensionInterfacePackedInt64ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_int64_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a 64-bit integer in a PackedInt64Array. + * + * @param p_self A const pointer to a PackedInt64Array object. + * @param p_index The index of the integer to get. + * + * @return A const pointer to the requested 64-bit integer. + */ +typedef const int64_t *(*GDExtensionInterfacePackedInt64ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_string_array_operator_index + * @since 4.1 + * + * Gets a pointer to a string in a PackedStringArray. + * + * @param p_self A pointer to a PackedStringArray object. + * @param p_index The index of the String to get. + * + * @return A pointer to the requested String. + */ +typedef GDExtensionStringPtr (*GDExtensionInterfacePackedStringArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_string_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a string in a PackedStringArray. + * + * @param p_self A const pointer to a PackedStringArray object. + * @param p_index The index of the String to get. + * + * @return A const pointer to the requested String. + */ +typedef GDExtensionStringPtr (*GDExtensionInterfacePackedStringArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_vector2_array_operator_index + * @since 4.1 + * + * Gets a pointer to a Vector2 in a PackedVector2Array. + * + * @param p_self A pointer to a PackedVector2Array object. + * @param p_index The index of the Vector2 to get. + * + * @return A pointer to the requested Vector2. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector2ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_vector2_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a Vector2 in a PackedVector2Array. + * + * @param p_self A const pointer to a PackedVector2Array object. + * @param p_index The index of the Vector2 to get. + * + * @return A const pointer to the requested Vector2. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector2ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_vector3_array_operator_index + * @since 4.1 + * + * Gets a pointer to a Vector3 in a PackedVector3Array. + * + * @param p_self A pointer to a PackedVector3Array object. + * @param p_index The index of the Vector3 to get. + * + * @return A pointer to the requested Vector3. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector3ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_vector3_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a Vector3 in a PackedVector3Array. + * + * @param p_self A const pointer to a PackedVector3Array object. + * @param p_index The index of the Vector3 to get. + * + * @return A const pointer to the requested Vector3. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector3ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_vector4_array_operator_index + * @since 4.3 + * + * Gets a pointer to a Vector4 in a PackedVector4Array. + * + * @param p_self A pointer to a PackedVector4Array object. + * @param p_index The index of the Vector4 to get. + * + * @return A pointer to the requested Vector4. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector4ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_vector4_array_operator_index_const + * @since 4.3 + * + * Gets a const pointer to a Vector4 in a PackedVector4Array. + * + * @param p_self A const pointer to a PackedVector4Array object. + * @param p_index The index of the Vector4 to get. + * + * @return A const pointer to the requested Vector4. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector4ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_color_array_operator_index + * @since 4.1 + * + * Gets a pointer to a color in a PackedColorArray. + * + * @param p_self A pointer to a PackedColorArray object. + * @param p_index The index of the Color to get. + * + * @return A pointer to the requested Color. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedColorArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name packed_color_array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a color in a PackedColorArray. + * + * @param p_self A const pointer to a PackedColorArray object. + * @param p_index The index of the Color to get. + * + * @return A const pointer to the requested Color. + */ +typedef GDExtensionTypePtr (*GDExtensionInterfacePackedColorArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name array_operator_index + * @since 4.1 + * + * Gets a pointer to a Variant in an Array. + * + * @param p_self A pointer to an Array object. + * @param p_index The index of the Variant to get. + * + * @return A pointer to the requested Variant. + */ +typedef GDExtensionVariantPtr (*GDExtensionInterfaceArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index); + +/** + * @name array_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a Variant in an Array. + * + * @param p_self A const pointer to an Array object. + * @param p_index The index of the Variant to get. + * + * @return A const pointer to the requested Variant. + */ +typedef GDExtensionVariantPtr (*GDExtensionInterfaceArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index); + +/** + * @name array_ref + * @since 4.1 + * @deprecated Deprecated in Godot 4.5. Removed from interface. Use copy constructor instead. + * + * Sets an Array to be a reference to another Array object. + * + * @param p_self A pointer to the Array object to update. + * @param p_from A pointer to the Array object to reference. + */ +typedef void (*GDExtensionInterfaceArrayRef)(GDExtensionTypePtr p_self, GDExtensionConstTypePtr p_from); + +/** + * @name array_set_typed + * @since 4.1 + * + * Makes an Array into a typed Array. + * + * @param p_self A pointer to the Array. + * @param p_type The type of Variant the Array will store. + * @param p_class_name A pointer to a StringName with the name of the object (if p_type is GDEXTENSION_VARIANT_TYPE_OBJECT). + * @param p_script A pointer to a Script object (if p_type is GDEXTENSION_VARIANT_TYPE_OBJECT and the base class is extended by a script). + */ +typedef void (*GDExtensionInterfaceArraySetTyped)(GDExtensionTypePtr p_self, GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstVariantPtr p_script); + +/** + * @name dictionary_operator_index + * @since 4.1 + * + * Gets a pointer to a Variant in a Dictionary with the given key. + * + * @param p_self A pointer to a Dictionary object. + * @param p_key A pointer to a Variant representing the key. + * + * @return A pointer to a Variant representing the value at the given key. + */ +typedef GDExtensionVariantPtr (*GDExtensionInterfaceDictionaryOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionConstVariantPtr p_key); + +/** + * @name dictionary_operator_index_const + * @since 4.1 + * + * Gets a const pointer to a Variant in a Dictionary with the given key. + * + * @param p_self A const pointer to a Dictionary object. + * @param p_key A pointer to a Variant representing the key. + * + * @return A const pointer to a Variant representing the value at the given key. + */ +typedef GDExtensionVariantPtr (*GDExtensionInterfaceDictionaryOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionConstVariantPtr p_key); + +/** + * @name dictionary_set_typed + * @since 4.4 + * + * Makes a Dictionary into a typed Dictionary. + * + * @param p_self A pointer to the Dictionary. + * @param p_key_type The type of Variant the Dictionary key will store. + * @param p_key_class_name A pointer to a StringName with the name of the object (if p_key_type is GDEXTENSION_VARIANT_TYPE_OBJECT). + * @param p_key_script A pointer to a Script object (if p_key_type is GDEXTENSION_VARIANT_TYPE_OBJECT and the base class is extended by a script). + * @param p_value_type The type of Variant the Dictionary value will store. + * @param p_value_class_name A pointer to a StringName with the name of the object (if p_value_type is GDEXTENSION_VARIANT_TYPE_OBJECT). + * @param p_value_script A pointer to a Script object (if p_value_type is GDEXTENSION_VARIANT_TYPE_OBJECT and the base class is extended by a script). + */ +typedef void (*GDExtensionInterfaceDictionarySetTyped)(GDExtensionTypePtr p_self, GDExtensionVariantType p_key_type, GDExtensionConstStringNamePtr p_key_class_name, GDExtensionConstVariantPtr p_key_script, GDExtensionVariantType p_value_type, GDExtensionConstStringNamePtr p_value_class_name, GDExtensionConstVariantPtr p_value_script); + +/** + * @name object_method_bind_call + * @since 4.1 + * + * Calls a method on an Object. + * + * @param p_method_bind A pointer to the MethodBind representing the method on the Object's class. + * @param p_instance A pointer to the Object. + * @param p_args A pointer to a C array of Variants representing the arguments. + * @param p_arg_count The number of arguments. + * @param r_ret A pointer to Variant which will receive the return value. + * @param r_error A pointer to a GDExtensionCallError struct that will receive error information. + */ +typedef void (*GDExtensionInterfaceObjectMethodBindCall)(GDExtensionMethodBindPtr p_method_bind, GDExtensionObjectPtr p_instance, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_arg_count, GDExtensionUninitializedVariantPtr r_ret, GDExtensionCallError *r_error); + +/** + * @name object_method_bind_ptrcall + * @since 4.1 + * + * Calls a method on an Object (using a "ptrcall"). + * + * @param p_method_bind A pointer to the MethodBind representing the method on the Object's class. + * @param p_instance A pointer to the Object. + * @param p_args A pointer to a C array representing the arguments. + * @param r_ret A pointer to the Object that will receive the return value. + */ +typedef void (*GDExtensionInterfaceObjectMethodBindPtrcall)(GDExtensionMethodBindPtr p_method_bind, GDExtensionObjectPtr p_instance, const GDExtensionConstTypePtr *p_args, GDExtensionTypePtr r_ret); + +/** + * @name object_destroy + * @since 4.1 + * + * Destroys an Object. + * + * @param p_o A pointer to the Object. + */ +typedef void (*GDExtensionInterfaceObjectDestroy)(GDExtensionObjectPtr p_o); + +/** + * @name global_get_singleton + * @since 4.1 + * + * Gets a global singleton by name. + * + * @param p_name A pointer to a StringName with the singleton name. + * + * @return A pointer to the singleton Object. + */ +typedef GDExtensionObjectPtr (*GDExtensionInterfaceGlobalGetSingleton)(GDExtensionConstStringNamePtr p_name); + +/** + * @name object_get_instance_binding + * @since 4.1 + * + * Gets a pointer representing an Object's instance binding. + * + * @param p_o A pointer to the Object. + * @param p_token A token the library received by the GDExtension's entry point function. + * @param p_callbacks A pointer to a GDExtensionInstanceBindingCallbacks struct. + * + * @return A pointer to the instance binding. + */ +typedef void *(*GDExtensionInterfaceObjectGetInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token, const GDExtensionInstanceBindingCallbacks *p_callbacks); + +/** + * @name object_set_instance_binding + * @since 4.1 + * + * Sets an Object's instance binding. + * + * @param p_o A pointer to the Object. + * @param p_token A token the library received by the GDExtension's entry point function. + * @param p_binding A pointer to the instance binding. + * @param p_callbacks A pointer to a GDExtensionInstanceBindingCallbacks struct. + */ +typedef void (*GDExtensionInterfaceObjectSetInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token, void *p_binding, const GDExtensionInstanceBindingCallbacks *p_callbacks); + +/** + * @name object_free_instance_binding + * @since 4.2 + * + * Free an Object's instance binding. + * + * @param p_o A pointer to the Object. + * @param p_token A token the library received by the GDExtension's entry point function. + */ +typedef void (*GDExtensionInterfaceObjectFreeInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token); + +/** + * @name object_set_instance + * @since 4.1 + * + * Sets an extension class instance on a Object. + * + * `p_classname` should be a registered extension class and should extend the `p_o` Object's class. + * + * @param p_o A pointer to the Object. + * @param p_classname A pointer to a StringName with the registered extension class's name. + * @param p_instance A pointer to the extension class instance. + */ +typedef void (*GDExtensionInterfaceObjectSetInstance)(GDExtensionObjectPtr p_o, GDExtensionConstStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance); + +/** + * @name object_get_class_name + * @since 4.1 + * + * Gets the class name of an Object. + * + * If the GDExtension wraps the Godot object in an abstraction specific to its class, this is the + * function that should be used to determine which wrapper to use. + * + * @param p_object A pointer to the Object. + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param r_class_name A pointer to a String to receive the class name. + * + * @return true if successful in getting the class name; otherwise false. + */ +typedef GDExtensionBool (*GDExtensionInterfaceObjectGetClassName)(GDExtensionConstObjectPtr p_object, GDExtensionClassLibraryPtr p_library, GDExtensionUninitializedStringNamePtr r_class_name); + +/** + * @name object_cast_to + * @since 4.1 + * + * Casts an Object to a different type. + * + * @param p_object A pointer to the Object. + * @param p_class_tag A pointer uniquely identifying a built-in class in the ClassDB. + * + * @return Returns a pointer to the Object, or NULL if it can't be cast to the requested type. + */ +typedef GDExtensionObjectPtr (*GDExtensionInterfaceObjectCastTo)(GDExtensionConstObjectPtr p_object, void *p_class_tag); + +/** + * @name object_get_instance_from_id + * @since 4.1 + * + * Gets an Object by its instance ID. + * + * @param p_instance_id The instance ID. + * + * @return A pointer to the Object. + */ +typedef GDExtensionObjectPtr (*GDExtensionInterfaceObjectGetInstanceFromId)(GDObjectInstanceID p_instance_id); + +/** + * @name object_get_instance_id + * @since 4.1 + * + * Gets the instance ID from an Object. + * + * @param p_object A pointer to the Object. + * + * @return The instance ID. + */ +typedef GDObjectInstanceID (*GDExtensionInterfaceObjectGetInstanceId)(GDExtensionConstObjectPtr p_object); + +/** + * @name object_has_script_method + * @since 4.3 + * + * Checks if this object has a script with the given method. + * + * @param p_object A pointer to the Object. + * @param p_method A pointer to a StringName identifying the method. + * + * @return true if the object has a script and that script has a method with the given name. Returns false if the object has no script. + */ +typedef GDExtensionBool (*GDExtensionInterfaceObjectHasScriptMethod)(GDExtensionConstObjectPtr p_object, GDExtensionConstStringNamePtr p_method); + +/** + * @name object_call_script_method + * @since 4.3 + * + * Call the given script method on this object. + * + * @param p_object A pointer to the Object. + * @param p_method A pointer to a StringName identifying the method. + * @param p_args A pointer to a C array of Variant. + * @param p_argument_count The number of arguments. + * @param r_return A pointer a Variant which will be assigned the return value. + * @param r_error A pointer the structure which will hold error information. + */ +typedef void (*GDExtensionInterfaceObjectCallScriptMethod)(GDExtensionObjectPtr p_object, GDExtensionConstStringNamePtr p_method, const GDExtensionConstVariantPtr *p_args, GDExtensionInt p_argument_count, GDExtensionUninitializedVariantPtr r_return, GDExtensionCallError *r_error); + +/** + * @name ref_get_object + * @since 4.1 + * + * Gets the Object from a reference. + * + * @param p_ref A pointer to the reference. + * + * @return A pointer to the Object from the reference or NULL. + */ +typedef GDExtensionObjectPtr (*GDExtensionInterfaceRefGetObject)(GDExtensionConstRefPtr p_ref); + +/** + * @name ref_set_object + * @since 4.1 + * + * Sets the Object referred to by a reference. + * + * @param p_ref A pointer to the reference. + * @param p_object A pointer to the Object to refer to. + */ +typedef void (*GDExtensionInterfaceRefSetObject)(GDExtensionRefPtr p_ref, GDExtensionObjectPtr p_object); + +/** + * @name script_instance_create + * @since 4.1 + * @deprecated Deprecated in Godot 4.2. Use `script_instance_create3` instead. + * + * Creates a script instance that contains the given info and instance data. + * + * @param p_info A pointer to a GDExtensionScriptInstanceInfo struct. + * @param p_instance_data A pointer to a data representing the script instance in the GDExtension. This will be passed to all the function pointers on p_info. + * + * @return A pointer to a ScriptInstanceExtension object. + */ +typedef GDExtensionScriptInstancePtr (*GDExtensionInterfaceScriptInstanceCreate)(const GDExtensionScriptInstanceInfo *p_info, GDExtensionScriptInstanceDataPtr p_instance_data); + +/** + * @name script_instance_create2 + * @since 4.2 + * @deprecated Deprecated in Godot 4.3. Use `script_instance_create3` instead. + * + * Creates a script instance that contains the given info and instance data. + * + * @param p_info A pointer to a GDExtensionScriptInstanceInfo2 struct. + * @param p_instance_data A pointer to a data representing the script instance in the GDExtension. This will be passed to all the function pointers on p_info. + * + * @return A pointer to a ScriptInstanceExtension object. + */ +typedef GDExtensionScriptInstancePtr (*GDExtensionInterfaceScriptInstanceCreate2)(const GDExtensionScriptInstanceInfo2 *p_info, GDExtensionScriptInstanceDataPtr p_instance_data); + +/** + * @name script_instance_create3 + * @since 4.3 + * + * Creates a script instance that contains the given info and instance data. + * + * @param p_info A pointer to a GDExtensionScriptInstanceInfo3 struct. + * @param p_instance_data A pointer to a data representing the script instance in the GDExtension. This will be passed to all the function pointers on p_info. + * + * @return A pointer to a ScriptInstanceExtension object. + */ +typedef GDExtensionScriptInstancePtr (*GDExtensionInterfaceScriptInstanceCreate3)(const GDExtensionScriptInstanceInfo3 *p_info, GDExtensionScriptInstanceDataPtr p_instance_data); + +/** + * @name placeholder_script_instance_create + * @since 4.2 + * + * Creates a placeholder script instance for a given script and instance. + * + * This interface is optional as a custom placeholder could also be created with script_instance_create(). + * + * @param p_language A pointer to a ScriptLanguage. + * @param p_script A pointer to a Script. + * @param p_owner A pointer to an Object. + * + * @return A pointer to a PlaceHolderScriptInstance object. + */ +typedef GDExtensionScriptInstancePtr (*GDExtensionInterfacePlaceHolderScriptInstanceCreate)(GDExtensionObjectPtr p_language, GDExtensionObjectPtr p_script, GDExtensionObjectPtr p_owner); + +/** + * @name placeholder_script_instance_update + * @since 4.2 + * + * Updates a placeholder script instance with the given properties and values. + * + * The passed in placeholder must be an instance of PlaceHolderScriptInstance + * such as the one returned by placeholder_script_instance_create(). + * + * @param p_placeholder A pointer to a PlaceHolderScriptInstance. + * @param p_properties A pointer to an Array of Dictionary representing PropertyInfo. + * @param p_values A pointer to a Dictionary mapping StringName to Variant values. + */ +typedef void (*GDExtensionInterfacePlaceHolderScriptInstanceUpdate)(GDExtensionScriptInstancePtr p_placeholder, GDExtensionConstTypePtr p_properties, GDExtensionConstTypePtr p_values); + +/** + * @name object_get_script_instance + * @since 4.2 + * + * Get the script instance data attached to this object. + * + * @param p_object A pointer to the Object. + * @param p_language A pointer to the language expected for this script instance. + * + * @return A GDExtensionScriptInstanceDataPtr that was attached to this object as part of script_instance_create. + */ +typedef GDExtensionScriptInstanceDataPtr (*GDExtensionInterfaceObjectGetScriptInstance)(GDExtensionConstObjectPtr p_object, GDExtensionObjectPtr p_language); + +/** + * @name object_set_script_instance + * @since 4.5 + * + * Set the script instance data attached to this object. + * + * @param p_object A pointer to the Object. + * @param p_script_instance A pointer to the script instance data to attach to this object. + */ +typedef void (*GDExtensionInterfaceObjectSetScriptInstance)(GDExtensionObjectPtr p_object, GDExtensionScriptInstanceDataPtr p_script_instance); + +/** + * @name callable_custom_create + * @since 4.2 + * @deprecated Deprecated in Godot 4.3. Use `callable_custom_create2` instead. + * + * Creates a custom Callable object from a function pointer. + * + * Provided struct can be safely freed once the function returns. + * + * @param r_callable A pointer that will receive the new Callable. + * @param p_callable_custom_info The info required to construct a Callable. + */ +typedef void (*GDExtensionInterfaceCallableCustomCreate)(GDExtensionUninitializedTypePtr r_callable, GDExtensionCallableCustomInfo *p_callable_custom_info); + +/** + * @name callable_custom_create2 + * @since 4.3 + * + * Creates a custom Callable object from a function pointer. + * + * Provided struct can be safely freed once the function returns. + * + * @param r_callable A pointer that will receive the new Callable. + * @param p_callable_custom_info The info required to construct a Callable. + */ +typedef void (*GDExtensionInterfaceCallableCustomCreate2)(GDExtensionUninitializedTypePtr r_callable, GDExtensionCallableCustomInfo2 *p_callable_custom_info); + +/** + * @name callable_custom_get_userdata + * @since 4.2 + * + * Retrieves the userdata pointer from a custom Callable. + * + * If the Callable is not a custom Callable or the token does not match the one provided to callable_custom_create() via GDExtensionCallableCustomInfo then NULL will be returned. + * + * @param p_callable A pointer to a Callable. + * @param p_token A pointer to an address that uniquely identifies the GDExtension. + * + * @return The userdata pointer given when creating this custom Callable. + */ +typedef void *(*GDExtensionInterfaceCallableCustomGetUserData)(GDExtensionConstTypePtr p_callable, void *p_token); + +/** + * @name classdb_construct_object + * @since 4.1 + * @deprecated Deprecated in Godot 4.4. Use `classdb_construct_object2` instead. + * + * Constructs an Object of the requested class. + * + * The passed class must be a built-in godot class, or an already-registered extension class. In both cases, object_set_instance() should be called to fully initialize the object. + * + * @param p_classname A pointer to a StringName with the class name. + * + * @return A pointer to the newly created Object. + */ +typedef GDExtensionObjectPtr (*GDExtensionInterfaceClassdbConstructObject)(GDExtensionConstStringNamePtr p_classname); + +/** + * @name classdb_construct_object2 + * @since 4.4 + * + * Constructs an Object of the requested class. + * + * The passed class must be a built-in godot class, or an already-registered extension class. In both cases, object_set_instance() should be called to fully initialize the object. + * + * "NOTIFICATION_POSTINITIALIZE" must be sent after construction. + * + * @param p_classname A pointer to a StringName with the class name. + * + * @return A pointer to the newly created Object. + */ +typedef GDExtensionObjectPtr (*GDExtensionInterfaceClassdbConstructObject2)(GDExtensionConstStringNamePtr p_classname); + +/** + * @name classdb_get_method_bind + * @since 4.1 + * + * Gets a pointer to the MethodBind in ClassDB for the given class, method and hash. + * + * @param p_classname A pointer to a StringName with the class name. + * @param p_methodname A pointer to a StringName with the method name. + * @param p_hash A hash representing the function signature. + * + * @return A pointer to the MethodBind from ClassDB. + */ +typedef GDExtensionMethodBindPtr (*GDExtensionInterfaceClassdbGetMethodBind)(GDExtensionConstStringNamePtr p_classname, GDExtensionConstStringNamePtr p_methodname, GDExtensionInt p_hash); + +/** + * @name classdb_get_class_tag + * @since 4.1 + * + * Gets a pointer uniquely identifying the given built-in class in the ClassDB. + * + * @param p_classname A pointer to a StringName with the class name. + * + * @return A pointer uniquely identifying the built-in class in the ClassDB. + */ +typedef void *(*GDExtensionInterfaceClassdbGetClassTag)(GDExtensionConstStringNamePtr p_classname); + +/** + * @name classdb_register_extension_class + * @since 4.1 + * @deprecated Deprecated in Godot 4.2. Use `classdb_register_extension_class5` instead. + * + * Registers an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_parent_class_name A pointer to a StringName with the parent class name. + * @param p_extension_funcs A pointer to a GDExtensionClassCreationInfo struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo *p_extension_funcs); + +/** + * @name classdb_register_extension_class2 + * @since 4.2 + * @deprecated Deprecated in Godot 4.3. Use `classdb_register_extension_class5` instead. + * + * Registers an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_parent_class_name A pointer to a StringName with the parent class name. + * @param p_extension_funcs A pointer to a GDExtensionClassCreationInfo2 struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass2)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo2 *p_extension_funcs); + +/** + * @name classdb_register_extension_class3 + * @since 4.3 + * @deprecated Deprecated in Godot 4.4. Use `classdb_register_extension_class5` instead. + * + * Registers an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_parent_class_name A pointer to a StringName with the parent class name. + * @param p_extension_funcs A pointer to a GDExtensionClassCreationInfo3 struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass3)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo3 *p_extension_funcs); + +/** + * @name classdb_register_extension_class4 + * @since 4.4 + * @deprecated Deprecated in Godot 4.5. Use `classdb_register_extension_class5` instead. + * + * Registers an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_parent_class_name A pointer to a StringName with the parent class name. + * @param p_extension_funcs A pointer to a GDExtensionClassCreationInfo4 struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass4)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo4 *p_extension_funcs); + +/** + * @name classdb_register_extension_class5 + * @since 4.5 + * + * Registers an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_parent_class_name A pointer to a StringName with the parent class name. + * @param p_extension_funcs A pointer to a GDExtensionClassCreationInfo5 struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClass5)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_parent_class_name, const GDExtensionClassCreationInfo5 *p_extension_funcs); + +/** + * @name classdb_register_extension_class_method + * @since 4.1 + * + * Registers a method on an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_method_info A pointer to a GDExtensionClassMethodInfo struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassMethod)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassMethodInfo *p_method_info); + +/** + * @name classdb_register_extension_class_virtual_method + * @since 4.3 + * + * Registers a virtual method on an extension class in ClassDB, that can be implemented by scripts or other extensions. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_method_info A pointer to a GDExtensionClassMethodInfo struct. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassVirtualMethod)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionClassVirtualMethodInfo *p_method_info); + +/** + * @name classdb_register_extension_class_integer_constant + * @since 4.1 + * + * Registers an integer constant on an extension class in the ClassDB. + * + * Note about registering bitfield values (if p_is_bitfield is true): even though p_constant_value is signed, language bindings are + * advised to treat bitfields as uint64_t, since this is generally clearer and can prevent mistakes like using -1 for setting all bits. + * Language APIs should thus provide an abstraction that registers bitfields (uint64_t) separately from regular constants (int64_t). + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_enum_name A pointer to a StringName with the enum name. + * @param p_constant_name A pointer to a StringName with the constant name. + * @param p_constant_value The constant value. + * @param p_is_bitfield Whether or not this constant is part of a bitfield. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassIntegerConstant)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_enum_name, GDExtensionConstStringNamePtr p_constant_name, GDExtensionInt p_constant_value, GDExtensionBool p_is_bitfield); + +/** + * @name classdb_register_extension_class_property + * @since 4.1 + * + * Registers a property on an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_info A pointer to a GDExtensionPropertyInfo struct. + * @param p_setter A pointer to a StringName with the name of the setter method. + * @param p_getter A pointer to a StringName with the name of the getter method. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassProperty)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionPropertyInfo *p_info, GDExtensionConstStringNamePtr p_setter, GDExtensionConstStringNamePtr p_getter); + +/** + * @name classdb_register_extension_class_property_indexed + * @since 4.2 + * + * Registers an indexed property on an extension class in the ClassDB. + * + * Provided struct can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_info A pointer to a GDExtensionPropertyInfo struct. + * @param p_setter A pointer to a StringName with the name of the setter method. + * @param p_getter A pointer to a StringName with the name of the getter method. + * @param p_index The index to pass as the first argument to the getter and setter methods. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassPropertyIndexed)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, const GDExtensionPropertyInfo *p_info, GDExtensionConstStringNamePtr p_setter, GDExtensionConstStringNamePtr p_getter, GDExtensionInt p_index); + +/** + * @name classdb_register_extension_class_property_group + * @since 4.1 + * + * Registers a property group on an extension class in the ClassDB. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_group_name A pointer to a String with the group name. + * @param p_prefix A pointer to a String with the prefix used by properties in this group. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassPropertyGroup)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringPtr p_group_name, GDExtensionConstStringPtr p_prefix); + +/** + * @name classdb_register_extension_class_property_subgroup + * @since 4.1 + * + * Registers a property subgroup on an extension class in the ClassDB. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_subgroup_name A pointer to a String with the subgroup name. + * @param p_prefix A pointer to a String with the prefix used by properties in this subgroup. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassPropertySubgroup)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringPtr p_subgroup_name, GDExtensionConstStringPtr p_prefix); + +/** + * @name classdb_register_extension_class_signal + * @since 4.1 + * + * Registers a signal on an extension class in the ClassDB. + * + * Provided structs can be safely freed once the function returns. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + * @param p_signal_name A pointer to a StringName with the signal name. + * @param p_argument_info A pointer to a GDExtensionPropertyInfo struct. + * @param p_argument_count The number of arguments the signal receives. + */ +typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassSignal)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name, GDExtensionConstStringNamePtr p_signal_name, const GDExtensionPropertyInfo *p_argument_info, GDExtensionInt p_argument_count); + +/** + * @name classdb_unregister_extension_class + * @since 4.1 + * + * Unregisters an extension class in the ClassDB. + * + * Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_class_name A pointer to a StringName with the class name. + */ +typedef void (*GDExtensionInterfaceClassdbUnregisterExtensionClass)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name); + +/** + * @name get_library_path + * @since 4.1 + * + * Gets the path to the current GDExtension library. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param r_path A pointer to a String which will receive the path. + */ +typedef void (*GDExtensionInterfaceGetLibraryPath)(GDExtensionClassLibraryPtr p_library, GDExtensionUninitializedStringPtr r_path); + +/** + * @name editor_add_plugin + * @since 4.1 + * + * Adds an editor plugin. + * + * It's safe to call during initialization. + * + * @param p_class_name A pointer to a StringName with the name of a class (descending from EditorPlugin) which is already registered with ClassDB. + */ +typedef void (*GDExtensionInterfaceEditorAddPlugin)(GDExtensionConstStringNamePtr p_class_name); + +/** + * @name editor_remove_plugin + * @since 4.1 + * + * Removes an editor plugin. + * + * @param p_class_name A pointer to a StringName with the name of a class that was previously added as an editor plugin. + */ +typedef void (*GDExtensionInterfaceEditorRemovePlugin)(GDExtensionConstStringNamePtr p_class_name); + +/** + * @name editor_help_load_xml_from_utf8_chars + * @since 4.3 + * + * Loads new XML-formatted documentation data in the editor. + * + * The provided pointer can be immediately freed once the function returns. + * + * @param p_data A pointer to a UTF-8 encoded C string (null terminated). + */ +typedef void (*GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8Chars)(const char *p_data); + +/** + * @name editor_help_load_xml_from_utf8_chars_and_len + * @since 4.3 + * + * Loads new XML-formatted documentation data in the editor. + * + * The provided pointer can be immediately freed once the function returns. + * + * @param p_data A pointer to a UTF-8 encoded C string. + * @param p_size The number of bytes (not code units). + */ +typedef void (*GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen)(const char *p_data, GDExtensionInt p_size); + +/** + * @name editor_register_get_classes_used_callback + * @since 4.5 + * + * Registers a callback that Godot can call to get the list of all classes (from ClassDB) that may be used by the calling GDExtension. + * + * This is used by the editor to generate a build profile (in "Tools" > "Engine Compilation Configuration Editor..." > "Detect from project"), + * in order to recompile Godot with only the classes used. + * 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. + * If a GDExtension doesn't register a callback, Godot will assume that it could be using any classes. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_callback The callback to retrieve the list of classes used. + */ +typedef void (*GDExtensionInterfaceEditorRegisterGetClassesUsedCallback)(GDExtensionClassLibraryPtr p_library, GDExtensionEditorGetClassesUsedCallback p_callback); + +/** + * @name register_main_loop_callbacks + * @since 4.5 + * + * Registers callbacks to be called at different phases of the main loop. + * + * @param p_library A pointer the library received by the GDExtension's entry point function. + * @param p_callbacks A pointer to the structure that contains the callbacks. + */ +typedef void (*GDExtensionInterfaceRegisterMainLoopCallbacks)(GDExtensionClassLibraryPtr p_library, const GDExtensionMainLoopCallbacks *p_callbacks); + +#ifdef __cplusplus +} +#endif diff --git a/managed/GodotSharpCompat/CallableDelegateRegistry.cs b/managed/GodotSharpCompat/CallableDelegateRegistry.cs new file mode 100644 index 0000000..c290f8b --- /dev/null +++ b/managed/GodotSharpCompat/CallableDelegateRegistry.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; + +namespace Godot +{ + internal static class CallableDelegateRegistry + { + private static readonly Dictionary> Delegates = new Dictionary>(); + private static long nextId = 1; + + internal static long Register(Func function) + { + long id = nextId++; + Delegates[id] = function; + return id; + } + + internal static void Unregister(long delegateId) + { + Delegates.Remove(delegateId); + } + + public static Variant Invoke(long delegateId, Variant[] arguments) + { + Func function; + if (!Delegates.TryGetValue(delegateId, out function)) + { + return new Variant(); + } + return function(arguments ?? new Variant[0]); + } + + internal static T ConvertArgument(Variant[] arguments, int index) + { + Variant value = arguments[index]; + Type type = typeof(T); + if (type == typeof(Variant)) + { + return (T)(object)value; + } + if (type == typeof(string)) + { + return (T)(object)value.ToString(); + } + if (type == typeof(int)) + { + return (T)(object)(int)value.AsInt64(); + } + if (type == typeof(long)) + { + return (T)(object)value.AsInt64(); + } + if (type == typeof(float)) + { + return (T)(object)(float)value.AsDouble(); + } + if (type == typeof(double)) + { + return (T)(object)value.AsDouble(); + } + if (type == typeof(bool)) + { + return (T)(object)value.AsBool(); + } + if (type == typeof(Vector2)) + { + return (T)(object)value.AsVector2(); + } + if (type == typeof(Vector3)) + { + return (T)(object)value.AsVector3(); + } + if (type == typeof(StringName)) + { + return (T)(object)value.AsStringName(); + } + if (type == typeof(NodePath)) + { + return (T)(object)value.AsNodePath(); + } + if (type == typeof(RID)) + { + return (T)(object)value.AsRID(); + } + if (type == typeof(Color)) + { + return (T)(object)value.AsColor(); + } + if (type == typeof(Quaternion)) + { + return (T)(object)value.AsQuaternion(); + } + if (type == typeof(Basis)) + { + return (T)(object)value.AsBasis(); + } + if (type == typeof(Transform3D)) + { + return (T)(object)value.AsTransform3D(); + } + if (type == typeof(Node)) + { + return (T)(object)value.AsObject(); + } + if (type == typeof(Node2D)) + { + return (T)(object)value.AsObject(); + } + if (type == typeof(GodotObject)) + { + return (T)(object)value.AsObject(); + } + return default(T); + } + } +} diff --git a/managed/GodotSharpCompat/ExportAttribute.cs b/managed/GodotSharpCompat/ExportAttribute.cs new file mode 100644 index 0000000..b03386f --- /dev/null +++ b/managed/GodotSharpCompat/ExportAttribute.cs @@ -0,0 +1,34 @@ +using System; + +namespace Godot +{ + [AttributeUsage(AttributeTargets.Property)] + public sealed class ExportAttribute : Attribute + { + public readonly PropertyHint Hint; + public readonly string HintString; + public readonly PropertyUsageFlags Usage; + + public ExportAttribute() + : this(PropertyHint.None, string.Empty, PropertyUsageFlags.PropertyUsageDefault) + { + } + + public ExportAttribute(PropertyHint hint) + : this(hint, string.Empty, PropertyUsageFlags.PropertyUsageDefault) + { + } + + public ExportAttribute(PropertyHint hint, string hintString) + : this(hint, hintString, PropertyUsageFlags.PropertyUsageDefault) + { + } + + public ExportAttribute(PropertyHint hint, string hintString, PropertyUsageFlags usage) + { + Hint = hint; + HintString = hintString ?? string.Empty; + Usage = usage; + } + } +} diff --git a/managed/GodotSharpCompat/GD.cs b/managed/GodotSharpCompat/GD.cs new file mode 100644 index 0000000..64d947d --- /dev/null +++ b/managed/GodotSharpCompat/GD.cs @@ -0,0 +1,15 @@ +using System.Runtime.CompilerServices; + +namespace Godot +{ + public static class GD + { + public static void Print(string message) + { + PrintInternal(message); + } + + [MethodImpl(MethodImplOptions.InternalCall)] + private static extern void PrintInternal(string message); + } +} diff --git a/managed/GodotSharpCompat/GodotObject.cs b/managed/GodotSharpCompat/GodotObject.cs new file mode 100644 index 0000000..17eff69 --- /dev/null +++ b/managed/GodotSharpCompat/GodotObject.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; + +namespace Godot +{ + public partial class GodotObject : System.IDisposable + { + private static readonly Dictionary NativeInstanceCache = new Dictionary(); + + internal System.IntPtr NativePtr; + private int ownedNativeRefCount; + + internal static T CreateFromNative(System.IntPtr nativePtr) where T : GodotObject, new() + { + return CreateFromNative(nativePtr, false); + } + + internal static T CreateFromNative(System.IntPtr nativePtr, bool ownsNativeRef) where T : GodotObject, new() + { + if (nativePtr == System.IntPtr.Zero) + { + return null; + } + + WeakReference weakReference; + if (NativeInstanceCache.TryGetValue(nativePtr, out weakReference)) + { + T cached = weakReference.Target as T; + if (cached != null && cached.NativePtr == nativePtr) + { + if (ownsNativeRef) + { + cached.ownedNativeRefCount++; + } + return cached; + } + } + + T instance = new T(); + instance.NativePtr = nativePtr; + instance.ownedNativeRefCount = ownsNativeRef ? 1 : 0; + NativeInstanceCache[nativePtr] = new WeakReference(instance); + return instance; + } + + ~GodotObject() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + System.GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (NativePtr == System.IntPtr.Zero) + { + return; + } + + NativeInstanceCache.Remove(NativePtr); + while (ownedNativeRefCount > 0) + { + NativeCalls.GodotObjectReleaseRefCounted(NativePtr); + ownedNativeRefCount--; + } + NativePtr = System.IntPtr.Zero; + } + } +} diff --git a/managed/GodotSharpCompat/GodotSharpCompat.csproj b/managed/GodotSharpCompat/GodotSharpCompat.csproj new file mode 100644 index 0000000..866a456 --- /dev/null +++ b/managed/GodotSharpCompat/GodotSharpCompat.csproj @@ -0,0 +1,26 @@ + + + Library + v4.7.2 + false + GodotSharpCompat + Godot + true + true + false + none + ..\..\project\leanclr\ + + + + + + + ../../thirdparty/leanclr/src/libraries/dotnetframework4.x-linux/mscorlib.dll + + + ../../thirdparty/leanclr/src/libraries/dotnetframework4.x-linux/System.dll + + + + diff --git a/managed/GodotSharpCompat/NativeCalls.cs b/managed/GodotSharpCompat/NativeCalls.cs new file mode 100644 index 0000000..e9f8df5 --- /dev/null +++ b/managed/GodotSharpCompat/NativeCalls.cs @@ -0,0 +1,9 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Godot +{ + internal static partial class NativeCalls + { + } +} diff --git a/managed/GodotSharpCompat/Node.cs b/managed/GodotSharpCompat/Node.cs new file mode 100644 index 0000000..b18c710 --- /dev/null +++ b/managed/GodotSharpCompat/Node.cs @@ -0,0 +1,13 @@ +namespace Godot +{ + public partial class Node : GodotObject + { + public virtual void _Ready() + { + } + + public virtual void _Process(double delta) + { + } + } +} diff --git a/project/Game.csproj b/project/Game.csproj new file mode 100644 index 0000000..8756890 --- /dev/null +++ b/project/Game.csproj @@ -0,0 +1,30 @@ + + + Library + v4.7.2 + latest + false + Game + Game + true + true + false + none + leanclr\ + + + + + + + ../thirdparty/leanclr/src/libraries/dotnetframework4.x-linux/mscorlib.dll + + + ../thirdparty/leanclr/src/libraries/dotnetframework4.x-linux/System.dll + + + leanclr\GodotSharpCompat.dll + + + + diff --git a/project/LeanCLRGodot.sln b/project/LeanCLRGodot.sln new file mode 100644 index 0000000..31e3a4e --- /dev/null +++ b/project/LeanCLRGodot.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Game", "Game.csproj", "{6CE2F047-6391-4EE7-87A3-4AD33A189355}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6CE2F047-6391-4EE7-87A3-4AD33A189355}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CE2F047-6391-4EE7-87A3-4AD33A189355}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CE2F047-6391-4EE7-87A3-4AD33A189355}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CE2F047-6391-4EE7-87A3-4AD33A189355}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/project/icon.svg b/project/icon.svg new file mode 100644 index 0000000..c6bbb7d --- /dev/null +++ b/project/icon.svg @@ -0,0 +1 @@ + diff --git a/project/icon.svg.import b/project/icon.svg.import new file mode 100644 index 0000000..aa22be5 --- /dev/null +++ b/project/icon.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://i0yc5j7xuf21" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/project/leanclr.gdextension b/project/leanclr.gdextension new file mode 100644 index 0000000..0bd8cb4 --- /dev/null +++ b/project/leanclr.gdextension @@ -0,0 +1,14 @@ +[configuration] + +entry_symbol = "leanclr_godot_library_init" +compatibility_minimum = "4.4" +reloadable = true + +[libraries] + +windows.debug.x86_64 = "res://bin/Debug/leanclr_godot.dll" +windows.release.x86_64 = "res://bin/Release/leanclr_godot.dll" +linux.debug.x86_64 = "res://bin/Debug/libleanclr_godot.so" +linux.release.x86_64 = "res://bin/Release/libleanclr_godot.so" +macos.debug = "res://bin/Debug/libleanclr_godot.dylib" +macos.release = "res://bin/Release/libleanclr_godot.dylib" diff --git a/project/leanclr.gdextension.uid b/project/leanclr.gdextension.uid new file mode 100644 index 0000000..917757d --- /dev/null +++ b/project/leanclr.gdextension.uid @@ -0,0 +1 @@ +uid://sbyqrdhnol0s diff --git a/project/main.gd b/project/main.gd new file mode 100644 index 0000000..d9a125e --- /dev/null +++ b/project/main.gd @@ -0,0 +1,11 @@ +extends Node + +func _ready() -> void: + var script := ResourceLoader.load("res://hello.lcs") + if script == null: + push_error("Failed to load LeanCLR hello.lcs") + get_tree().quit(1) + return + + print("Loaded LeanCLR script: ", script.get_type_name()) + get_tree().quit() diff --git a/project/main.gd.uid b/project/main.gd.uid new file mode 100644 index 0000000..ee26465 --- /dev/null +++ b/project/main.gd.uid @@ -0,0 +1 @@ +uid://bkcd2d6cuaxfs diff --git a/project/main.tscn b/project/main.tscn new file mode 100644 index 0000000..2562e19 --- /dev/null +++ b/project/main.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=2 format=3 uid="uid://leanclr_godot_main"] + +[ext_resource type="Script" path="res://scripts/ScriptMain.cs" id="1_leanclr"] + +[node name="Main" type="LeanCLRMain"] + +[node name="ScriptLanguageDemo" type="Node2D" parent="."] +script = ExtResource("1_leanclr") + +[node name="Child" type="Node" parent="ScriptLanguageDemo"] + +[node name="UiLabel" type="Label" parent="ScriptLanguageDemo"] + +[node name="SpriteDemo" type="Sprite2D" parent="ScriptLanguageDemo"] + +[node name="Node3DDemo" type="Node3D" parent="ScriptLanguageDemo"] + +[node name="CpuParticles3DDemo" type="CPUParticles3D" parent="ScriptLanguageDemo"] + +[node name="Camera3DDemo" type="Camera3D" parent="ScriptLanguageDemo"] diff --git a/project/project.godot b/project/project.godot new file mode 100644 index 0000000..226137e --- /dev/null +++ b/project/project.godot @@ -0,0 +1,19 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[animation] + +compatibility/default_parent_skeleton_in_mesh_instance_3d=true + +[application] + +config/name="LeanCLR Godot" +run/main_scene="res://runtime_hot_reload_demo.tscn" +config/features=PackedStringArray("4.6") diff --git a/project/runtime_csharp_editor.tscn b/project/runtime_csharp_editor.tscn new file mode 100644 index 0000000..01e26e6 --- /dev/null +++ b/project/runtime_csharp_editor.tscn @@ -0,0 +1,39 @@ +[gd_scene format=3 uid="uid://dynd0csycincd"] + +[ext_resource type="Script" uid="uid://b626vql61yl6r" path="res://scripts/RuntimeCSharpEditor.gd" id="1_editor_script"] + +[node name="RuntimeCSharpEditor" type="Window" unique_id=440944382] +oversampling_override = 1.0 +title = "LeanCLR Runtime C# Editor" +position = Vector2i(560, 36) +size = Vector2i(760, 560) +visible = false +always_on_top = true +script = ExtResource("1_editor_script") + +[node name="RuntimeCSharpEditorPanel" type="VBoxContainer" parent="." unique_id=48727115] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="RuntimeCSharpTitle" type="Label" parent="RuntimeCSharpEditorPanel" unique_id=1798922565] +layout_mode = 2 +text = "HotReloadSmoke.cs" + +[node name="RuntimeCSharpCodeEdit" type="CodeEdit" parent="RuntimeCSharpEditorPanel" unique_id=2041813682] +unique_name_in_owner = true +custom_minimum_size = Vector2(720, 390) +layout_mode = 2 +size_flags_vertical = 3 + +[node name="RuntimeCSharpRunButton" type="Button" parent="RuntimeCSharpEditorPanel" unique_id=1963029537] +unique_name_in_owner = true +layout_mode = 2 +text = "Build + Execute Without Restart" + +[node name="RuntimeCSharpStatus" type="Label" parent="RuntimeCSharpEditorPanel" unique_id=32725415] +unique_name_in_owner = true +layout_mode = 2 +text = "Ready" diff --git a/project/runtime_hot_reload_demo.tscn b/project/runtime_hot_reload_demo.tscn new file mode 100644 index 0000000..3b17bdd --- /dev/null +++ b/project/runtime_hot_reload_demo.tscn @@ -0,0 +1,78 @@ +[gd_scene format=3 uid="uid://dom55c3dsfsh6"] + +[ext_resource type="Script" uid="uid://bo2r8gbx576k6" path="res://scripts/HotReloadSmoke.cs" id="1_flappy"] +[ext_resource type="Texture2D" uid="uid://i0yc5j7xuf21" path="res://icon.svg" id="2_icon"] +[ext_resource type="PackedScene" uid="uid://dynd0csycincd" path="res://runtime_csharp_editor.tscn" id="3_editor_scene"] +[ext_resource type="Script" uid="uid://dca5khgessig" path="res://scripts/HotReloadInputRelay.gd" id="4_input_relay"] + +[node name="RuntimeHotReloadDemo" type="Node2D" unique_id=1212946146] + +[node name="GameWorld" type="Node2D" parent="." unique_id=914199522] + +[node name="Sky" type="ColorRect" parent="GameWorld" unique_id=90320198] +offset_right = 540.0 +offset_bottom = 360.0 +color = Color(0.42, 0.78, 0.95, 1) + +[node name="CloudA" type="ColorRect" parent="GameWorld" unique_id=1619648798] +offset_left = 76.0 +offset_top = 44.0 +offset_right = 168.0 +offset_bottom = 66.0 +color = Color(0.92, 0.97, 1, 1) + +[node name="CloudB" type="ColorRect" parent="GameWorld" unique_id=329244074] +offset_left = 318.0 +offset_top = 74.0 +offset_right = 442.0 +offset_bottom = 98.0 +color = Color(0.92, 0.97, 1, 1) + +[node name="PipeTop" type="ColorRect" parent="GameWorld" unique_id=1793488116] +offset_left = 420.0 +offset_right = 480.0 +offset_bottom = 92.0 +color = Color(0.07, 0.63, 0.23, 1) + +[node name="PipeBottom" type="ColorRect" parent="GameWorld" unique_id=422849216] +offset_left = 420.0 +offset_top = 208.0 +offset_right = 480.0 +offset_bottom = 320.0 +color = Color(0.07, 0.63, 0.23, 1) + +[node name="Ground" type="ColorRect" parent="GameWorld" unique_id=581381780] +offset_top = 320.0 +offset_right = 540.0 +offset_bottom = 360.0 +color = Color(0.68, 0.48, 0.22, 1) + +[node name="Bird" type="TextureRect" parent="GameWorld" unique_id=225012823] +offset_left = 108.0 +offset_top = 130.0 +offset_right = 148.0 +offset_bottom = 170.0 +pivot_offset = Vector2(20, 20) +texture = ExtResource("2_icon") +expand_mode = 1 + +[node name="Hud" type="Node" parent="GameWorld" unique_id=441089907] + +[node name="DemoStatus" type="Label" parent="GameWorld/Hud" unique_id=204759433] +offset_left = 15.0 +offset_top = 328.0 +offset_right = 517.0 +offset_bottom = 374.0 +text = "Running flappy-physics-v1 | score=0 | y=146 | vy=0 | pipeX=420" + +[node name="FlappyScript" type="Node" parent="." unique_id=1458328663] +script = ExtResource("1_flappy") +FlapPower = 5 +Name = &"FlappyScript" + +[node name="LiveHotReloadHost" type="LeanCLRHotReloadHost" parent="." unique_id=465275025] + +[node name="HotReloadInputRelay" type="Node" parent="." unique_id=394620894] +script = ExtResource("4_input_relay") + +[node name="RuntimeCSharpEditor" parent="." unique_id=56462960 instance=ExtResource("3_editor_scene")] diff --git a/project/scripts/ClassDbMain.cs b/project/scripts/ClassDbMain.cs new file mode 100644 index 0000000..bdc5bcb --- /dev/null +++ b/project/scripts/ClassDbMain.cs @@ -0,0 +1,11 @@ +using Godot; + +namespace Game; + +public partial class ClassDbMain : Node +{ + public override void _Ready() + { + GD.Print("LeanCLR demo: ClassDB host owner name = " + Name); + } +} diff --git a/project/scripts/ClassDbMain.cs.uid b/project/scripts/ClassDbMain.cs.uid new file mode 100644 index 0000000..c37c2f3 --- /dev/null +++ b/project/scripts/ClassDbMain.cs.uid @@ -0,0 +1 @@ +uid://b5rn1ql6ugvjj diff --git a/project/scripts/HotReloadInputRelay.gd b/project/scripts/HotReloadInputRelay.gd new file mode 100644 index 0000000..e86f68e --- /dev/null +++ b/project/scripts/HotReloadInputRelay.gd @@ -0,0 +1,10 @@ +extends Node + +@onready var hot_reload_host: Node = get_node("../LiveHotReloadHost") + +func _ready() -> void: + set_process_input(true) + +func _input(event: InputEvent) -> void: + if hot_reload_host != null: + hot_reload_host.forward_input(event) diff --git a/project/scripts/HotReloadInputRelay.gd.uid b/project/scripts/HotReloadInputRelay.gd.uid new file mode 100644 index 0000000..b7f32a2 --- /dev/null +++ b/project/scripts/HotReloadInputRelay.gd.uid @@ -0,0 +1 @@ +uid://dca5khgessig diff --git a/project/scripts/HotReloadSmoke.cs b/project/scripts/HotReloadSmoke.cs new file mode 100644 index 0000000..bb1df68 --- /dev/null +++ b/project/scripts/HotReloadSmoke.cs @@ -0,0 +1,270 @@ +using Godot; + +namespace Game; + +public partial class HotReloadSmoke : Node +{ + private const string Version = "flappy-physics-v1"; + private const float WorldWidth = 540.0f; + private const float WorldHeight = 360.0f; + private const float GroundY = 320.0f; + private const float BirdX = 108.0f; + private const float BirdSize = 40.0f; + private const float Gravity = 960.0f; + private const float FlapVelocity = -330.0f; + private const float PipeSpeed = 170.0f; + private const float PipeWidth = 60.0f; + private const float GapHeight = 160.0f; + private const float ResetPipeX = 560.0f; + private const float PipeRecycleX = -80.0f; + private const int MinGapCenter = 118; + private const int MaxGapCenter = 235; + private static readonly Color AliveBirdColor = new Color(1.0f, 0.95f, 0.18f, 1.0f); + private static readonly Color GameOverBirdColor = new Color(1.0f, 0.32f, 0.22f, 1.0f); + + [Export(PropertyHint.Range, "1,10,1")] + public int FlapPower { get; set; } = 5; + + private float elapsed; + private float birdY; + private float velocityY; + private float pipeX; + private int gapCenter; + private int score; + private bool gameOver; + private bool passedPipe; + private bool processLogged; + private bool runtimeReloadedObject; + + public override void _Ready() + { + if (birdY <= 0.0f || pipeX <= 0.0f) + { + ResetGame(); + } + ApplyGameState(); + GD.Print("LeanCLR flappy reload: version = " + Version); + GD.Print("LeanCLR flappy reload: score = " + score.ToString()); + GD.Print("LeanCLR flappy reload: bird y = " + ((int)birdY).ToString()); + GD.Print("LeanCLR flappy reload: velocity y = " + ((int)velocityY).ToString()); + GD.Print("LeanCLR flappy reload: active marker = " + FileAccess.GetFileAsString("res://leanclr/live_reload.txt").Trim()); + } + + public override void _Input(InputEvent event_) + { + if (!IsGameplayObjectActive()) + { + return; + } + + if (event_ != null && event_.IsPressed() && !event_.IsEcho()) + { + ForceFlap(); + } + } + + public void ForceFlap() + { + if (gameOver) + { + ResetGame(); + GD.Print("LeanCLR flappy input: restart"); + return; + } + + velocityY = FlapVelocity - FlapPower * 10.0f; + GD.Print("LeanCLR flappy input: flap velocity = " + ((int)velocityY).ToString()); + } + + public Variant CaptureHotReloadState() + { + Dictionary state = new Dictionary(); + state[new Variant("elapsed")] = new Variant(elapsed); + state[new Variant("birdY")] = new Variant(birdY); + state[new Variant("velocityY")] = new Variant(velocityY); + state[new Variant("pipeX")] = new Variant(pipeX); + state[new Variant("gapCenter")] = new Variant(gapCenter); + state[new Variant("score")] = new Variant(score); + state[new Variant("gameOver")] = new Variant(gameOver); + state[new Variant("passedPipe")] = new Variant(passedPipe); + state[new Variant("processLogged")] = new Variant(processLogged); + GD.Print("LeanCLR hot reload state: captured score = " + score.ToString() + " y = " + ((int)birdY).ToString()); + return new Variant(state); + } + + public void RestoreHotReloadState(Variant stateVariant) + { + runtimeReloadedObject = true; + Dictionary state = stateVariant.AsDictionary(); + if (state != null) + { + elapsed = ReadFloat(state, "elapsed", elapsed); + birdY = ReadFloat(state, "birdY", birdY); + velocityY = ReadFloat(state, "velocityY", velocityY); + pipeX = ReadFloat(state, "pipeX", pipeX); + gapCenter = ReadInt(state, "gapCenter", gapCenter); + score = ReadInt(state, "score", score); + gameOver = ReadBool(state, "gameOver", gameOver); + passedPipe = ReadBool(state, "passedPipe", passedPipe); + processLogged = ReadBool(state, "processLogged", processLogged); + } + GD.Print("LeanCLR hot reload state: restored score = " + score.ToString() + " y = " + ((int)birdY).ToString()); + } + + public void OnHotReloaded() + { + runtimeReloadedObject = true; + ApplyGameState(); + GD.Print("LeanCLR hot reload state: active score after reload = " + score.ToString() + " y = " + ((int)birdY).ToString()); + } + + public override void _Process(double delta) + { + if (!IsGameplayObjectActive()) + { + return; + } + + float dt = Clamp((float)delta, 0.0f, 0.033f); + elapsed += dt; + + if (!gameOver) + { + velocityY += Gravity * dt; + birdY += velocityY * dt; + pipeX -= PipeSpeed * dt; + + if (pipeX < PipeRecycleX) + { + pipeX = ResetPipeX; + gapCenter = NextGapCenter(); + passedPipe = false; + } + + if (!passedPipe && pipeX + PipeWidth < BirdX) + { + passedPipe = true; + score++; + GD.Print("LeanCLR flappy score: " + score.ToString()); + } + + if (CheckCollision()) + { + gameOver = true; + GD.Print("LeanCLR flappy collision: game over score = " + score.ToString()); + } + } + + ApplyGameState(); + if (!processLogged) + { + processLogged = true; + GD.Print("LeanCLR flappy process: playable physics tick delta = " + delta.ToString()); + } + } + + private void ResetGame() + { + elapsed = 0.0f; + birdY = 146.0f; + velocityY = 0.0f; + pipeX = 420.0f; + gapCenter = 172; + score = 0; + gameOver = false; + passedPipe = false; + processLogged = false; + } + + private bool CheckCollision() + { + if (birdY < 0.0f || birdY + BirdSize > GroundY) + { + return true; + } + + bool overlapsPipeX = BirdX + BirdSize > pipeX && BirdX < pipeX + PipeWidth; + if (!overlapsPipeX) + { + return false; + } + + float gapTop = gapCenter - GapHeight * 0.5f; + float gapBottom = gapCenter + GapHeight * 0.5f; + return birdY < gapTop || birdY + BirdSize > gapBottom; + } + + private void ApplyGameState() + { + TextureRect bird = GetNodeOrNull("../GameWorld/Bird"); + ColorRect pipeTop = GetNodeOrNull("../GameWorld/PipeTop"); + ColorRect pipeBottom = GetNodeOrNull("../GameWorld/PipeBottom"); + Label title = GetNodeOrNull