Skip to content

Commit

Permalink
Needed changes for godot-cpp#1280
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey2k committed Nov 17, 2023
1 parent e9129f2 commit f3786e9
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
BASE_BRANCH: main
SCONSFLAGS: "production=yes extra_suffix=luaAPI"
SCONS_CACHE_LIMIT: 7168
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}

jobs:
android-builds:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gdextension-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Download godot ${{ inputs.godot_version }}
run: wget -O godot.zip https://downloads.tuxfamily.org/godotengine/${{ inputs.godot_version }}/Godot_v${{ inputs.godot_version }}-stable_linux.x86_64.zip
run: wget -O godot.zip https://github.com/godotengine/godot-builds/releases/download/4.2-beta2/Godot_v4.2-beta2_linux.x86_64.zip
- name: Extract godot
run: |
7z x godot.zip
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Download godot ${{ inputs.godot_version }}
run: wget -O godot.zip https://downloads.tuxfamily.org/godotengine/${{ inputs.godot_version }}/Godot_v${{ inputs.godot_version }}-stable_linux.x86_64.zip
run: wget -O godot.zip https://github.com/godotengine/godot-builds/releases/download/4.2-beta2/Godot_v4.2-beta2_linux.x86_64.zip
- name: Extract godot
run: |
7z x godot.zip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gdextension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

env:
BASE_BRANCH: main
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}

jobs:
gdextension:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ios-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
BASE_BRANCH: main
SCONSFLAGS: "production=yes extra_suffix=luaAPI"
SCONS_CACHE_LIMIT: 7168
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}

jobs:
ios-builds:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
BASE_BRANCH: main
SCONSFLAGS: "production=yes extra_suffix=luaAPI"
SCONS_CACHE_LIMIT: 7168
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}

jobs:
linux-builds:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
BASE_BRANCH: main
SCONSFLAGS: "production=yes extra_suffix=luaAPI"
SCONS_CACHE_LIMIT: 7168
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}

jobs:
macos-builds:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: godotengine/godot
ref: ${{ inputs.godot_version }}-stable
ref: ${{ inputs.godot_version }}
path: scripts/godot

- name: Download Artifact
Expand Down
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: master

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: master

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: master

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: master

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: master

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: master

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: master

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: master

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: master

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: master

template-version-file:
name: 📝 Create template version file
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:
BASE_BRANCH: main
SCONSFLAGS: "production=yes extra_suffix=luaAPI optimize=size"
SCONS_CACHE_LIMIT: 7168
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}
EM_VERSION: 3.1.18
EM_CACHE_FOLDER: "emsdk-cache"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
BASE_BRANCH: main
SCONSFLAGS: "production=yes extra_suffix=luaAPI"
SCONS_CACHE_LIMIT: 7168
GODOT_VERSION: ${{ inputs.godot_version }}-stable
GODOT_VERSION: ${{ inputs.godot_version }}

jobs:
windows-builds:
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/dsnopek/godot-cpp.git
branch = callable-custom
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 57 files
+25 −6 .github/workflows/ci.yml
+1 −1 .github/workflows/static_checks.yml
+1 −1 .gitignore
+21 −5 CMakeLists.txt
+26 −17 README.md
+16 −222 SConstruct
+214 −95 binding_generator.py
+11,796 −2,521 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
+131 −44 include/godot_cpp/classes/wrapped.hpp
+90 −0 include/godot_cpp/core/binder_common.hpp
+29 −19 include/godot_cpp/core/class_db.hpp
+1 −1 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
+9 −5 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
+212 −0 include/godot_cpp/variant/callable_method_pointer.hpp
+79 −50 include/godot_cpp/variant/char_string.hpp
+8 −7 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
+73 −0 src/classes/wrapped.cpp
+28 −13 src/core/class_db.cpp
+2 −2 src/core/memory.cpp
+63 −20 src/godot.cpp
+113 −0 src/variant/callable_custom.cpp
+62 −0 src/variant/callable_method_pointer.cpp
+114 −100 src/variant/char_string.cpp
+6 −4 src/variant/variant.cpp
+16 −1 test/CMakeLists.txt
+3 −1 test/project/example.gdextension
+100 −0 test/project/main.gd
+1 −1 test/project/project.godot
+225 −0 test/src/example.cpp
+36 −0 test/src/example.h
+22 −8 tools/android.py
+342 −0 tools/godotcpp.py
+31 −6 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
}
Loading

0 comments on commit f3786e9

Please sign in to comment.