Skip to content

Commit

Permalink
Lua: Add ArrayProperty out parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 9, 2024
1 parent 88b3724 commit 8878b2e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lua-api/lib/src/ScriptUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API
}

arr.count = dynamic_arr.size();
arr.capacity = dynamic_arr.size();
arr.data = dynamic_arr.data();
//} else {
//throw sol::error("Cannot set an out parameter with an array (yet)");
Expand Down Expand Up @@ -615,6 +616,41 @@ sol::object call_function(sol::this_state s, uevr::API::UObject* self, uevr::API
tbl["result"] = (uevr::API::UClass*)*(uevr::API::UClass**)((uintptr_t)params.data() + prop->get_offset());
} else if (prop_name_hash == L"ObjectProperty"_fnv) {
tbl["result"] = (uevr::API::UObject*)*(uevr::API::UObject**)((uintptr_t)params.data() + prop->get_offset());
} else if (prop_name_hash == L"ArrayProperty"_fnv) {
const auto tbl_was_empty = tbl.empty();
auto& arr = *(uevr::API::TArray<uevr::API::UObject*>*)((uintptr_t)params.data() + prop->get_offset());

if (!arr.empty()) {
const auto inner_prop = ((uevr::API::FArrayProperty*)prop)->get_inner();

if (inner_prop == nullptr) {
continue;
}

const auto inner_c = inner_prop->get_class();

if (inner_c == nullptr) {
continue;
}

const auto inner_name_hash = ::utility::hash(inner_c->get_fname()->to_string());

if (inner_name_hash == L"ObjectProperty"_fnv) {
for (size_t i = 0; i < arr.count; ++i) {
tbl[i + 1] = arr.data[i];
}
} else if (inner_name_hash == L"ClassProperty"_fnv) {
for (size_t i = 0; i < arr.count; ++i) {
tbl[i + 1] = (uevr::API::UClass*)arr.data[i];
}
} else {
// TODO
}

if (tbl_was_empty) {
arr.~TArray(); // This should be safe, as this is not our array
}
}
} else {
//tbl["result"] = sol::make_object(s, sol::lua_nil);
}
Expand Down

0 comments on commit 8878b2e

Please sign in to comment.