1 #define SOL_ALL_SAFETIES_ON 1
2 #include <sol/sol.hpp>
3
4
main()5 int main() {
6 sol::state lua;
7
8 lua.set_function("bark", [](sol::this_state s, int a, int b) {
9 lua_State* L = s; // current state
10 return a + b + lua_gettop(L);
11 });
12
13 lua.script("first = bark(2, 2)"); // only takes 2 arguments, NOT 3
14
15 // Can be at the end, too, or in the middle: doesn't matter
16 lua.set_function("bark", [](int a, int b, sol::this_state s) {
17 lua_State* L = s; // current state
18 return a + b + lua_gettop(L);
19 });
20
21 lua.script("second = bark(2, 2)"); // only takes 2 arguments
22 int first = lua["first"];
23 sol_c_assert(first == 6);
24 int second = lua["second"];
25 sol_c_assert(second == 6);
26
27 return 0;
28 }