This is a C callback with a specific signature, callable from programs written in Lua. If it succeeds, it returns an int answer, by pushing it onto the Lua stack. But "sometimes" it fails, in which case it throws an exception, which will be processed by wrap_lua_CFunction (above).
| 66 | // the Lua stack. But "sometimes" it fails, in which case it throws an |
| 67 | // exception, which will be processed by wrap_lua_CFunction (above). |
| 68 | int do_work( lua_State * L ) |
| 69 | { |
| 70 | bool success = rand() % 2; // "Sometimes" do_work fails. |
| 71 | if( success ) |
| 72 | { |
| 73 | lua_pushnumber(L, 42); // Success, push the result on the Lua stack, return to Lua. |
| 74 | return 1; |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | leaf::throw_exception(ec1); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | |
| 83 | std::shared_ptr<lua_State> init_lua_state() |
nothing calls this directly
no test coverage detected