-
-
Notifications
You must be signed in to change notification settings - Fork 537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sol not recognizing Intrusive List as a container #1466
Comments
If I understand correctly, containers are already understood by sol if they have many characteristics of a container. If sol determines that a type is a container, it will automatically add a bunch of container methods to it based on the kind of container it thinks it is https://sol2.readthedocs.io/en/latest/containers.html#container-detection. // sol should automatically detect a pushed RoomListType as a container if it seems like a container
lua.new_usertype<RoomListType>(
// also I think this new_usertype is ill formed?
[](RoomListType& list) {
return sol::as_container(list);
}
); You should not need to create a user type for it (unless there are other con-container methods you want to add...). |
Thanks, I guess my question is what is missing from the |
EDIT: The container has no proper using StringList = PCSX::Intrusive::List<std::string>;
void TestIntrusive() {
sol::state lua;
lua.open_libraries();
lua.new_usertype<StringList>("StringList",
sol::meta_function::length, &StringList::size
// other meta methods...
);
} You can manually specify the metamethods like length and pairs..., but still not sure. Ok so I've dug deeper into this and it's not being interpreted as a container at all, even when pushed using I've even checked Interestingly, compilation fails when setting the global It's possible that the list is not being recognized because it does not contain an Here's a minimal test with many different things I've tried: int main() {
sol::state lua;
lua.open_libraries();
PCSX::Intrusive::List<std::string> intrusive;
//robin_hood::unordered_map<std::string, std::string> intrusive;
lua.new_usertype<PCSX::Intrusive::List<std::string>>("Intrusive");
static_assert(sol::is_container_v<decltype(intrusive)>);
//lua["intrusive"] = std::ref(intrusive);
//lua["intrusive"] = &intrusive;
//lua["intrusive"] = sol::as_container(&intrusive);
lua["intrusive"] = sol::as_container(intrusive);
//const auto& code = R"(
// for i = 1, #intrusive do
// print(intrusive[i])
// end
//)";
const auto& code = R"(
for k, v in pairs(intrusive) do
--for k, v in intrusive:pairs() do
print(k, v)
end
)";
lua.script(code);
return 0;
} Here's one of the errors (with all errors commonly sharing
|
So, the main issue I think is that this: lua.new_usertype<RoomListType>(
[](RoomListType& rl) {
return sol::as_container(rl); // Required for sol to treat Intrusive Lists as a container
}
); gets never called. This binding here: "players",
&Room::players, which is calling RoomListType& players() { return m_players; } properly does its job during the Lua code |
@ThePhD do you have any ideas on how we can make progress on this? Thanks! |
Hello,
I'm new to Lua and only intermediate at C++ at best, so I apologize if this is a dumb question. In short, I'm trying to access a particular Intrusive List implementation from Lua, but sol throws an error when I try to iterate on it saying that it's not recognized as a container. I read some other issue threads and saw the
as_container
approach, which partially works:sol no longer complains about it not being a container, and even allows me to iterate on it, but if I try to access any of the members on
Character
from inside Lua it bombs out:Error:
Any ideas on what I'm doing wrong here? I'm confused about why the
as_container
bit was necessary since I believe that intrusive list class implements all the iterator functions needed to be detected as a container.Thanks!
The text was updated successfully, but these errors were encountered: