From f9f49265522fe933fd6ca726ecd23bf33c9aae09 Mon Sep 17 00:00:00 2001 From: francesco-ST Date: Thu, 3 Feb 2011 15:56:02 +0100 Subject: Introduced window registry and changed win/plot weak table to ordinary. Now the table that store the window <-> plot relations is no more weak on the keys (windows). The windows are removed from the table when the event loop thread of the windows terminates. In this way we don't depend on the GC and we avoid the problems with delayed removal of the keys. --- agg-plot/lua-plot.cpp | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'agg-plot/lua-plot.cpp') 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(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(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); -- cgit v1.2.3

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