godot_luaAPI icon indicating copy to clipboard operation
godot_luaAPI copied to clipboard

Allow LuaCallableExtra to be called in GDScript

Open jbromberg opened this issue 1 year ago • 0 comments

There are many instances where you may end up with a LuaCallableExtra in GDScript and there is no way to call it. The problem is illustrated here:

func lua_call(function):
	print("calling %s" % function)
	function.call()

var lua := LuaAPI.new()
lua.push_variant("call", lua_call)
lua.push_variant("foo", func(): print("foo"))

# Doesn't work
lua.do_string("call(foo)")

# Works
lua.do_string("call(function()
foo()
end)")

More broadly, it seems there could be some consolidation between LuaCallable and LuaCallableExtra to provide a simpler API. They both exist as functions in Lua but not in GDScript. Godot's Callable also has the bind() method that could allow the ref and tuple to still be passed into the Callable as arguments. This is obviously a deeper change but at the very least it would be great to be able to call a LuaCallableExtra from GDScript or at least expose the underlying Callable it wraps.

jbromberg avatar Apr 17 '24 23:04 jbromberg