Skip to content

Commit

Permalink
Lua: Fix bug where functions would sometimes not be found
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 1, 2024
1 parent 522ff8a commit b14be18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
19 changes: 4 additions & 15 deletions lua-api/lib/src/ScriptContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,11 @@ int ScriptContext::setup_bindings() {
"read_byte", &lua::utility::read_t<uint8_t>,
"read_float", &lua::utility::read_t<float>,
"read_double", &lua::utility::read_t<double>,
sol::meta_function::index, [](sol::this_state s, uevr::API::UObject* self, sol::object index_obj) -> sol::object {
if (!index_obj.is<std::string>()) {
return sol::make_object(s, sol::lua_nil);
}

const auto name = utility::widen(index_obj.as<std::string>());

return lua::utility::prop_to_object(s, self, name);
sol::meta_function::index, [](sol::this_state s, uevr::API::UObject* self, const std::wstring& index_obj) -> sol::object {
return lua::utility::prop_to_object(s, self, index_obj);
},
sol::meta_function::new_index, [](sol::this_state s, uevr::API::UObject* self, sol::object index_obj, sol::object value) {
if (!index_obj.is<std::string>()) {
return;
}

const auto name = utility::widen(index_obj.as<std::string>());
lua::utility::set_property(s, self, name, value);
sol::meta_function::new_index, [](sol::this_state s, uevr::API::UObject* self, const std::wstring& index_obj, sol::object value) {
lua::utility::set_property(s, self, index_obj, value);
}
);

Expand Down
2 changes: 2 additions & 0 deletions lua-api/lib/src/ScriptUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ sol::object prop_to_object(sol::this_state s, void* self, uevr::API::FProperty*
}

return sol::make_object(s, *(uevr::API::UClass**)((uintptr_t)self + offset));
case L"Function"_fnv:
return sol::make_object(s, (uevr::API::UFunction*)desc); // Not actually a property inside the object
case L"StructProperty"_fnv:
{
const auto struct_data = (void*)((uintptr_t)self + offset);
Expand Down

0 comments on commit b14be18

Please sign in to comment.