-rw-r--r-- | agg-plot/lua-plot-cpp.h | 7 | ||||
-rw-r--r-- | agg-plot/lua-plot.cpp | 55 | ||||
-rw-r--r-- | agg-plot/window.cpp | 7 | ||||
-rw-r--r-- | agg-plot/window.h | 2 | ||||
-rw-r--r-- | win-plot-refs.c | 30 | ||||
-rw-r--r-- | win-plot-refs.h | 3 |
diff --git a/agg-plot/lua-plot-cpp.h b/agg-plot/lua-plot-cpp.h index 1c3f52c0..022be7e9 100644 --- a/agg-plot/lua-plot-cpp.h +++ b/agg-plot/lua-plot-cpp.h @@ -19,16 +19,11 @@ private: plot_type m_plot; public: - lua_plot() : m_plot(), window_id(-1) { }; - - void update_window(lua_State *L); + lua_plot() : m_plot() { }; plot_type& self() { return m_plot; }; static lua_plot *check(lua_State *L, int index); - - int window_id; - int slot_id; }; #endif diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 0f28020b..4118843b 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -25,7 +25,7 @@ extern "C" { #include "lua-plot.h" #include "lua-plot-cpp.h" -#include "object-index.h" +#include "win-plot-refs.h" #include "window.h" #include "gs-types.h" #include "lua-utils.h" @@ -47,13 +47,14 @@ static int plot_add_line (lua_State *L); static int plot_index (lua_State *L); static int plot_newindex (lua_State *L); static int plot_free (lua_State *L); -// static int plot_show (lua_State *L); +static int plot_show (lua_State *L); static int plot_title_set (lua_State *L); static int plot_title_get (lua_State *L); static int plot_units_set (lua_State *L); static int plot_units_get (lua_State *L); -static int plot_add_gener (lua_State *L, bool as_line); +static int plot_add_gener (lua_State *L, bool as_line); +static void plot_update_raw (lua_State *L, int plot_index); static const struct luaL_Reg plot_functions[] = { {"plot", plot_new}, @@ -64,7 +65,7 @@ static const struct luaL_Reg plot_methods[] = { {"add", plot_add }, {"addline", plot_add_line }, {"update", plot_update }, - // {"show", plot_show }, + {"show", plot_show }, {"__index", plot_index }, {"__newindex", plot_newindex }, {"__gc", plot_free }, @@ -91,27 +92,6 @@ lua_plot::check(lua_State *L, int index) return (lua_plot *) gs_check_userdata (L, index, GS_PLOT); } -void -lua_plot::update_window(lua_State *L) -{ - if (this->window_id <= 0) - return; - - object_index_get (L, OBJECT_WINDOW, this->window_id); - - if (gs_is_userdata (L, lua_gettop (L), GS_WINDOW)) - { - lua_pushcfunction (L, window_slot_update_unprotected); - lua_insert (L, -2); - lua_pushinteger (L, this->slot_id); - lua_call (L, 2, 0); - } - else - { - lua_pop (L, 1); - } -} - int plot_new (lua_State *L) { @@ -147,7 +127,7 @@ plot_add_gener (lua_State *L, bool as_line) AGG_LOCK(); p->self().add(obj, color, as_line); - p->update_window(L); + plot_update_raw (L, 1); AGG_UNLOCK(); @@ -178,7 +158,7 @@ plot_title_set (lua_State *L) AGG_LOCK(); p->self().set_title(title); - p->update_window(L); + plot_update_raw (L, 1); AGG_UNLOCK(); @@ -214,7 +194,7 @@ plot_units_set (lua_State *L) if (current != request) { plt.set_units(request); - p->update_window(L); + plot_update_raw (L, 1); } AGG_UNLOCK(); @@ -249,25 +229,32 @@ plot_newindex (lua_State *L) return mlua_newindex_with_properties (L, plot_properties_set); } +void +plot_update_raw (lua_State *L, int plot_index) +{ + window_plot_rev_lookup_apply (L, plot_index, window_slot_update_unprotected); +} + int plot_update (lua_State *L) { lua_plot *p = lua_plot::check(L, 1); AGG_LOCK(); - p->update_window(L); + plot_update_raw (L, 1); AGG_UNLOCK(); return 0; } -/* int plot_show (lua_State *L) { - lua_plot *p = lua_plot::check(L, 1); - p->start_new_thread (L); - return 1; + lua_pushcfunction (L, window_attach); + window_new (L); + lua_pushvalue (L, 1); + lua_pushstring (L, ""); + lua_call (L, 3, 0); + return 0; } -*/ void plot_register (lua_State *L) diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index 5c9a2bb6..7d10e346 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -17,10 +17,8 @@ extern "C" { __BEGIN_DECLS -static int window_new (lua_State *L); static int window_free (lua_State *L); static int window_split (lua_State *L); -static int window_attach (lua_State *L); static const struct luaL_Reg window_functions[] = { {"window", window_new}, @@ -304,13 +302,8 @@ window_attach (lua_State *L) if (slot_id >= 0) { - plot->window_id = win->id; - plot->slot_id = slot_id; - win->draw_slot(slot_id, true); - win->unlock(); - window_plot_ref_add (L, slot_id, 1, 2); } else diff --git a/agg-plot/window.h b/agg-plot/window.h index 1c7858de..803aa3e1 100644 --- a/agg-plot/window.h +++ b/agg-plot/window.h @@ -12,6 +12,8 @@ extern void window_register (lua_State *L); extern int window_slot_update_unprotected (lua_State *L); extern int window_update_unprotected (lua_State *L); extern int window_update (lua_State *L); +extern int window_new (lua_State *L); +extern int window_attach (lua_State *L); __END_DECLS diff --git a/win-plot-refs.c b/win-plot-refs.c index 3dbd4dd9..bd7a642a 100644 --- a/win-plot-refs.c +++ b/win-plot-refs.c @@ -60,3 +60,33 @@ window_plot_ref_remove (lua_State *L, int slot_id, int window_index) lua_pop (L, 2); } + +void +window_plot_rev_lookup_apply (lua_State *L, int plot_index, lua_CFunction func) +{ + INDEX_SET_ABS(L, plot_index); + + lua_getfield (L, LUA_REGISTRYINDEX, window_plot_ref_table_name); + lua_pushnil (L); + + while (lua_next (L, -2) != 0) + { + lua_pushnil (L); + + while (lua_next (L, -2) != 0) + { + if (lua_rawequal (L, -1, plot_index)) + { + lua_pushcfunction (L, func); + lua_pushvalue (L, -5); + lua_pushvalue (L, -4); + lua_call (L, 2, 0); + } + lua_pop (L, 1); + } + + lua_pop (L, 1); + } + + lua_pop (L, 1); +} diff --git a/win-plot-refs.h b/win-plot-refs.h index 5fa7cdb4..485727d7 100644 --- a/win-plot-refs.h +++ b/win-plot-refs.h @@ -14,6 +14,9 @@ extern void window_plot_ref_add (lua_State *L, int slot_id, extern void window_plot_ref_remove (lua_State *L, int slot_id, int window_index); +extern void window_plot_rev_lookup_apply (lua_State *L, int plot_index, + lua_CFunction func); + __END_DECLS #endif |