You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use the ADL customization points to turn a Lua table to a custom type using the get<CustomType>() syntax. For getting a single value, it works as expected. However, when I put that custom type into a std::vector the program crashes.
Here is the program that I'm working on:
#include<fmt/format.h>
#include<fmt/ranges.h>
#include<sol/sol.hpp>structA {};
template <typename Handler>
autosol_lua_check(sol::types<A>, lua_State *L, int index, Handler &&handler, sol::stack::record &tracking) -> bool {
if (not sol::stack::check_usertype<A>(L, index) andnot sol::stack::check<sol::table>(L, index)) {
handler(L, index, sol::type_of(L, index), sol::type::userdata, "expected a A or a table");
returnfalse;
}
tracking.use(1);
returntrue;
}
autosol_lua_get(sol::types<A>, lua_State *L, int index, sol::stack::record &tracking) -> A {
if (sol::stack::check_usertype<A>(L, index)) {
return sol::stack::get_usertype<A>(L, index, tracking);
}
auto result = A{};
auto object = sol::stack::get<sol::table>(L, lua_absindex(L, index));
tracking.use(1);
return result;
}
intmain() {
auto lua = sol::state{};
lua.open_libraries(sol::lib::base, sol::lib::package);
lua.new_usertype<A>("A");
[[maybe_unused]] auto a = lua.script(R"lua(return {})lua").get<A>(); // Works
[[maybe_unused]] auto as = lua.script(R"lua(return {{}})lua").get<std::vector<A>>(); // Crashes
}
What am I doing wrong here?
Lua: LuaJIT
Compiler: GCC 10.5
The text was updated successfully, but these errors were encountered:
I am trying to use the ADL customization points to turn a Lua table to a custom type using the
get<CustomType>()
syntax. For getting a single value, it works as expected. However, when I put that custom type into astd::vector
the program crashes.Here is the program that I'm working on:
What am I doing wrong here?
The text was updated successfully, but these errors were encountered: