This PR adds some new types for better metatable control over objects.
Added:
New LuaObjectMetatable type: this is a interface class meant to be used to define metatables.
New object_metatable property on LuaAPI: This is the default metatable to use for object which do not have a lua_metatable property them selfs.
New LuaDefaultObjectMetatable type: this is the type that object_metatable defaults to, it provides the same functionality with metatables and metamethods we had before this update. The LuaAPI permissive property has been moved to this class now. It will yield metamethod calls to the object if it defines them like before. Otherwise looks for the lua_fields method which is either a blacklist or a whitelist depending on permissive.
Removed:
the permissive property has been removed from LuaAPI. Moved to LuaDefaultObjectMetatable which can be accessed via LuaAPI.object_metatable.permissive
Code Example:
extends Node2D
class TestMetatable:
extends LuaObjectMetatable
func __index(obj: Object, lua: LuaAPI, index: String) -> Variant:
print("__index called")
return obj.get(index)
class example:
func lua_fields():
return ['test']
func test():
print("test")
class example2:
var lua_metatable := TestMetatable.new()
func test():
print("test2")
func _ready() -> void:
var luaAPI = LuaAPI.new()
luaAPI.object_metatable.permissive = false
var ex1 = example.new()
var ex2 = example2.new()
luaAPI.push_variant("example1", ex1)
luaAPI.push_variant("example2", ex2)
var err = luaAPI.do_string("""
example1.test()
example2.test()
""")
if err is LuaError:
print(err.message)
This PR adds some new types for better metatable control over objects.
Added:
LuaObjectMetatable
type: this is a interface class meant to be used to define metatables.object_metatable
property onLuaAPI
: This is the default metatable to use for object which do not have a lua_metatable property them selfs.LuaDefaultObjectMetatable
type: this is the type thatobject_metatable
defaults to, it provides the same functionality with metatables and metamethods we had before this update. TheLuaAPI
permissive property has been moved to this class now. It will yield metamethod calls to the object if it defines them like before. Otherwise looks for thelua_fields
method which is either a blacklist or a whitelist depending onpermissive
.Removed:
permissive
property has been removed fromLuaAPI
. Moved toLuaDefaultObjectMetatable
which can be accessed viaLuaAPI.object_metatable.permissive
Code Example: