MCPcopy Create free account
hub / github.com/boostorg/leaf / do_work

Function do_work

example/lua_callback_exceptions.cpp:68–80  ·  view source on GitHub ↗

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).

Source from the content-addressed store, hash-verified

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).
68int 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
83std::shared_ptr<lua_State> init_lua_state()

Callers

nothing calls this directly

Calls 1

throw_exceptionFunction · 0.70

Tested by

no test coverage detected