Skip to content

Commit 1777e36

Browse files
committed
Merge branch 'main' into feature/luajit
2 parents a0f6f47 + cbe221b commit 1777e36

File tree

7 files changed

+109
-4
lines changed

7 files changed

+109
-4
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
jobs:
1212
build_linux:
1313
name: ${{ matrix.platform }} (${{ matrix.arch }}, ${{ matrix.target }}, ${{ matrix.luajit && 'luajit' || 'lua' }})
14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.runner || 'ubuntu-latest' }}
1515
strategy:
1616
fail-fast: false
1717
matrix:
@@ -23,15 +23,16 @@ jobs:
2323
- platform: linux
2424
arch: x86_32
2525
packages: [g++-multilib]
26+
- platform: linux
27+
arch: arm64
28+
runner: ubuntu-24.04-arm
2629
- platform: android
2730
arch: x86_32
2831
packages: [g++-multilib]
2932
- platform: android
3033
arch: arm32
3134
packages: [g++-multilib]
3235
exclude:
33-
- platform: linux
34-
arch: arm64
3536
- platform: linux
3637
arch: arm32
3738
steps:
@@ -192,6 +193,10 @@ jobs:
192193
runner-os: ubuntu-latest
193194
godot-release: 4.4-stable/Godot_v4.4-stable_linux.x86_64.zip
194195
godot-bin: ./Godot_v4.4-stable_linux.x86_64
196+
- name: Linux (arm64)
197+
runner-os: ubuntu-24.04-arm
198+
godot-release: 4.4-stable/Godot_v4.4-stable_linux.arm64.zip
199+
godot-bin: ./Godot_v4.4-stable_linux.arm64
195200
- name: Windows
196201
runner-os: windows-latest
197202
godot-release: 4.4-stable/Godot_v4.4-stable_win64.exe.zip

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# Changelog
22
## [Unreleased](https://github.com/gilzoide/lua-gdextension/compare/0.4.0...HEAD)
3+
### Added
4+
- Support for Linux arm64
5+
- `LuaTable.get_metatable` and `LuaTable.set_metatable` methods
36

47

58
## [0.4.0](https://github.com/gilzoide/lua-gdextension/releases/tag/0.4.0)
69
### Added
710
- `LuaCoroutine.completed` and `LuaCoroutine.failed` signals
811
- `await` function similar to GDScript's, allowing coroutines to yield and resume automatically when a signal is emitted
912
- Support for Web exports
10-
- Support Windows arm64 exports
13+
- Support for Windows arm64
1114
- Support for calling static methods from Godot classes, like `FileAccess.open`
1215
- Custom [Lua 5.4+ warning function](https://www.lua.org/manual/5.4/manual.html#lua_setwarnf) that sends messages to `push_warning`
1316
- `LuaThread` class as a superclass for `LuaCoroutine`.

addons/lua-gdextension/luagdextension.gdextension

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ linux.debug.x86_32 = "build/libluagdextension.linux.template_debug.x86_32.so"
1818
linux.release.x86_32 = "build/libluagdextension.linux.template_release.x86_32.so"
1919
linux.debug.x86_64 = "build/libluagdextension.linux.template_debug.x86_64.so"
2020
linux.release.x86_64 = "build/libluagdextension.linux.template_release.x86_64.so"
21+
linux.debug.arm64 = "build/libluagdextension.linux.template_debug.arm64.so"
22+
linux.release.arm64 = "build/libluagdextension.linux.template_release.arm64.so"
2123
android.debug.x86_32 = "build/libluagdextension.android.template_debug.x86_32.so"
2224
android.release.x86_32 = "build/libluagdextension.android.template_release.x86_32.so"
2325
android.debug.x86_64 = "build/libluagdextension.android.template_debug.x86_64.so"

doc_classes/LuaTable.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
[/codeblocks]
3939
</description>
4040
</method>
41+
<method name="get_metatable" qualifiers="const">
42+
<return type="LuaTable" />
43+
<description>
44+
Returns this table's metatable.
45+
See [url]https://www.lua.org/manual/5.4/manual.html#2.4[/url]
46+
</description>
47+
</method>
4148
<method name="length" qualifiers="const">
4249
<return type="int" />
4350
<description>
@@ -101,6 +108,14 @@
101108
[/codeblocks]
102109
</description>
103110
</method>
111+
<method name="set_metatable">
112+
<return type="void" />
113+
<param index="0" name="metatable" type="LuaTable" />
114+
<description>
115+
Set a new metatable for this table.
116+
See [url]https://www.lua.org/manual/5.4/manual.html#2.4[/url]
117+
</description>
118+
</method>
104119
<method name="to_array" qualifiers="const">
105120
<return type="Array" />
106121
<description>

src/LuaTable.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ Array LuaTable::to_array() const {
108108
return luagdextension::to_array(lua_object);
109109
}
110110

111+
Ref<LuaTable> LuaTable::get_metatable() const {
112+
if (sol::optional<sol::table> metatable = lua_object[sol::metatable_key]) {
113+
return LuaObject::wrap_object<LuaTable>(*metatable);
114+
}
115+
else {
116+
return nullptr;
117+
}
118+
}
119+
120+
void LuaTable::set_metatable(LuaTable *metatable) {
121+
lua_object[sol::metatable_key] = metatable ? metatable->get_table() : sol::nil;
122+
}
123+
111124
bool LuaTable::_iter_init(const Variant& iter) const {
112125
StackTopChecker topcheck(lua_object.lua_state());
113126
lua_State *L = lua_object.lua_state();
@@ -172,6 +185,9 @@ void LuaTable::_bind_methods() {
172185
ClassDB::bind_method(D_METHOD("to_dictionary"), &LuaTable::to_dictionary);
173186
ClassDB::bind_method(D_METHOD("to_array"), &LuaTable::to_array);
174187

188+
ClassDB::bind_method(D_METHOD("get_metatable"), &LuaTable::get_metatable);
189+
ClassDB::bind_method(D_METHOD("set_metatable", "metatable"), &LuaTable::set_metatable);
190+
175191
ClassDB::bind_method(D_METHOD("_iter_init", "iter"), &LuaTable::_iter_init);
176192
ClassDB::bind_method(D_METHOD("_iter_next", "iter"), &LuaTable::_iter_next);
177193
ClassDB::bind_method(D_METHOD("_iter_get", "iter"), &LuaTable::_iter_get);

src/LuaTable.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class LuaTable : public LuaObjectSubclass<sol::table> {
5353
Dictionary to_dictionary() const;
5454
Array to_array() const;
5555

56+
Ref<LuaTable> get_metatable() const;
57+
void set_metatable(LuaTable *metatable);
58+
5659
bool _iter_init(const Variant& iter) const;
5760
bool _iter_next(const Variant& iter) const;
5861
Variant _iter_get(const Variant& iter) const;

test/gdscript_tests/LuaTable.gd

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,64 @@ func test_dont_unpack_other_state() -> bool:
111111
var t_type = other_state.do_string("return type(t)")
112112
assert(t_type == "userdata", "Table should remain as Variant when passed to another LuaState")
113113
return true
114+
115+
116+
func test_setgetmetatable() -> bool:
117+
var table = lua_state.create_table()
118+
assert(table.get_metatable() == null)
119+
assert(table.get_metatable() == lua_state.globals.getmetatable.invoke(table))
120+
121+
var metatable = lua_state.create_table()
122+
table.set_metatable(metatable)
123+
assert(table.get_metatable() == metatable)
124+
assert(table.get_metatable() == lua_state.globals.getmetatable.invoke(table))
125+
126+
table.set_metatable(null)
127+
assert(table.get_metatable() == null)
128+
assert(table.get_metatable() == lua_state.globals.getmetatable.invoke(table))
129+
return true
130+
131+
132+
func test_to_dictionary_pairs() -> bool:
133+
var table = lua_state.do_string("""
134+
local function iterate_index_then_self(t)
135+
-- iteration over `t` metatable's __index table, if there's any
136+
local mt = getmetatable(t)
137+
if mt and type(mt.__index) == "table" then
138+
for k, v in pairs(mt.__index) do
139+
coroutine.yield(k, v)
140+
end
141+
end
142+
143+
-- now iterate over `t` normally
144+
for k, v in next, t, nil do
145+
coroutine.yield(k, v)
146+
end
147+
end
148+
149+
local t = {
150+
key1 = 1,
151+
key2 = 2,
152+
}
153+
setmetatable(t, {
154+
-- Here's an example "__index" table
155+
__index = {
156+
meta_key1 = 1,
157+
meta_key2 = 2,
158+
},
159+
-- And here's the "__pairs" metamethod
160+
__pairs = function(t)
161+
return coroutine.wrap(iterate_index_then_self), t, nil
162+
end,
163+
})
164+
return t
165+
""")
166+
167+
assert(table.to_dictionary() == {
168+
key1 = 1,
169+
key2 = 2,
170+
meta_key1 = 1,
171+
meta_key2 = 2,
172+
})
173+
174+
return true

0 commit comments

Comments
 (0)