Skip to content
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

🛠 Sometimes the conversion of sol::nested wrappers is not perfect. #1502

Closed
wants to merge 1 commit into from

Conversation

wzhengsen
Copy link

struct Vector {
	int x;
	int y;
};

template <class Handler>
bool sol_lua_check(sol::types<Vector>, ::lua_State* L, int index,
     Handler&& handler, sol::stack::record& tracking) {
    // It can pass the type check correctly.
	return sol::stack::check<sol::lua_table>(
	     L, index, std::forward<Handler>(handler), tracking);
}

Vector sol_lua_get(sol::types<Vector>, ::lua_State* L, int idx,
     sol::stack::record& tracking) {
    // However, it is not possible to convert the type.
	tracking.use(1);
	sol::table t = sol::table(L, idx);
	return { t["x"].get<int>(), t["y"].get<int>() };
}

int main() {
	sol::state lua;
	lua.open_libraries(sol::lib::base);
	lua.script("vectors = { {x = 3, y = 6}, {x = 6,y=3} }");
	auto v = lua["vectors"].get<std::vector<Vector>>();// error.

	return 0;
}

@wzhengsen wzhengsen closed this Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant