From 5286661bce369e47f1c4fad07aeed96d816b9835 Mon Sep 17 00:00:00 2001 From: praydog Date: Wed, 26 Jun 2024 00:03:53 -0700 Subject: [PATCH] Lua: Initial support for passing Vector types to functions --- lua-api/lib/src/ScriptContext.cpp | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lua-api/lib/src/ScriptContext.cpp b/lua-api/lib/src/ScriptContext.cpp index b156fc39..57d4b9b1 100644 --- a/lua-api/lib/src/ScriptContext.cpp +++ b/lua-api/lib/src/ScriptContext.cpp @@ -504,6 +504,39 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API *(uevr::API::UClass**)¶ms[offset] = arg; continue; } + case L"StructProperty"_fnv: + { + const auto arg_obj = args[args_index++]; + const auto struct_desc = ((uevr::API::FStructProperty*)prop_desc)->get_struct(); + + if (struct_desc == nullptr) { + 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 (is_ue5()) { + *(lua::datatypes::Vector3d*)¶ms[offset] = arg; + } else { + *(lua::datatypes::Vector3f*)¶ms[offset] = arg; + } + } else if (arg_obj.is()) { + const auto arg = arg_obj.as(); + + if (is_ue5()) { + *(lua::datatypes::Vector3d*)¶ms[offset] = arg; + } else { + *(lua::datatypes::Vector3f*)¶ms[offset] = arg; + } + } else { + throw sol::error("Invalid argument type for FVector"); + } + } + + continue; + } case L"ArrayProperty"_fnv: // TODO throw sol::error("Array properties are not supported (yet)");