gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/window.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年10月26日 14:22:07 +0200
committerfrancesco-ST <francesco.abbate@st.com>2010年10月26日 14:22:07 +0200
commit7e665c04ea2063264a6415bfbd03ae0de2da0bcd (patch)
tree93667d65eff9d3e910cfb25edcd0c98a6c875f1f /agg-plot/window.cpp
parent071e8359e6c9019b3f3ddc41d8185d391458906b (diff)
downloadgsl-shell-7e665c04ea2063264a6415bfbd03ae0de2da0bcd.tar.gz
added error handling when an invalid split string is given
Diffstat (limited to 'agg-plot/window.cpp')
-rw-r--r--agg-plot/window.cpp 47
1 files changed, 38 insertions, 9 deletions
diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp
index a2501c25..ef5fd42b 100644
--- a/agg-plot/window.cpp
+++ b/agg-plot/window.cpp
@@ -293,17 +293,24 @@ window::cleanup_tree_rec (lua_State *L, int window_index, ref::node* n)
}
}
-void
+bool
window::split(const char *spec)
{
- if (m_tree)
- delete m_tree;
-
::split<ref>::lexer lexbuf(spec);
- m_tree = ::split<ref>::parse(lexbuf);
+ tree::node<ref, direction_e> *new_tree = ::split<ref>::parse(lexbuf);
+
+ if (new_tree)
+ {
+ if (m_tree)
+ delete m_tree;
+
+ m_tree = new_tree;
+ bmatrix m0;
+ ref::calculate(m_tree, m0, 0);
+ return true;
+ }
- bmatrix m0;
- ref::calculate(m_tree, m0, 0);
+ return false;
}
static const char *
@@ -360,6 +367,22 @@ int window::attach(lua_plot *plot, const char *spec)
return r->slot_id;
}
+const char *
+window::error_message(window::error_e code)
+{
+ switch (code)
+ {
+ case invalid_split_string:
+ return "invalid window subdivision specification";
+ case invalid_slot:
+ return "invalid slot specification";
+ default:
+ ;
+ }
+ return "unknown error";
+}
+
+
typedef void (window::*window_slot_method_type)(int slot_id);
int window_generic_oper (lua_State *L, window_slot_method_type method)
@@ -406,6 +429,7 @@ window_new (lua_State *L)
if (spec)
{
win->split(spec);
+ // return luaL_error(L, window::error_message(window::invalid_split_string));
}
return 1;
@@ -434,7 +458,12 @@ window_split (lua_State *L)
win->lock();
win->cleanup_refs(L, 1);
- win->split(spec);
+ if (!win->split(spec))
+ {
+ win->do_window_update();
+ win->unlock();
+ return luaL_error(L, window::error_message(window::invalid_split_string));
+ }
win->on_draw();
win->do_window_update();
@@ -463,7 +492,7 @@ window_attach (lua_State *L)
else
{
win->unlock();
- luaL_error (L, "invalid slot");
+ luaL_error (L, window::error_message(window::invalid_slot));
}
return 0;
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月14日 14:31:37 +0000

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