-rw-r--r-- | agg-plot/canvas-window-cpp.h | 2 | ||||
-rw-r--r-- | agg-plot/canvas-window.cpp | 8 | ||||
-rw-r--r-- | agg-plot/lua-cpp-utils.h | 7 | ||||
-rw-r--r-- | agg-plot/lua-plot-cpp.h | 9 | ||||
-rw-r--r-- | agg-plot/lua-plot.cpp | 24 | ||||
-rw-r--r-- | agg-plot/window-cpp.h | 2 | ||||
-rw-r--r-- | agg-plot/window.cpp | 19 |
diff --git a/agg-plot/canvas-window-cpp.h b/agg-plot/canvas-window-cpp.h index 850a0c58..14500e48 100644 --- a/agg-plot/canvas-window-cpp.h +++ b/agg-plot/canvas-window-cpp.h @@ -60,8 +60,6 @@ public: }; void scale (agg::trans_affine& m) { trans_affine_compose (m, m_matrix); }; - - static canvas_window *check (lua_State *L, int index); }; #endif diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp index 1e3cfacb..0a37dbb8 100644 --- a/agg-plot/canvas-window.cpp +++ b/agg-plot/canvas-window.cpp @@ -128,16 +128,10 @@ canvas_thread_function (void *_win) return NULL; } -canvas_window * -canvas_window::check (lua_State *L, int index) -{ - return (canvas_window *) gs_check_userdata (L, index, GS_CANVAS_WINDOW); -} - int canvas_window_close (lua_State *L) { - canvas_window *win = canvas_window::check (L, 1); + canvas_window *win = object_check<canvas_window>(L, 1, GS_CANVAS_WINDOW); win->lock(); if (win->status == canvas_window::running) win->close(); diff --git a/agg-plot/lua-cpp-utils.h b/agg-plot/lua-cpp-utils.h index 0efaa848..559cb97b 100644 --- a/agg-plot/lua-cpp-utils.h +++ b/agg-plot/lua-cpp-utils.h @@ -51,10 +51,15 @@ T* push_new_object (lua_State *L, enum gs_type_e tp, init_type& init) template <class T> int object_free (lua_State *L, int index, enum gs_type_e tp) { - INDEX_SET_ABS(L, index); T *obj = (T *) gs_check_userdata (L, index, tp); obj->~T(); return 0; } +template <class T> +T* object_check (lua_State *L, int index, enum gs_type_e tp) +{ + return (T *) gs_check_userdata (L, index, tp); +} + #endif diff --git a/agg-plot/lua-plot-cpp.h b/agg-plot/lua-plot-cpp.h index 022be7e9..a3420708 100644 --- a/agg-plot/lua-plot-cpp.h +++ b/agg-plot/lua-plot-cpp.h @@ -14,16 +14,13 @@ extern "C" { class lua_plot { public: typedef plot<drawable, lua_management> plot_type; - -private: - plot_type m_plot; - -public: + lua_plot() : m_plot() { }; plot_type& self() { return m_plot; }; - static lua_plot *check(lua_State *L, int index); +private: + plot_type m_plot; }; #endif diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index a86c1f54..f0ce872d 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -86,16 +86,10 @@ static const struct luaL_Reg plot_properties_set[] = { __END_DECLS -lua_plot * -lua_plot::check(lua_State *L, int index) -{ - return (lua_plot *) gs_check_userdata (L, index, GS_PLOT); -} - int plot_new (lua_State *L) { - lua_plot *p = new(L, GS_PLOT) lua_plot(); + lua_plot *p = push_new_object<lua_plot>(L, GS_PLOT); if (lua_isstring (L, 1)) { @@ -110,15 +104,13 @@ plot_new (lua_State *L) int plot_free (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); - p->~lua_plot(); - return 0; + return object_free<lua_plot>(L, 1, GS_PLOT); } int plot_add_gener (lua_State *L, bool as_line) { - lua_plot *p = lua_plot::check(L, 1); + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); drawable *obj = parse_graph_args (L); agg::rgba8 *color = check_color_rgba8 (L, 3); @@ -150,7 +142,7 @@ plot_add_line (lua_State *L) int plot_title_set (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); const char *title = lua_tostring (L, 2); if (title == NULL) @@ -170,7 +162,7 @@ plot_title_set (lua_State *L) int plot_title_get (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); AGG_LOCK(); @@ -185,7 +177,7 @@ plot_title_get (lua_State *L) int plot_units_set (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); bool request = (bool) lua_toboolean (L, 2); AGG_LOCK(); @@ -210,7 +202,7 @@ plot_units_set (lua_State *L) int plot_units_get (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); AGG_LOCK(); @@ -243,7 +235,7 @@ plot_update_raw (lua_State *L, int plot_index) int plot_update (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); + object_check<lua_plot>(L, 1, GS_PLOT); plot_update_raw (L, 1); return 0; } diff --git a/agg-plot/window-cpp.h b/agg-plot/window-cpp.h index 963d5a0d..2bfaf77d 100644 --- a/agg-plot/window-cpp.h +++ b/agg-plot/window-cpp.h @@ -54,8 +54,6 @@ public: ~window() { if (m_tree) delete m_tree; }; - static window *check (lua_State *L, int index); - void split(const char *spec); int attach(lua_plot *plot, const char *spec); void draw_slot(int slot_id, bool update_req); diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index f6c7e4b4..0873d4e2 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -164,12 +164,6 @@ window::on_draw() draw_rec(m_tree); } -window * -window::check (lua_State *L, int index) -{ - return (window *) gs_check_userdata (L, index, GS_WINDOW); -} - void window::cleanup_tree_rec (lua_State *L, int window_index, ref::node* n) { @@ -218,8 +212,7 @@ next_int (const char *str, int& val) return eptr; } -/* Returns the existing plot ref id, 0 if there isn't any. - It does return -1 in case of error.*/ +/* Returns the slot_id or -1 in case of error. */ int window::attach(lua_plot *plot, const char *spec) { ref::node *n = m_tree; @@ -269,7 +262,7 @@ window_free (lua_State *L) int window_split (lua_State *L) { - window *win = window::check (L, 1); + window *win = object_check<window>(L, 1, GS_WINDOW); const char *spec = luaL_checkstring (L, 2); win->lock(); @@ -287,8 +280,8 @@ window_split (lua_State *L) int window_attach (lua_State *L) { - window *win = window::check (L, 1); - lua_plot *plot = lua_plot::check (L, 2); + window *win = object_check<window>(L, 1, GS_WINDOW); + lua_plot *plot = object_check<lua_plot>(L, 2, GS_PLOT); const char *spec = luaL_checkstring (L, 3); win->lock(); @@ -313,7 +306,7 @@ window_attach (lua_State *L) int window_slot_update (lua_State *L) { - window *win = window::check (L, 1); + window *win = object_check<window>(L, 1, GS_WINDOW); int slot_id = luaL_checkinteger (L, 2); win->lock(); @@ -329,7 +322,7 @@ window_slot_update (lua_State *L) int window_update (lua_State *L) { - window *win = window::check (L, 1); + window *win = object_check<window>(L, 1, GS_WINDOW); win->lock(); win->on_draw(); |