Skip to content

Commit 8635435

Browse files
committed
Expose LuaFunction::to_callable to Godot
1 parent c55b241 commit 8635435

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/LuaFunction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ LuaFunction::LuaFunction(const sol::protected_function& function) : LuaObjectSub
4747
void LuaFunction::_bind_methods() {
4848
ClassDB::bind_method(D_METHOD("invokev", "arg_array"), &LuaFunction::invokev);
4949
ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "invoke", &LuaFunction::invoke);
50+
ClassDB::bind_method(D_METHOD("to_callable"), &LuaFunction::to_callable);
51+
5052
}
5153

5254
Variant LuaFunction::invokev(const Array& args) {

test/gdscript_tests/LuaFunction_invoke.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func test_invoke_args() -> bool:
3939
return true
4040

4141

42+
func test_callable() -> bool:
43+
var callable = function.to_callable()
44+
assert(callable.call(5) == 5, "Value passed '5' was not returned")
45+
assert(callable.call(1, 2) == [1, 2], "Multiple returns did not return array")
46+
assert(callable.call(1, 2, []) == [1, 2, []], "Multiple returns did not return array")
47+
return true
48+
49+
4250
func _test_call(f: LuaFunction, args: Array = []):
4351
var result = f.invokev(args)
4452
if result is LuaError:

0 commit comments

Comments
 (0)