From 1002c98152dc3dabad7b251103d60a587f7aa5b1 Mon Sep 17 00:00:00 2001 From: francesco-ST Date: Thu, 2 Dec 2010 10:21:15 +0100 Subject: new model for C++/Lua error exception-safe separation Now all the exceptions are trapped in pure C++ functions and a status code is returned by reference to indicate success or give an error message. The C function that instruments Lua interface can call lua_error but is not supposed to catch exceptions and does not allocate auto class instance that need non-trivial destructors. --- agg-plot/lua-plot.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'agg-plot/lua-plot.cpp') diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 6f036514..5b60ea3d 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -25,6 +25,7 @@ extern "C" { #include "lua-plot.h" #include "lua-plot-cpp.h" +#include "lua-cpp-utils.h" #include "bitmap-plot.h" #include "window.h" #include "gs-types.h" @@ -148,35 +149,39 @@ plot_free (lua_State *L) return object_free(L, 1, GS_PLOT); } -int -plot_add_gener (lua_State *L, bool as_line) +void +plot_add_gener_cpp (lua_State *L, lua_plot *p, bool as_line, + gslshell::ret_status& st) { - lua_plot *p = object_check(L, 1, GS_PLOT); - - agg::rgba8 color; - try { + agg::rgba8 color; drawable *obj = parse_graph_args (L, color); - object_refs_add (L, table_plot_obj, p->current_layer_index(), 1, 2); - AGG_LOCK(); - p->add(obj, color, as_line); - AGG_UNLOCK(); + object_refs_add (L, table_plot_obj, p->current_layer_index(), 1, 2); + if (p->sync_mode()) plot_flush (L); } - catch (std::bad_alloc&) - { - return luaL_error (L, OUT_OF_MEMORY_MSG); - } - catch (agg_spec_error& e) + catch (std::exception& e) { - return luaL_error (L, e.message()); + st.error(e.what(), "plot add or addline"); } +} + +int +plot_add_gener (lua_State *L, bool as_line) +{ + lua_plot *p = object_check(L, 1, GS_PLOT); + + gslshell::ret_status st; + plot_add_gener_cpp (L, p, as_line, st); + + if (st.error_msg()) + return luaL_error (L, "%s in %s", st.error_msg(), st.context()); return 0; } -- cgit v1.2.3

AltStyle によって変換されたページ (->オリジナル) /