gilzoide / godot-lua-pluginscript

Godot PluginScript for the Lua language, currently based on LuaJIT's FFI
https://gilzoide.github.io/godot-lua-pluginscript/topics/README.md.html
MIT License
300 stars 21 forks source link

Get Lua script instances while unboxing Object Variants #47

Open gilzoide opened 1 year ago

gilzoide commented 1 year ago

Using Godot Object pointers provide unexpected results regarding the access to properties that are not declared (see https://github.com/gilzoide/godot-lua-pluginscript/discussions/46).

Using Lua tables, it doesn't matter if a property is declared or not, so it should be possible to set new values to Lua instances from Lua regardless of property declaration. It won't work from GDScript or other languages, but people might be writing all scripts in Lua, so it's more useful to have script instances automatically unboxed, if available.

Using GD.get_lua_instance from Variant.unbox should be enough, falling back to the original Object pointer if there is not Lua script attached to it. The cost of this operation is a single table index, so it shouldn't be a problem regarding performance.