WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
347 stars 27 forks source link

Support argument passing and return to do_file/string #191

Closed Trey2k closed 5 months ago

Trey2k commented 5 months ago

The lack of support for this was just an oversight. do_file and do_string will now take an optional second argument that should be an array of arguments. And now return a Variant instead of a LuaError.

Example

func _ready():
    var lua: LuaAPI = LuaAPI.new()
    lua.bind_libraries(["base", "table", "string"])

    var ret = lua.do_string("""
    local a, b = ...
    print(a, b)
    return a + b
    """, [4, 6])
    if ret is LuaError:
        print("ERROR %d: %s" % [ret.type, ret.message])
        return

    print(ret)