| 3 | |
| 4 | |
| 5 | int main(int, char*[]) { |
| 6 | sol::state lua; |
| 7 | lua.script("function func (a, b) return (a + b) * 2 end"); |
| 8 | |
| 9 | sol::reference func_ref = lua["func"]; |
| 10 | |
| 11 | // for some reason, you need to use the low-level API |
| 12 | func_ref.push(); // function on stack now |
| 13 | |
| 14 | // maybe this is in a lua_CFunction you bind, |
| 15 | // or maybe you're trying to work with a pre-existing system |
| 16 | // maybe you've used a custom lua_load call, or you're |
| 17 | // working with state_view's load(lua_Reader, ...) call... |
| 18 | // here's a little bit of how you can work with the stack |
| 19 | lua_State* L = lua.lua_state(); |
| 20 | sol::stack_aligned_unsafe_function func(L, -1); |
| 21 | lua_pushinteger(L, 5); // argument 1, using plain API |
| 22 | lua_pushinteger(L, 6); // argument 2 |
| 23 | |
| 24 | // take 2 arguments from the top, |
| 25 | // and use "stack_aligned_function" to call |
| 26 | int result = func(sol::stack_count(2)); |
| 27 | |
| 28 | // make sure everything is clean |
| 29 | SOL_ASSERT(result == 22); |
| 30 | SOL_ASSERT( |
| 31 | lua.stack_top() == 0); // stack is empty/balanced |
| 32 | |
| 33 | return 0; |
| 34 | } |
nothing calls this directly
no test coverage detected