author | francesco-ST <francesco.abbate@st.com> | 2011年02月03日 15:56:02 +0100 |
---|---|---|
committer | francesco-ST <francesco.abbate@st.com> | 2011年02月03日 15:56:02 +0100 |
commit | f9f49265522fe933fd6ca726ecd23bf33c9aae09 (patch) | |
tree | 59a12e3870bca9379cd99adf673ce0aa6536656e | |
parent | 9cd1461d668ec3c38700a5a88fc9bd1fd9b79cc3 (diff) | |
download | gsl-shell-f9f49265522fe933fd6ca726ecd23bf33c9aae09.tar.gz |
-rw-r--r-- | Makefile | 1 | ||||
-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 | ||||
-rw-r--r-- | gsl-shell.c | 6 | ||||
-rw-r--r-- | lua-gsl.c | 27 | ||||
-rw-r--r-- | object-index.c | 85 | ||||
-rw-r--r-- | object-index.h | 19 | ||||
-rw-r--r-- | object-refs.c | 126 | ||||
-rw-r--r-- | object-refs.h | 28 | ||||
-rw-r--r-- | refs.c | 19 | ||||
-rw-r--r-- | refs.h | 14 |
@@ -94,7 +94,6 @@ ifeq ($(strip $(ENABLE_AGG_PLOT)), yes) LUA_BASE_DIRS += pre3d LUA_BASE_FILES += draw.lua contour.lua hpcontour.lua plcurve.lua plot3d.lua \ pre3d/pre3d.lua pre3d/pre3d_shape_utils.lua - C_SRC_FILES += refs.c object-index.c object-refs.c INCLUDES += $(PTHREADS_CFLAGS) -Iagg-plot SUBDIRS += agg-plot DEFS += -DAGG_PLOT_ENABLED 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 diff --git a/gsl-shell.c b/gsl-shell.c index f716296d..ecb9d6cb 100644 --- a/gsl-shell.c +++ b/gsl-shell.c @@ -65,8 +65,8 @@ #include "lua-utils.h" #if defined(GSL_SHELL_DEBUG) && defined(AGG_PLOT_ENABLED) -#include "object-index.h" #include "window.h" +#include "window_registry.h" #include "debug-support.h" #endif @@ -361,7 +361,7 @@ static void dotty (lua_State *L) { } #if defined(GSL_SHELL_DEBUG) && defined(AGG_PLOT_ENABLED) - object_index_apply_all (L, window_close); + window_index_apply_all (L, window_close); do { @@ -369,7 +369,7 @@ static void dotty (lua_State *L) { msleep(50); GSL_SHELL_LOCK(); } - while (object_index_count (L) > 0); + while (window_index_count (L) > 0); #endif lua_settop(L, 0); /* clear stack */ @@ -48,8 +48,7 @@ #include "interp.h" #ifdef AGG_PLOT_ENABLED -#include "object-index.h" -#include "object-refs.h" +#include "window_registry.h" #include "lua-draw.h" #include "lua-text.h" #include "window.h" @@ -60,14 +59,23 @@ static const struct luaL_Reg gsl_methods_dummy[] = {{NULL, NULL}}; #endif +#ifdef GSL_SHELL_DEBUG + +static int gsl_shell_lua_registry (lua_State *L); + +static const struct luaL_Reg gsl_shell_debug_functions[] = { + {"registry", gsl_shell_lua_registry}, + {NULL, NULL} +}; +#endif + int luaopen_gsl (lua_State *L) { gsl_set_error_handler_off (); #ifdef AGG_PLOT_ENABLED - object_index_prepare (L); - object_refs_prepare (L); + window_registry_prepare (L); #endif #ifdef LUA_STRICT @@ -107,7 +115,18 @@ luaopen_gsl (lua_State *L) ode_complex_register (L); solver_complex_register (L); + luaL_register (L, NULL, gsl_shell_debug_functions); + lua_pop (L, 1); return 1; } + +#ifdef GSL_SHELL_DEBUG +int +gsl_shell_lua_registry (lua_State *L) +{ + lua_pushvalue (L, LUA_REGISTRYINDEX); + return 1; +} +#endif diff --git a/object-index.c b/object-index.c deleted file mode 100644 index 4074511c..00000000 --- a/object-index.c +++ /dev/null @@ -1,85 +0,0 @@ - -#include <lua.h> -#include <lauxlib.h> - -#include "object-index.h" - -static const char *table_name = "GSL.reg.wins"; - -void -object_index_prepare (lua_State *L) -{ - lua_newtable (L); - lua_setfield (L, LUA_REGISTRYINDEX, table_name); -} - -int -object_index_add(lua_State *L, int index) -{ - int n; - - if (index < 0) - index = lua_gettop (L) - (index+1); - - lua_getfield (L, LUA_REGISTRYINDEX, table_name); - - n = lua_objlen (L, -1); - - lua_pushvalue (L, index); - lua_rawseti (L, -2, n+1); - lua_pop (L, 1); - - return n+1; -} - -void -object_index_get (lua_State *L, int id) -{ - lua_getfield (L, LUA_REGISTRYINDEX, table_name); - lua_rawgeti (L, -1, id); - lua_remove (L, -2); -} - -void -object_index_remove (lua_State *L, int id) -{ - lua_getfield (L, LUA_REGISTRYINDEX, table_name); - lua_pushnil (L); - lua_rawseti (L, -2, id); - lua_pop (L, 1); -} - -void -object_index_apply_all (lua_State *L, lua_CFunction f) -{ - lua_getfield (L, LUA_REGISTRYINDEX, table_name); - - 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 -object_index_count (lua_State *L) -{ - int count = 0; - - lua_getfield (L, LUA_REGISTRYINDEX, table_name); - - lua_pushnil (L); /* first key */ - while (lua_next(L, -2) != 0) - { - lua_pop (L, 1); - count ++; - } - - lua_pop (L, 1); - - return count; -} diff --git a/object-index.h b/object-index.h deleted file mode 100644 index a2bc0a73..00000000 --- a/object-index.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef OBJECT_INDEX_H -#define OBJECT_INDEX_H - -#include "defs.h" - -__BEGIN_DECLS - -#include "lua.h" - -extern void object_index_prepare (lua_State *L); -extern int object_index_add (lua_State *L, int index); -extern void object_index_get (lua_State *L, int id); -extern void object_index_remove (lua_State *L, int id); -extern void object_index_apply_all (lua_State *L, lua_CFunction f); -extern int object_index_count (lua_State *L); - -__END_DECLS - -#endif diff --git a/object-refs.c b/object-refs.c deleted file mode 100644 index 9b561b96..00000000 --- a/object-refs.c +++ /dev/null @@ -1,126 +0,0 @@ - -#include <lua.h> -#include <lauxlib.h> -#include <assert.h> - -#include "lua-defs.h" -#include "refs.h" -#include "object-refs.h" - -static char const * const table_name[] = {"GSL.oirfs.wp"}; -static bool table_mult_valued[] = {false}; - -void -object_refs_prepare (lua_State *L) -{ - assert (table_window_plot == 0); - register_ref_table (L, table_name[0]); -} - -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); -} - -void -object_refs_add (lua_State *L, int table, int index, - int key_index, int value_index) -{ - bool mult = table_mult_valued[table]; - - INDEX_SET_ABS_2(L, key_index, value_index); - - lua_getfield (L, LUA_REGISTRYINDEX, table_name[table]); - 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); - } - - if (mult) - objref_mref_add (L, -1, index, value_index); - else - { - lua_pushvalue (L, value_index); - lua_rawseti (L, -2, index); - } - - lua_pop (L, 2); -} - -void -object_refs_remove (lua_State *L, int table, int index, int key_index) -{ - INDEX_SET_ABS(L, key_index); - - lua_getfield (L, LUA_REGISTRYINDEX, table_name[table]); - 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 -object_refs_lookup_apply (lua_State *L, int table, int value_index, - lua_CFunction func) -{ - assert (! table_mult_valued[table]); - - INDEX_SET_ABS(L, value_index); - - lua_getfield (L, LUA_REGISTRYINDEX, table_name[table]); - 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/object-refs.h b/object-refs.h deleted file mode 100644 index 01186576..00000000 --- a/object-refs.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef OBJECT_REFS_H -#define OBJECT_REFS_H - -#include "defs.h" - -__BEGIN_DECLS - -#include "lua.h" - -enum object_table_e { table_window_plot = 0 }; - -extern void object_refs_prepare (lua_State *L); - -extern void object_refs_add (lua_State *L, int table, int index, - int key_index, int value_index); - -extern void object_refs_remove (lua_State *L, int table, int index, int key_index); - -extern void object_refs_lookup_apply (lua_State *L, int table, int value_index, - lua_CFunction func); - -extern void objref_mref_add (lua_State *L, int table_index, int index, - int value_index); - - -__END_DECLS - -#endif diff --git a/refs.c b/refs.c deleted file mode 100644 index 3be5307e..00000000 --- a/refs.c +++ /dev/null @@ -1,19 +0,0 @@ - -#include "lua.h" -#include "lauxlib.h" - -#include "refs.h" - -void -register_ref_table (lua_State *L, const char *table_name) -{ - lua_newtable (L); - - /* the metatable to define it as a weak table */ - lua_newtable (L); - lua_pushstring (L, "k"); - lua_setfield (L, -2, "__mode"); - lua_setmetatable (L, -2); - - lua_setfield (L, LUA_REGISTRYINDEX, table_name); -} diff --git a/refs.h b/refs.h deleted file mode 100644 index fac4c7b5..00000000 --- a/refs.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef REFS_H -#define REFS_H - -#include "defs.h" - -__BEGIN_DECLS - -#include "lua.h" - -extern void register_ref_table (lua_State *L, const char *table_name); - -__END_DECLS - -#endif |