Skip to content

Commit 5a3feaa

Browse files
committed
Convert null objects to nil in Lua
1 parent fd70a43 commit 5a3feaa

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
```lua
2626
MyScript.exported_dictionary = export(Dictionary)
2727
```
28+
- Convert null Object Variants (`<Object#null>`) to `nil` when passing them to Lua
2829

2930

3031
## [0.5.0](https://github.com/gilzoide/lua-gdextension/releases/tag/0.5.0)

src/utils/convert_godot_lua.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ sol::stack_object lua_push(lua_State *lua_state, const Variant& value) {
184184
break;
185185

186186
case Variant::OBJECT:
187+
if ((Object *) value == nullptr) {
188+
sol::stack::push(lua_state, sol::nil);
189+
break;
190+
}
187191
if (LuaObject *lua_obj = Object::cast_to<LuaObject>(value)) {
188192
if (LuaState::find_lua_state(lua_state) == lua_obj->get_lua_state()) {
189193
sol::stack::push(lua_state, lua_obj->get_lua_object());

test/lua_tests/null_object.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert(instance_from_id(0) == nil)

test/lua_tests/null_object.lua.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://d043pcf3pr0ak

0 commit comments

Comments
 (0)