| 8 | } |
| 9 | |
| 10 | int main() { |
| 11 | |
| 12 | sol::state lua; |
| 13 | |
| 14 | lua["my_func"] = my_function; // way 1 |
| 15 | lua.set("my_func", my_function); // way 2 |
| 16 | lua.set_function("my_func", my_function); // way 3 |
| 17 | |
| 18 | // This function is now accessible as 'my_func' in |
| 19 | // lua scripts / code run on this state: |
| 20 | lua.script("some_str = my_func(1, 'Da')"); |
| 21 | |
| 22 | // Read out the global variable we stored in 'some_str' in |
| 23 | // the quick lua code we just executed |
| 24 | std::string some_str = lua["some_str"]; |
| 25 | SOL_ASSERT(some_str == "DaD"); |
| 26 | |
| 27 | return 0; |
| 28 | } |