Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ jobs:
include:
- name: Linux
runner-os: ubuntu-latest
godot-release: 4.4-stable/Godot_v4.4-stable_linux.x86_64.zip
godot-bin: ./Godot_v4.4-stable_linux.x86_64
godot-release: 4.4.1-stable/Godot_v4.4.1-stable_linux.x86_64.zip
godot-bin: ./Godot_v4.4.1-stable_linux.x86_64
- name: Linux (arm64)
runner-os: ubuntu-24.04-arm
godot-release: 4.4-stable/Godot_v4.4-stable_linux.arm64.zip
godot-bin: ./Godot_v4.4-stable_linux.arm64
godot-release: 4.4.1-stable/Godot_v4.4.1-stable_linux.arm64.zip
godot-bin: ./Godot_v4.4.1-stable_linux.arm64
- name: Windows
runner-os: windows-latest
godot-release: 4.4-stable/Godot_v4.4-stable_win64.exe.zip
godot-bin: ./Godot_v4.4-stable_win64.exe
godot-release: 4.4.1-stable/Godot_v4.4.1-stable_win64.exe.zip
godot-bin: ./Godot_v4.4.1-stable_win64.exe
- name: Windows (arm64)
runner-os: windows-11-arm
godot-release: 4.4-stable/Godot_v4.4-stable_windows_arm64.exe.zip
godot-bin: ./Godot_v4.4-stable_windows_arm64.exe
godot-release: 4.4.1-stable/Godot_v4.4.1-stable_windows_arm64.exe.zip
godot-bin: ./Godot_v4.4.1-stable_windows_arm64.exe
- name: macOS
runner-os: macos-latest
godot-release: 4.4-stable/Godot_v4.4-stable_macos.universal.zip
godot-release: 4.4.1-stable/Godot_v4.4.1-stable_macos.universal.zip
godot-bin: ./Godot.app/Contents/MacOS/Godot
env:
GODOT_BIN: ${{ matrix.godot-bin }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog
## [Unreleased](https://github.com/gilzoide/lua-gdextension/compare/0.6.0...HEAD)
### Changed
- Opening `GODOT_CLASSES` now registers all classes at once instead of setting up a lazy getter in `_G`'s metatable
- Opening `GODOT_SINGLETONS` now registers all singletons at once instead of setting up a lazy getter in `_G`'s metatable



## [0.6.0](https://github.com/gilzoide/lua-gdextension/releases/tag/0.6.0)
Expand Down
4 changes: 2 additions & 2 deletions doc_classes/LuaState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,15 @@
[b]Note: This may override some Lua functions like [code]print[/code].[/b]
</constant>
<constant name="GODOT_SINGLETONS" value="32768" enum="Library" is_bitfield="true">
Godot singletons library.
Godot singletons library. Adds global singletons like [Engine] and [ResourceLoader] to _G.
</constant>
<constant name="GODOT_CLASSES" value="65536" enum="Library" is_bitfield="true">
Godot classes library. Adds Godot classes like [Node] to _G.
[codeblocks]
[gdscript]
var lua_state = LuaState.new()
lua_state.open_libraries(LuaState.Library.LUA_BASE | LuaState.Library.GODOT_CLASSES)
var vec3 = lua_state.do_string("""
var node = lua_state.do_string("""
-- Create a Node in Lua
local node = Node:new()
return node
Expand Down
8 changes: 3 additions & 5 deletions src/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "LuaTable.hpp"
#include "LuaThread.hpp"
#include "luaopen/godot.hpp"
#include "utils/_G_metatable.hpp"
#include "utils/convert_godot_lua.hpp"
#include "utils/module_names.hpp"

Expand Down Expand Up @@ -75,7 +74,6 @@ LuaState::LuaState()
: lua_state(lua_panic_handler, lua_alloc)
#endif
{
setup_G_metatable(lua_state);
#ifdef HAVE_LUA_WARN
lua_setwarnf(lua_state, lua_warn_handler, this);
#endif
Expand Down Expand Up @@ -153,12 +151,12 @@ void LuaState::open_libraries(BitField<Library> libraries) {
if (libraries.has_flag(GODOT_UTILITY_FUNCTIONS)) {
lua_state.require(module_names::utility_functions, &luaopen_godot_utility_functions, false);
}
if (libraries.has_flag(GODOT_SINGLETONS)) {
lua_state.require(module_names::singleton_access, &luaopen_godot_singleton_access, false);
}
if (libraries.has_flag(GODOT_CLASSES)) {
lua_state.require(module_names::classes, &luaopen_godot_classes, false);
}
if (libraries.has_flag(GODOT_SINGLETONS)) {
lua_state.require(module_names::singleton_access, &luaopen_godot_singleton_access, false);
}
if (libraries.has_flag(GODOT_ENUMS)) {
lua_state.require(module_names::enums, &luaopen_godot_enums, false);
}
Expand Down
9 changes: 5 additions & 4 deletions src/luaopen/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "../utils/Class.hpp"
#include "../utils/module_names.hpp"

#include <sol/sol.hpp>
#include <godot_cpp/classes/class_db_singleton.hpp>

using namespace luagdextension;

extern "C" int luaopen_godot_classes(lua_State *L) {
sol::state_view state = L;

state.registry()[module_names::classes] = true;
Class::register_usertype(state);
ClassDBSingleton *classdb = ClassDBSingleton::get_singleton();
for (auto&& class_name : classdb->get_class_list()) {
state.set(class_name.ascii().get_data(), Class(class_name));
}

return 0;
}
2 changes: 1 addition & 1 deletion src/luaopen/godot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extern "C" int luaopen_godot(lua_State *L) {

state.require(module_names::variant, &luaopen_godot_variant, false);
state.require(module_names::utility_functions, &luaopen_godot_utility_functions, false);
state.require(module_names::singleton_access, &luaopen_godot_singleton_access, false);
state.require(module_names::classes, &luaopen_godot_classes, false);
state.require(module_names::singleton_access, &luaopen_godot_singleton_access, false);
state.require(module_names::enums, &luaopen_godot_enums, false);
state.require(module_names::local_paths, &luaopen_godot_local_paths, false);

Expand Down
16 changes: 8 additions & 8 deletions src/luaopen/singleton_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "../utils/custom_sol.hpp"

#include "../utils/module_names.hpp"
#include <godot_cpp/classes/engine.hpp>

#include <sol/sol.hpp>

using namespace luagdextension;
using namespace godot;

extern "C" int luaopen_godot_singleton_access(lua_State *L) {
sol::state_view state = L;

state.registry()[module_names::singleton_access] = true;

sol::state_view state(L);
Engine *engine = Engine::get_singleton();
for (auto&& singleton_name : engine->get_singleton_list()) {
state.set(singleton_name.ascii().get_data(), engine->get_singleton(singleton_name));
}
return 0;
}
67 changes: 0 additions & 67 deletions src/utils/_G_metatable.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions src/utils/_G_metatable.hpp

This file was deleted.

9 changes: 5 additions & 4 deletions test/test_entrypoint.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const LUA_TEST_DIR = "res://lua_tests"
const GDSCRIPT_TEST_DIR = "res://gdscript_tests"

func _initialize():
var all_success = true
var error_count = 0

print("Starting Lua GDExtension tests (runtime: ", LuaState.get_lua_runtime(), ")")
for lua_script in DirAccess.get_files_at(LUA_TEST_DIR):
Expand All @@ -16,7 +16,7 @@ func _initialize():
var file_name = str(LUA_TEST_DIR, "/", lua_script)
var result = lua_state.do_file(file_name)
if result is LuaError:
all_success = false
error_count += 1
print("! ", lua_script)
push_error(result.message)
else:
Expand All @@ -38,11 +38,12 @@ func _initialize():
obj._setup()
# actual test
if not obj.call(method_name):
all_success = false
error_count += 1
printerr(" ! ", method_name)
else:
print(" ✓ ", method_name)
if obj is Node:
obj.queue_free()

quit(0 if all_success else -1)
print("\nFailed tests: ", error_count)
quit(0 if error_count == 0 else -1)
Loading