gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat
-rw-r--r--agg-plot/plot-window.cpp 4
-rw-r--r--lua-gsl.c 5
-rw-r--r--lua-utils.c 62
-rw-r--r--lua-utils.h 4
4 files changed, 47 insertions, 28 deletions
diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp
index 74005134..6c89ec85 100644
--- a/agg-plot/plot-window.cpp
+++ b/agg-plot/plot-window.cpp
@@ -161,9 +161,7 @@ plot_window_add_gener (lua_State *L, bool as_line)
drawable *obj = parse_graph_args (L);
agg::rgba8 *color = check_color_rgba8 (L, 3);
- lua_pushvalue (L, 1);
- mlua_fenv_addref (L, 2);
- lua_pop (L, 1);
+ mlua_plotref_add (L, 1, 2);
AGG_LOCK();
diff --git a/lua-gsl.c b/lua-gsl.c
index 1ea3ca2b..fe4a7a8d 100644
--- a/lua-gsl.c
+++ b/lua-gsl.c
@@ -45,7 +45,6 @@
#include "bspline.h"
#ifdef AGG_PLOT_ENABLED
-/* #include "lua-plot.h" */
#include "lua-draw.h"
#include "canvas-window.h"
#include "plot-window.h"
@@ -58,7 +57,10 @@ luaopen_gsl (lua_State *L)
{
gsl_set_error_handler_off ();
+#ifdef AGG_PLOT_ENABLED
prepare_window_ref_table (L);
+ prepare_plotref_table (L);
+#endif
#ifdef USE_SEPARATE_NAMESPACE
luaL_register (L, MLUA_GSLLIBNAME, gsl_methods_dummy);
@@ -83,7 +85,6 @@ luaopen_gsl (lua_State *L)
mlinear_register (L);
bspline_register (L);
#ifdef AGG_PLOT_ENABLED
- /* plot_register (L); */
draw_register (L);
canvas_window_register (L);
plot_window_register (L);
diff --git a/lua-utils.c b/lua-utils.c
index 9e14562a..d9006b30 100644
--- a/lua-utils.c
+++ b/lua-utils.c
@@ -26,6 +26,7 @@
#include "gs-types.h"
char const * const CACHE_FIELD_NAME = "__cache";
+char const * const registry_plotref_name = "GSL.plotref";
const struct luaL_Reg *
mlua_find_method (const struct luaL_Reg *p, const char *key)
@@ -226,28 +227,6 @@ mlua_fenv_get (lua_State *L, int index, int fenv_index)
}
void
-mlua_fenv_addref (lua_State *L, int refindex)
-{
- int n;
- lua_getfenv (L, -1);
- n = lua_objlen (L, -1);
- lua_pushvalue (L, refindex);
- lua_rawseti (L, -2, n+1);
- lua_pop (L, 1);
-}
-
-#if 0
-void
-mlua_set_fenv_ref (lua_State *L, int refindex)
-{
- lua_newtable (L);
- lua_pushvalue (L, refindex);
- lua_rawseti (L, -2, 1);
- lua_setfenv (L, -2);
-}
-#endif
-
-void
prepare_window_ref_table (lua_State *L)
{
lua_newtable (L);
@@ -284,3 +263,42 @@ mlua_window_unref(lua_State *L, int id)
lua_rawseti (L, -2, id);
lua_pop (L, 1);
}
+
+void
+prepare_plotref_table (lua_State *L)
+{
+ 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, registry_plotref_name);
+}
+
+void
+mlua_plotref_add (lua_State *L, int key_index, int val_index)
+{
+ size_t n;
+
+ lua_getfield (L, LUA_REGISTRYINDEX, registry_plotref_name);
+ lua_pushvalue (L, key_index);
+ lua_pushvalue (L, key_index);
+ lua_rawget (L, -3);
+
+ if (lua_isnil (L, -1))
+ {
+ lua_pop (L, 1);
+ lua_newtable (L);
+ }
+
+ n = lua_objlen (L, -1);
+
+ lua_pushvalue (L, val_index);
+ lua_rawseti (L, -2, n + 1);
+
+ lua_rawset (L, -3);
+ lua_pop (L, 1);
+}
diff --git a/lua-utils.h b/lua-utils.h
index 2db36e05..b7382863 100644
--- a/lua-utils.h
+++ b/lua-utils.h
@@ -66,13 +66,15 @@ extern lua_Number mlua_named_number (lua_State *L, int index,
extern void mlua_fenv_set (lua_State *L, int index, int fenv_index);
extern void mlua_fenv_get (lua_State *L, int index, int fenv_index);
-extern void mlua_fenv_addref (lua_State *L, int refindex);
extern void mlua_set_fenv_ref (lua_State *L, int refidx);
extern int mlua_window_ref (lua_State *L, int index);
extern void mlua_window_unref (lua_State *L, int id);
extern void prepare_window_ref_table (lua_State *L);
+extern void prepare_plotref_table (lua_State *L);
+extern void mlua_plotref_add (lua_State *L, int key_index, int val_index);
+
__END_DECLS
generated by cgit v1.2.3 (git 2.46.0) at 2025年10月04日 14:54:50 +0000

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