WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
381 stars 29 forks source link

Allow LuaCallableExtra to be called in GDScript #207

Open jbromberg opened 5 months ago

jbromberg commented 5 months ago

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.