2
0
mirror of https://github.com/boostorg/leaf.git synced 2026-01-29 07:32:33 +00:00

Uniform wrapping for multi-line comments

This commit is contained in:
Emil Dotchevski
2020-12-06 23:42:50 -08:00
parent 420022600e
commit ed3683a8ce
16 changed files with 277 additions and 203 deletions

View File

@@ -28,10 +28,11 @@ struct e_lua_pcall_error { int value; };
struct e_lua_error_message { std::string value; };
// 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 calls luaL_error. This causes the Lua interpreter to abort and
// pop back into the C++ code which called it (see call_lua below).
// 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 calls luaL_error.
// This causes the Lua interpreter to abort and pop back into the C++ code which
// called it (see call_lua below).
int do_work( lua_State * L )
{
bool success = rand()%2; // "Sometimes" do_work fails.
@@ -53,12 +54,13 @@ std::shared_ptr<lua_State> init_lua_state()
std::shared_ptr<lua_State> L(lua_open(), &lua_close);
// Register the do_work function (above) as a C callback, under the global
// Lua name "do_work". With this, calls from Lua programs to do_work
// will land in the do_work C function we've registered.
// Lua name "do_work". With this, calls from Lua programs to do_work will
// land in the do_work C function we've registered.
lua_register( &*L, "do_work", &do_work );
// Pass some Lua code as a C string literal to Lua. This creates a global Lua
// function called "call_do_work", which we will later ask Lua to execute.
// Pass some Lua code as a C string literal to Lua. This creates a global
// Lua function called "call_do_work", which we will later ask Lua to
// execute.
luaL_dostring( &*L, "\
\n function call_do_work()\
\n return do_work()\
@@ -72,8 +74,8 @@ std::shared_ptr<lua_State> init_lua_state()
// in Lua, and returns the value from do_work, which is written in C++ and
// registered with the Lua interpreter as a C callback.
// If do_work succeeds, we return the resulting int answer.
// If it fails, we'll communicate that failure to our caller.
// If do_work succeeds, we return the resulting int answer. If it fails, we'll
// communicate that failure to our caller.
leaf::result<int> call_lua( lua_State * L )
{
leaf::error_monitor cur_err;
@@ -85,9 +87,11 @@ leaf::result<int> call_lua( lua_State * L )
auto load = leaf::on_error(e_lua_error_message{lua_tostring(L, 1)});
lua_pop(L,1);
// We got a Lua error which may be the error we're reporting from do_work, or some other error.
// If it is another error, cur_err.assigned_error_id() will return a new leaf::error_id,
// otherwise we'll be working with the original value returned by leaf::new_error in do_work.
// We got a Lua error which may be the error we're reporting from
// do_work, or some other error. If it is another error,
// cur_err.assigned_error_id() will return a new leaf::error_id,
// otherwise we'll be working with the original value returned by
// leaf::new_error in do_work.
return cur_err.assigned_error_id().load(e_lua_pcall_error{err});
}
else