-rw-r--r-- | agg-plot/Makefile | 2 | ||||
-rw-r--r-- | agg-plot/canvas-window.cpp | 4 | ||||
-rw-r--r-- | agg-plot/lua-plot.cpp | 37 | ||||
-rw-r--r-- | agg-plot/window.cpp | 11 | ||||
-rw-r--r-- | agg-plot/window_registry.cpp | 172 | ||||
-rw-r--r-- | agg-plot/window_registry.h | 27 |
diff --git a/agg-plot/Makefile b/agg-plot/Makefile index d9a3040a..97637ef2 100644 --- a/agg-plot/Makefile +++ b/agg-plot/Makefile @@ -44,7 +44,7 @@ endif INCLUDES += $(AGG_INCLUDES) -I$(GSH_BASE_DIR) -I$(LUADIR)/src -AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp markers.cpp lua-draw.cpp lua-text.cpp text.cpp agg-parse-trans.cpp window.cpp lua-plot.cpp canvas-window.cpp bitmap-plot.cpp +AGGPLOT_SRC_FILES = $(PLATSUP_SRC_FILES) utils.cpp units.cpp colors.cpp markers.cpp lua-draw.cpp lua-text.cpp text.cpp agg-parse-trans.cpp window_registry.cpp window.cpp lua-plot.cpp canvas-window.cpp bitmap-plot.cpp AGGPLOT_OBJ_FILES := $(AGGPLOT_SRC_FILES:%.cpp=%.o) diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp index f5a1bdaf..ddc18fa9 100644 --- a/agg-plot/canvas-window.cpp +++ b/agg-plot/canvas-window.cpp @@ -25,7 +25,7 @@ #include "agg-parse-trans.h" #include "lua-cpp-utils.h" #include "lua-utils.h" -#include "object-index.h" +#include "window_registry.h" #include "lua-draw.h" #include "gs-types.h" #include "colors.h" @@ -109,7 +109,7 @@ canvas_thread_function (void *_inf) win->unlock(); GSL_SHELL_LOCK(); - object_index_remove (inf->L, inf->window_id); + window_index_remove (inf->L, inf->window_id); GSL_SHELL_UNLOCK(); return NULL; diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index c3122a2d..9bb9eda3 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -30,7 +30,7 @@ extern "C" { #include "window.h" #include "gs-types.h" #include "lua-utils.h" -#include "object-refs.h" +#include "window_registry.h" #include "lua-cpp-utils.h" #include "lua-draw.h" #include "colors.h" @@ -176,6 +176,31 @@ plot_add_gener_cpp (lua_State *L, lua_plot *p, bool as_line, } } +static void +objref_mref_add (lua_State *L, int table_index, int index, int value_index) +{ + int n; + INDEX_SET_ABS(L, table_index); + + lua_rawgeti (L, table_index, index); + if (lua_isnil (L, -1)) + { + lua_pop (L, 1); + lua_newtable (L); + lua_pushvalue (L, -1); + lua_rawseti (L, table_index, index); + n = 0; + } + else + { + n = lua_objlen (L, -1); + } + + lua_pushvalue (L, value_index); + lua_rawseti (L, -2, n+1); + lua_pop (L, 1); +} + int plot_add_gener (lua_State *L, bool as_line) { @@ -277,7 +302,7 @@ plot_newindex (lua_State *L) void plot_update_raw (lua_State *L, lua_plot *p, int plot_index) { - object_refs_lookup_apply (L, table_window_plot, plot_index, window_slot_update); + window_refs_lookup_apply (L, plot_index, window_slot_update); p->commit_pending_draw(); } @@ -293,7 +318,7 @@ int plot_flush (lua_State *L) { lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); - object_refs_lookup_apply (L, table_window_plot, 1, window_slot_refresh); + window_refs_lookup_apply (L, 1, window_slot_refresh); p->commit_pending_draw(); return 0; } @@ -332,13 +357,13 @@ plot_push_layer (lua_State *L) { lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); - object_refs_lookup_apply (L, table_window_plot, 1, window_slot_refresh); + window_refs_lookup_apply (L, 1, window_slot_refresh); AGG_LOCK(); p->push_layer(); AGG_UNLOCK(); - object_refs_lookup_apply (L, table_window_plot, 1, window_save_slot_image); + window_refs_lookup_apply (L, 1, window_save_slot_image); return 0; } @@ -378,7 +403,7 @@ plot_clear (lua_State *L) p->clear_current_layer(); AGG_UNLOCK(); - object_refs_lookup_apply (L, table_window_plot, 1, window_restore_slot_image); + window_refs_lookup_apply (L, 1, window_restore_slot_image); if (p->sync_mode()) plot_update_raw (L, p, 1); diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index 398efbdc..11120575 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -6,11 +6,10 @@ extern "C" { #include "lua-defs.h" #include "window-cpp.h" +#include "window_registry.h" #include "lua-draw.h" #include "lua-cpp-utils.h" #include "gs-types.h" -#include "object-refs.h" -#include "object-index.h" #include "colors.h" #include "lua-plot-cpp.h" #include "split-parser.h" @@ -289,7 +288,7 @@ window::cleanup_tree_rec (lua_State *L, int window_index, ref::node* n) if (ref) { if (ref->plot) - object_refs_remove (L, table_window_plot, ref->slot_id, window_index); + window_refs_remove (L, ref->slot_id, window_index); } } @@ -420,12 +419,12 @@ void window::start (lua_State *L, gslshell::ret_status& st) typedef canvas_window::thread_info thread_info; std::auto_ptr<thread_info> inf(new thread_info(L, this)); - this->window_id = object_index_add (L, -1); + this->window_id = window_index_add (L, -1); inf->window_id = this->window_id; if (! this->start_new_thread (inf)) { - object_index_remove (L, this->window_id); + window_index_remove (L, this->window_id); this->unlock(); st.error("error during thread initialization", "window creation"); } @@ -519,7 +518,7 @@ window_attach (lua_State *L) if (win->status == canvas_window::running) win->draw_slot(slot_id, true); win->unlock(); - object_refs_add (L, table_window_plot, slot_id, 1, 2); + window_refs_add (L, slot_id, 1, 2); } else { diff --git a/agg-plot/window_registry.cpp b/agg-plot/window_registry.cpp new file mode 100644 index 00000000..4c59e8f7 --- /dev/null +++ b/agg-plot/window_registry.cpp @@ -0,0 +1,172 @@ + +#include "lua-defs.h" +#include "window_registry.h" + +static char const * const refs_tname = "GSL.oirfs.wp"; +static char const * const registry_tname = "GSL.reg.wins"; + +void +window_registry_prepare (lua_State *L) +{ + lua_newtable (L); + lua_setfield (L, LUA_REGISTRYINDEX, registry_tname); + + lua_newtable (L); + lua_setfield (L, LUA_REGISTRYINDEX, refs_tname); +} + +int +window_index_add(lua_State *L, int index) +{ + int n; + + if (index < 0) + index = lua_gettop (L) - (index+1); + + lua_getfield (L, LUA_REGISTRYINDEX, registry_tname); + + n = lua_objlen (L, -1); + + lua_pushvalue (L, index); + lua_rawseti (L, -2, n+1); + lua_pop (L, 1); + + return n+1; +} + +void +window_index_get (lua_State *L, int id) +{ + lua_getfield (L, LUA_REGISTRYINDEX, registry_tname); + lua_rawgeti (L, -1, id); + lua_remove (L, -2); +} + +void +window_index_remove (lua_State *L, int id) +{ + lua_getfield (L, LUA_REGISTRYINDEX, registry_tname); + lua_getfield (L, LUA_REGISTRYINDEX, refs_tname); + lua_rawgeti (L, -2, id); + if (! lua_isnil (L, -1)) + { + lua_pushnil (L); + lua_rawset (L, -3); + lua_pop (L, 1); + } + else + { + lua_pop (L, 2); + } + + lua_pushnil (L); + lua_rawseti (L, -2, id); + lua_pop (L, 1); +} + +void +window_index_apply_all (lua_State *L, lua_CFunction f) +{ + lua_getfield (L, LUA_REGISTRYINDEX, registry_tname); + + lua_pushnil (L); /* first key */ + while (lua_next(L, -2) != 0) + { + lua_pushcfunction (L, f); + lua_insert (L, -2); + lua_call (L, 1, 0); + } + + lua_pop (L, 1); +} + +int +window_index_count (lua_State *L) +{ + int count = 0; + + lua_getfield (L, LUA_REGISTRYINDEX, registry_tname); + + lua_pushnil (L); /* first key */ + while (lua_next(L, -2) != 0) + { + lua_pop (L, 1); + count ++; + } + + lua_pop (L, 1); + + return count; +} + +void +window_refs_add (lua_State *L, int index, int key_index, int value_index) +{ + INDEX_SET_ABS_2(L, key_index, value_index); + + lua_getfield (L, LUA_REGISTRYINDEX, refs_tname); + lua_pushvalue (L, key_index); + lua_rawget (L, -2); + + if (lua_isnil (L, -1)) + { + lua_pop (L, 1); + lua_newtable (L); + lua_pushvalue (L, key_index); + lua_pushvalue (L, -2); + lua_rawset (L, -4); + } + + lua_pushvalue (L, value_index); + lua_rawseti (L, -2, index); + + lua_pop (L, 2); +} + +void +window_refs_remove (lua_State *L, int index, int key_index) +{ + INDEX_SET_ABS(L, key_index); + + lua_getfield (L, LUA_REGISTRYINDEX, refs_tname); + lua_pushvalue (L, key_index); + lua_rawget (L, -2); + + if (! lua_isnil (L, -1)) + { + lua_pushnil (L); + lua_rawseti (L, -2, index); + } + + lua_pop (L, 2); +} + +void +window_refs_lookup_apply (lua_State *L, int value_index, lua_CFunction func) +{ + INDEX_SET_ABS(L, value_index); + + lua_getfield (L, LUA_REGISTRYINDEX, refs_tname); + lua_pushnil (L); + + while (lua_next (L, -2) != 0) + { + lua_pushnil (L); + + while (lua_next (L, -2) != 0) + { + if (lua_rawequal (L, -1, value_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/agg-plot/window_registry.h b/agg-plot/window_registry.h new file mode 100644 index 00000000..1711ea8b --- /dev/null +++ b/agg-plot/window_registry.h @@ -0,0 +1,27 @@ +#ifndef WINDOW_REGISTRY_H +#define WINDOW_REGISTRY_H + +#include "defs.h" + +__BEGIN_DECLS + +#include "lua.h" +#include "lauxlib.h" + +extern void window_registry_prepare (lua_State *L); + +extern int window_index_add (lua_State *L, int index); +extern void window_index_get (lua_State *L, int id); +extern void window_index_remove (lua_State *L, int id); +extern void window_index_apply_all (lua_State *L, lua_CFunction f); +extern int window_index_count (lua_State *L); + +extern void window_refs_add (lua_State *L, int index, int key_index, + int value_index); +extern void window_refs_remove (lua_State *L, int index, int key_index); +extern void window_refs_lookup_apply (lua_State *L, int value_index, + lua_CFunction func); + +__END_DECLS + +#endif |