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
// bind and set up your things: everything is entirely self-contained
42
+
lua["f"] = sol::overload(
43
+
[](Player& from_tolua) {
44
+
std::cout << "calling 1-argument version with tolua-created Player { health:" << from_tolua.getHealth() << "}" << std::endl;
45
+
},
46
+
[](Player& from_tolua, int second_arg) {
47
+
std::cout << "calling 2-argument version with tolua-created Player { health: " << from_tolua.getHealth() << "} and integer argument of " << second_arg << std::endl;
48
+
});
49
+
}
50
+
51
+
voidcheck_with_sol(lua_State* L) {
52
+
sol::state_view lua(L);
53
+
Player& obj = lua["obj"];
54
+
(void)obj;
55
+
assert(obj.getHealth() == 4);
56
+
}
57
+
58
+
intmain(int, char* []) {
59
+
60
+
std::cout << "=== interop example (tolua) ===" << std::endl;
61
+
std::cout << "(code lifted from a sol2 user's use case: https://github.com/ThePhD/sol2/issues/511#issuecomment-331729884)" << std::endl;
62
+
63
+
lua_State* L = luaL_newstate();
64
+
65
+
luaL_openlibs(L); // initalize all lua standard library functions
66
+
tolua_open(L); // initalize tolua
67
+
tolua_Player_open(L); // make Player class accessible from LUA
0 commit comments