Skip to content

Commit

Permalink
Update variant__call to use luaL_error instead of returning nil
Browse files Browse the repository at this point in the history
  • Loading branch information
gilzoide committed Oct 14, 2023
1 parent f3b8b77 commit fbe6cb9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/luaopen/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,14 @@ bool variant_is(const Variant& variant, const sol::stack_object& type) {
return false;
}

sol::stack_object variant__call(sol::this_state L, const Variant& variant, sol::variadic_args args) {
ERR_FAIL_COND_V_MSG(
variant.get_type() != Variant::CALLABLE,
to_lua(L, Variant()),
String("attempt to call a %s value") % get_type_name(variant)
);
VariantArguments var_args = args;
sol::stack_object variant__call(sol::this_state state, const Variant& variant, sol::variadic_args args) {
if (variant.get_type() != Variant::CALLABLE) {
luaL_error(state, "attempt to call a %s value", get_type_name(variant).ascii().get_data());
}
Callable callable = variant;
VariantArguments var_args = args;
Variant result = callable.callv(var_args.get_array());
return to_lua(L, result);
return to_lua(state, result);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/convert_godot_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ sol::stack_object variant_static_call_string_name(sol::this_state state, Variant
Variant::call_static(type, method, variant_args.argv(), variant_args.argc(), result, error);
if (error.error != GDEXTENSION_CALL_OK) {
String message = String("Invalid static call to method '{0}' in type {1}").format(Array::make(method, Variant::get_type_name(type)));
lua_error(args.lua_state(), error, message);
lua_error(state, error, message);
}
return to_lua(state, result);
}
Expand All @@ -219,7 +219,7 @@ sol::stack_object variant_call_string_name(sol::this_state state, Variant& varia
variant.call(method, variant_args.argv(), variant_args.argc(), result, error);
if (error.error != GDEXTENSION_CALL_OK) {
String message = String("Invalid call to method '{0}' in object of type {1}").format(Array::make(method, get_type_name(variant)));
lua_error(args.lua_state(), error, message);
lua_error(state, error, message);
}
return to_lua(state, result);
}
Expand Down

0 comments on commit fbe6cb9

Please sign in to comment.