Skip to content

Commit

Permalink
Bump to godot 4.2-stable (#180)
Browse files Browse the repository at this point in the history
* Needed changes for godot-cpp#1280

* Bump to godot 4.2-stable
  • Loading branch information
Trey2k committed Nov 30, 2023
1 parent a7c659a commit 8de338b
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 129 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:
- "project/demo/*"

env:
GODOT_VERSION: 4.1.2
GODOT_VERSION: 4.2

jobs:
static-checks:
Expand All @@ -37,31 +37,31 @@ jobs:
uses: ./.github/workflows/linux.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

macos-build:
name: 🍎 macOS
needs: static-checks
uses: ./.github/workflows/macos-build.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

macos-package:
name: 🍎 macOS Package
needs: macos-build
uses: ./.github/workflows/macos-package.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

android-build:
name: 🤖 Android
needs: static-checks
uses: ./.github/workflows/android-build.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

android-package:
name: 🤖 Android Package
Expand All @@ -75,7 +75,7 @@ jobs:
uses: ./.github/workflows/ios-build.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

ios-package:
name: 🍎 IOS Package
Expand All @@ -89,23 +89,23 @@ jobs:
uses: ./.github/workflows/web.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

windows-build:
name: 🎨 Windows
needs: static-checks
uses: ./.github/workflows/windows.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

gdextension-build:
name: ⚙️ GDExtension
needs: static-checks
uses: ./.github/workflows/gdextension.yml
with:
fullbuild: ${{ github.event_name == 'workflow_dispatch' }}
godot_version: 4.1.2
godot_version: 4.2

module-unit-tests:
name: ⚙️ Module Unit Tests
Expand All @@ -117,7 +117,7 @@ jobs:
needs: gdextension-build
uses: ./.github/workflows/gdextension-unit-tests.yml
with:
godot_version: 4.1.2
godot_version: 4.2

template-version-file:
name: 📝 Create template version file
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
branch = c4b71b7b
[submodule "external/godot-cpp"]
path = external/godot-cpp
url = https://github.com/Trey2k/godot-cpp
branch = 4.0
url = https://github.com/godotengine/godot-cpp.git
branch = 4.2
9 changes: 0 additions & 9 deletions doc_classes/LuaAPI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@
Calls a function inside current Lua state. This can be either a exposed function or a function defined with with Lua. You may want to check if the function actually exists with [code]function_exists(LuaFunctionName)[/code]. This function supports 1 return value from lua. It will be returned as a variant and if Lua returns no value it will be null. If an error occurs while calling this function, a LuaError object will be returned.
</description>
</method>
<method name="call_function_ref">
<return type="Variant" />
<param index="0" name="Args" type="Array" />
<param index="1" name="LuaFunctionRef" type="int" />
<description>
This method is used to create a Callable when pulling a lua function from the stack. It is not intended to be called directly.
When returning a Callable, the function ref is bound to the Callable. You must only supply the arguments.
</description>
</method>
<method name="pull_variant">
<return type="Variant" />
<param index="0" name="Name" type="String" />
Expand Down
2 changes: 1 addition & 1 deletion external/godot-cpp
Submodule godot-cpp updated 61 files
+34 −14 .github/workflows/ci.yml
+1 −1 .github/workflows/static_checks.yml
+5 −1 .gitignore
+23 −8 CMakeLists.txt
+27 −17 README.md
+16 −222 SConstruct
+227 −100 binding_generator.py
+11,940 −2,657 gdextension/extension_api.json
+336 −16 gdextension/gdextension_interface.h
+62 −0 include/godot_cpp/classes/editor_plugin_registration.hpp
+1 −1 include/godot_cpp/classes/ref.hpp
+204 −113 include/godot_cpp/classes/wrapped.hpp
+90 −0 include/godot_cpp/core/binder_common.hpp
+29 −19 include/godot_cpp/core/class_db.hpp
+13 −12 include/godot_cpp/core/memory.hpp
+2 −0 include/godot_cpp/core/method_ptrcall.hpp
+3 −22 include/godot_cpp/core/object.hpp
+62 −0 include/godot_cpp/core/object_id.hpp
+12 −0 include/godot_cpp/core/property_info.hpp
+34 −12 include/godot_cpp/godot.hpp
+21 −11 include/godot_cpp/templates/cowdata.hpp
+1 −1 include/godot_cpp/templates/list.hpp
+3 −3 include/godot_cpp/templates/rid_owner.hpp
+4 −4 include/godot_cpp/templates/thread_work_pool.hpp
+64 −0 include/godot_cpp/variant/callable_custom.hpp
+248 −0 include/godot_cpp/variant/callable_method_pointer.hpp
+79 −50 include/godot_cpp/variant/char_string.hpp
+21 −8 include/godot_cpp/variant/variant.hpp
+8 −0 include/godot_cpp/variant/vector3.hpp
+8 −0 include/godot_cpp/variant/vector3i.hpp
+8 −0 include/godot_cpp/variant/vector4.hpp
+8 −0 include/godot_cpp/variant/vector4i.hpp
+3 −3 src/classes/editor_plugin_registration.cpp
+79 −0 src/classes/wrapped.cpp
+28 −13 src/core/class_db.cpp
+8 −7 src/core/memory.cpp
+132 −39 src/godot.cpp
+113 −0 src/variant/callable_custom.cpp
+114 −0 src/variant/callable_method_pointer.cpp
+114 −100 src/variant/char_string.cpp
+22 −4 src/variant/variant.cpp
+16 −1 test/CMakeLists.txt
+11 −0 test/SConstruct
+7 −0 test/generate_xcframework.sh
+0 −0 test/project/bin/libgdexample.macos.template_debug.framework/Resources/Info.plist
+0 −0 test/project/bin/libgdexample.macos.template_release.framework/Resources/Info.plist
+19 −1 test/project/example.gdextension
+126 −0 test/project/main.gd
+2 −1 test/project/project.godot
+240 −0 test/src/example.cpp
+43 −0 test/src/example.h
+25 −13 tools/android.py
+361 −0 tools/godotcpp.py
+32 −7 tools/ios.py
+0 −26 tools/ios_osxcross.py
+5 −0 tools/linux.py
+28 −6 tools/macos.py
+0 −28 tools/macos_osxcross.py
+67 −15 tools/targets.py
+23 −24 tools/web.py
+31 −11 tools/windows.py
2 changes: 1 addition & 1 deletion project/addons/luaAPI/luaAPI.gdextension
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[configuration]
entry_symbol = "luaAPI_library_init"
compatibility_minimum = 4.1
compatibility_minimum = 4.2

[libraries]
linux.x86_64.debug = "bin/libluaapi.linux.template_debug.x86_64.so"
Expand Down
2 changes: 1 addition & 1 deletion project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ config_version=5

config/name="LuaAPI Test Project"
run/main_scene="res://testing/run_tests.tscn"
config/features=PackedStringArray("4.1", "Mobile")
config/features=PackedStringArray("4.2", "Mobile")

[autoload]

Expand Down
2 changes: 1 addition & 1 deletion project/testing/tests/LuaAPI.call_function.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func _process(delta):
errors.append(LuaError.new_error("testCallable is not Callable but is '%d'" % typeof(testCallable), LuaError.ERR_TYPE))
return fail()

var cret = testCallable.call([5])
var cret = testCallable.call(5)
if cret is LuaError:
errors.append(cret)
return fail()
Expand Down
30 changes: 0 additions & 30 deletions src/classes/luaAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ void LuaAPI::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_registry_value", "Name"), &LuaAPI::getRegistryValue);
ClassDB::bind_method(D_METHOD("set_registry_value", "Name", "var"), &LuaAPI::setRegistryValue);
ClassDB::bind_method(D_METHOD("call_function", "LuaFunctionName", "Args"), &LuaAPI::callFunction);
#ifdef LAPI_GDEXTENSION
ClassDB::bind_method(D_METHOD("call_function_ref", "Args", "LuaFunctionRef"), &LuaAPI::callFunctionRef);
#endif
ClassDB::bind_method(D_METHOD("function_exists", "LuaFunctionName"), &LuaAPI::luaFunctionExists);

ClassDB::bind_method(D_METHOD("new_coroutine"), &LuaAPI::newCoroutine);
Expand Down Expand Up @@ -137,33 +134,6 @@ Variant LuaAPI::callFunction(String functionName, Array args) {
return state.callFunction(functionName, args);
}

#ifdef LAPI_GDEXTENSION
// Invokes the passed lua reference
Variant LuaAPI::callFunctionRef(Array args, int funcRef) {
lua_pushcfunction(lState, LuaState::luaErrorHandler);

// Getting the lua function via the reference stored in funcRef
lua_rawgeti(lState, LUA_REGISTRYINDEX, funcRef);

// Push all the argument on to the stack
for (int i = 0; i < args.size(); i++) {
LuaState::pushVariant(lState, args[i]);
}

Variant toReturn;
// execute the function using a protected call.
int ret = lua_pcall(lState, args.size(), 1, -2 - args.size());
if (ret != LUA_OK) {
toReturn = LuaState::handleError(lState, ret);
} else {
toReturn = LuaState::getVariant(lState, -1);
}

lua_pop(lState, 1);
return toReturn;
}
#endif

// Calls LuaState::pushGlobalVariant()
Ref<LuaError> LuaAPI::pushGlobalVariant(String name, Variant var) {
return state.pushGlobalVariant(name, var);
Expand Down
3 changes: 0 additions & 3 deletions src/classes/luaAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class LuaAPI : public RefCounted {

Variant pullVariant(String name);
Variant callFunction(String functionName, Array args);
#ifdef LAPI_GDEXTENSION
Variant callFunctionRef(Array args, int funcRef);
#endif

Variant getRegistryValue(String name);

Expand Down
49 changes: 23 additions & 26 deletions src/classes/luaCallable.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#ifndef LAPI_GDEXTENSION

#include "luaCallable.h"
#include "luaAPI.h"

#ifndef LAPI_GDEXTENSION
#include "core/templates/hashfuncs.h"
#else
#include <gdextension_interface.h>
#include <godot_cpp/templates/hashfuncs.hpp>
#endif

// I used "GDScriptLambdaCallable" as a template for this
LuaCallable::LuaCallable(Ref<LuaAPI> p_obj, int ref, lua_State *p_state) {
obj = p_obj;
LuaCallable::LuaCallable(Ref<LuaAPI> obj, int ref, lua_State *p_state) {
objectID = obj->get_instance_id();
funcRef = ref;
state = p_state;
h = (uint32_t)hash_djb2_one_64((uint64_t)this);
Expand Down Expand Up @@ -36,7 +39,7 @@ CallableCustom::CompareLessFunc LuaCallable::get_compare_less_func() const {
}

ObjectID LuaCallable::get_object() const {
return obj->get_instance_id();
return objectID;
}

String LuaCallable::get_as_text() const {
Expand All @@ -53,31 +56,20 @@ uint32_t LuaCallable::hash() const {
return h;
}

void LuaCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const {
bool LuaCallable::is_valid() const {
return ObjectDB::get_instance(objectID);
}

void LuaCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, LAPI_CALL_ERROR &r_call_error) const {
lua_pushcfunction(state, LuaState::luaErrorHandler);

// Getting the lua function via the reference stored in funcRef
lua_rawgeti(state, LUA_REGISTRYINDEX, funcRef);

// ------------------
// This is a hack to match the API with the GDExtension Callable workaround
if (p_argcount != 1 || p_arguments[0]->get_type() != Variant::Type::ARRAY) {
r_return_value = LuaError::newError("LuaCallable arguments must be supplied with a Godot Array", LuaError::ERR_TYPE);
return;
}

Array args = p_arguments[0]->operator Array();
for (int i = 0; i < args.size(); i++) {
LuaState::pushVariant(state, args[i]);
}

p_argcount = args.size();
// ------------------

// Push all the argument on to the stack
// for (int i = 0; i < p_argcount; i++) {
// LuaState::pushVariant(state, *p_arguments[i]);
// }
for (int i = 0; i < p_argcount; i++) {
LuaState::pushVariant(state, *p_arguments[i]);
}

// execute the function using a protected call.
int ret = lua_pcall(state, p_argcount, 1, -2 - p_argcount);
Expand All @@ -88,9 +80,14 @@ void LuaCallable::call(const Variant **p_arguments, int p_argcount, Variant &r_r
}

lua_pop(state, 1);
// TODO: Tie the error handling systems together?
#ifndef LAPI_GDEXTENSION
r_call_error.error = LAPI_CALL_ERROR::CALL_OK;
#else
r_call_error.error = GDExtensionCallErrorType::GDEXTENSION_CALL_OK;
#endif
}

int LuaCallable::getFuncRef() {
return funcRef;
}
#endif
}
44 changes: 26 additions & 18 deletions src/classes/luaCallable.h
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
#ifndef LAPI_GDEXTENSION

#ifndef LUACALLABLE_H
#define LUACALLABLE_H

#ifndef LAPI_GDEXTENSION
#include "core/object/ref_counted.h"
#include "core/variant/callable.h"
#else
#include <godot_cpp/classes/ref.hpp>
#include <godot_cpp/variant/callable_custom.hpp>
#endif

#include <classes/luaAPI.h>

#include <lua/lua.hpp>

#ifdef LAPI_GDEXTENSION
using namespace godot;
#define LAPI_CALL_ERROR GDExtensionCallError
#else
#define LAPI_CALL_ERROR Callable::CallError
#endif

class LuaCallable : public CallableCustom {
static bool compare_equal(const CallableCustom *p_a, const CallableCustom *p_b);
static bool compare_less(const CallableCustom *p_a, const CallableCustom *p_b);
uint32_t h;

public:
uint32_t hash() const override;
String get_as_text() const override;
CompareEqualFunc get_compare_equal_func() const override;
CompareLessFunc get_compare_less_func() const override;
ObjectID get_object() const override;
lua_State *getLuaState() const;
void call(const Variant **p_argument, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const override;
LuaCallable(Ref<LuaAPI> obj, int ref, lua_State *p_state);
virtual ~LuaCallable() override;

int getFuncRef();
virtual uint32_t hash() const override;
virtual String get_as_text() const override;
virtual CompareEqualFunc get_compare_equal_func() const override;
virtual CompareLessFunc get_compare_less_func() const override;

LuaCallable(Ref<LuaAPI> obj, int ref, lua_State *p_state);
~LuaCallable() override;
virtual ObjectID get_object() const override;

virtual void call(const Variant **p_argument, int p_argcount, Variant &r_return_value, LAPI_CALL_ERROR &r_call_error) const override;
virtual bool is_valid() const override;

int getFuncRef();
lua_State *getLuaState() const;

private:
int funcRef;
Ref<LuaAPI> obj;
ObjectID objectID;
lua_State *state = nullptr;
uint32_t h;

static bool compare_equal(const CallableCustom *p_a, const CallableCustom *p_b);
static bool compare_less(const CallableCustom *p_a, const CallableCustom *p_b);
};

#endif
#endif
Loading

0 comments on commit 8de338b

Please sign in to comment.