| 2 | #include <sol/sol.hpp> |
| 3 | |
| 4 | int main() { |
| 5 | |
| 6 | sol::state lua; |
| 7 | |
| 8 | lua.script(R"( |
| 9 | function f (a) |
| 10 | return a + 5 |
| 11 | end |
| 12 | )"); |
| 13 | |
| 14 | // Get and immediately call |
| 15 | int x = lua["f"](30); |
| 16 | SOL_ASSERT(x == 35); |
| 17 | |
| 18 | // Store it into a variable first, then call |
| 19 | sol::unsafe_function f = lua["f"]; |
| 20 | int y = f(20); |
| 21 | SOL_ASSERT(y == 25); |
| 22 | |
| 23 | // Store it into a variable first, then call |
| 24 | sol::protected_function safe_f = lua["f"]; |
| 25 | int z = safe_f(45); |
| 26 | SOL_ASSERT(z == 50); |
| 27 | |
| 28 | return 0; |
| 29 | } |