new model for C++/Lua error exception-safe separation - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/lua-plot.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年12月02日 10:21:15 +0100
committerfrancesco-ST <francesco.abbate@st.com>2010年12月02日 10:21:15 +0100
commit1002c98152dc3dabad7b251103d60a587f7aa5b1 (patch)
treef4710447b154d4244ac861e70c3dce5917f6e2f8 /agg-plot/lua-plot.cpp
parent9a2e6443e486a5b417c7e0bfbcfef15ac9e0b6d8 (diff)
downloadgsl-shell-1002c98152dc3dabad7b251103d60a587f7aa5b1.tar.gz
new model for C++/Lua error exception-safe separationgsl-shell-1.0
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.
Diffstat (limited to 'agg-plot/lua-plot.cpp')
-rw-r--r--agg-plot/lua-plot.cpp 37
1 files changed, 21 insertions, 16 deletions
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<lua_plot>(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<lua_plot>(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<lua_plot>(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;
}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 15:37:49 +0000

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