From ff35a24837cd53b0af0085a594e5ceb95664c5b2 Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 26 Jun 2024 01:35:20 -0700 Subject: [PATCH] Lua: Add support for passing StructObjects to functions --- lua-api/lib/src/ScriptUtility.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lua-api/lib/src/ScriptUtility.cpp b/lua-api/lib/src/ScriptUtility.cpp index 9d9c9ed..fcdc144 100644 --- a/lua-api/lib/src/ScriptUtility.cpp +++ b/lua-api/lib/src/ScriptUtility.cpp @@ -376,7 +376,19 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API throw sol::error("Struct property has no struct"); } - if (struct_desc == get_vector_struct()) { + if (arg_obj.is()) { + const auto arg = arg_obj.as(); + + if (arg.desc != struct_desc) { + if (arg.desc != nullptr) { + throw sol::error(std::format("Invalid argument type for function '{}', expected '{}', got '{}'", ::utility::narrow(fn->get_fname()->to_string()), ::utility::narrow(struct_desc->get_fname()->to_string()), ::utility::narrow(arg.desc->get_fname()->to_string()))); + } else { + throw sol::error(std::format("Invalid argument type for function '{}', expected '{}', got 'nil'", ::utility::narrow(fn->get_fname()->to_string()), ::utility::narrow(struct_desc->get_fname()->to_string()))); + } + } + + memcpy(¶ms[offset], arg.object, struct_desc->get_struct_size()); + } else if (struct_desc == get_vector_struct()) { if (arg_obj.is()) { const auto arg = arg_obj.as(); @@ -396,6 +408,8 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API } else { throw sol::error("Invalid argument type for FVector"); } + } else { + throw sol::error("Invalid argument type for struct property"); } continue;