From 9cd1461d668ec3c38700a5a88fc9bd1fd9b79cc3 Mon Sep 17 00:00:00 2001 From: francesco-ST Date: Thu, 3 Feb 2011 14:31:50 +0100 Subject: Changed plot objects reference strategy to use Lua set/getfenv. The weak table for plot references is removed. --- agg-plot/lua-plot.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'agg-plot/lua-plot.cpp') diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index 4fc4b738..c3122a2d 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -116,6 +116,9 @@ plot_new (lua_State *L) typedef plot_auto plot_type; lua_plot *p = push_new_object(L, GS_PLOT); + lua_newtable (L); + lua_setfenv (L, -2); + if (lua_isstring (L, 1)) { const char *title = lua_tostring (L, 1); @@ -131,6 +134,9 @@ canvas_new (lua_State *L) { lua_plot *p = push_new_object(L, GS_PLOT); + lua_newtable (L); + lua_setfenv (L, -2); + p->sync_mode(false); if (lua_isstring (L, 1)) @@ -181,7 +187,8 @@ plot_add_gener (lua_State *L, bool as_line) if (st.error_msg()) return luaL_error (L, "%s in %s", st.error_msg(), st.context()); - object_refs_add (L, table_plot_obj, p->current_layer_index(), 1, 2); + lua_getfenv (L, 1); + objref_mref_add (L, -1, p->current_layer_index(), 2); return 0; } @@ -336,12 +343,21 @@ plot_push_layer (lua_State *L) return 0; } +static void +plot_ref_clear (lua_State *L, int index, int layer_id) +{ + lua_getfenv (L, index); + lua_newtable (L); + lua_rawseti (L, -2, layer_id); + lua_pop (L, 1); + } + int plot_pop_layer (lua_State *L) { lua_plot *p = object_check(L, 1, GS_PLOT); - object_refs_remove (L, table_plot_obj, p->current_layer_index(), 1); + plot_ref_clear (L, 1, p->current_layer_index()); AGG_LOCK(); p->pop_layer(); @@ -356,7 +372,7 @@ plot_clear (lua_State *L) { lua_plot *p = object_check(L, 1, GS_PLOT); - object_refs_remove (L, table_plot_obj, p->current_layer_index(), 1); + plot_ref_clear (L, 1, p->current_layer_index()); AGG_LOCK(); p->clear_current_layer(); -- cgit v1.2.3

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