gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/lua-plot.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年12月20日 14:30:02 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年12月21日 09:24:17 +0100
commit751dcf17daffe9c66d4f5227014a80790bd6ac84 (patch)
tree0ce1318510e1fb2b5f2e1fd26aed76589cb1d946 /agg-plot/lua-plot.cpp
parentc16aebdd99c9f0ec0639ec207d4405a983cf2149 (diff)
downloadgsl-shell-751dcf17daffe9c66d4f5227014a80790bd6ac84.tar.gz
Better code factorization in Lua plot interface functions
Diffstat (limited to 'agg-plot/lua-plot.cpp')
-rw-r--r--agg-plot/lua-plot.cpp 109
1 files changed, 50 insertions, 59 deletions
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 0a80e79a..d041b888 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -242,93 +242,110 @@ plot_add_line (lua_State *L)
return plot_add_gener (L, true);
}
-static int plot_string_property_get (lua_State* L, const char* (lua_plot::*getter)() const)
+static int plot_string_property_get (lua_State* L, const char* (sg_plot::*getter)() const)
{
- lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT);
+ sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
AGG_LOCK();
const char *title = (p->*getter)();
lua_pushstring (L, title);
AGG_UNLOCK();
-
return 1;
}
-static int plot_string_property_set (lua_State* L, void (lua_plot::*setter)(const char*))
+static void plot_string_property_set (lua_State* L, void (sg_plot::*setter)(const char*), bool update)
{
sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
const char *s = lua_tostring (L, 2);
if (s == NULL)
- return gs_type_error (L, 2, "string");
+ gs_type_error (L, 2, "string");
AGG_LOCK();
(p->*setter)(s);
AGG_UNLOCK();
- plot_update_raw (L, p, 1);
-
- return 0;
+ if (update)
+ plot_update_raw (L, p, 1);
+}
+
+static int plot_bool_property_get(lua_State* L, bool (sg_plot::*getter)() const)
+{
+ sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
+ AGG_LOCK();
+ bool r = (p->*getter)();
+ lua_pushboolean(L, (int)r);
+ AGG_UNLOCK();
+ return 1;
+}
+
+static void plot_bool_property_set(lua_State* L, void (sg_plot::*setter)(bool), bool update)
+{
+ sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
+
+ if (!lua_isboolean(L, 2))
+ gs_type_error (L, 2, "boolean");
+
+ bool request = (bool) lua_toboolean (L, 2);
+
+ AGG_LOCK();
+ (p->*setter)(request);
+ AGG_UNLOCK();
+
+ if (update)
+ plot_update_raw (L, p, 1);
}
int
plot_title_set (lua_State *L)
{
- return plot_string_property_set(L, &lua_plot::set_title);
+ plot_string_property_set(L, &sg_plot::set_title, true);
+ return 0;
}
int
plot_title_get (lua_State *L)
{
- return plot_string_property_get(L, &gs_plot::title);
+ return plot_string_property_get(L, &sg_plot::title);
}
int
plot_xlab_set (lua_State *L)
{
- return plot_string_property_set(L, &lua_plot::set_xlabel);
+ plot_string_property_set(L, &sg_plot::set_xlabel, true);
+ return 0;
}
int
plot_xlab_get (lua_State *L)
{
- return plot_string_property_get(L, &lua_plot::xlabel);
+ return plot_string_property_get(L, &sg_plot::xlabel);
}
int
plot_ylab_set (lua_State *L)
{
- return plot_string_property_set(L, &lua_plot::set_ylabel);
+ plot_string_property_set(L, &sg_plot::set_ylabel, true);
+ return 0;
}
int
plot_ylab_get (lua_State *L)
{
- return plot_string_property_get(L, &lua_plot::ylabel);
+ return plot_string_property_get(L, &sg_plot::ylabel);
}
int
plot_units_set (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- bool request = (bool) lua_toboolean (L, 2);
- AGG_LOCK();
- p->set_units(request);
- AGG_UNLOCK();
- plot_update_raw (L, p, 1);
+ plot_bool_property_set(L, &sg_plot::set_units, true);
return 0;
}
int
plot_units_get (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
-
- AGG_LOCK();
- lua_pushboolean (L, p->use_units());
- AGG_UNLOCK();
-
- return 1;
+ return plot_bool_property_get(L, &sg_plot::use_units);
}
int
@@ -484,62 +501,36 @@ plot_save_svg (lua_State *L)
static int plot_pad_mode_set (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- bool request = (bool) lua_toboolean (L, 2);
- AGG_LOCK();
- p->pad_mode(request);
- AGG_UNLOCK();
- plot_update_raw (L, p, 1);
+ plot_bool_property_set(L, &sg_plot::pad_mode, true);
return 0;
}
static int plot_pad_mode_get (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- AGG_LOCK();
- lua_pushboolean (L, p->pad_mode());
- AGG_UNLOCK();
- return 1;
+ return plot_bool_property_get(L, &sg_plot::pad_mode);
}
static int plot_clip_mode_set (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- bool request = (bool) lua_toboolean (L, 2);
- AGG_LOCK();
- p->set_clip_mode(request);
- AGG_UNLOCK();
- plot_update_raw (L, p, 1);
+ plot_bool_property_set(L, &sg_plot::set_clip_mode, true);
return 0;
}
static int plot_clip_mode_get (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- AGG_LOCK();
- lua_pushboolean (L, p->clip_is_active());
- AGG_UNLOCK();
- return 1;
+ return plot_bool_property_get(L, &sg_plot::clip_is_active);
}
int
plot_sync_mode_get (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- AGG_LOCK();
- lua_pushboolean (L, p->sync_mode());
- AGG_UNLOCK();
- return 1;
+ return plot_bool_property_get(L, &sg_plot::sync_mode);
}
int
plot_sync_mode_set (lua_State *L)
{
- sg_plot *p = object_check<sg_plot>(L, 1, GS_PLOT);
- bool request = (bool) lua_toboolean (L, 2);
- AGG_LOCK();
- p->sync_mode(request);
- AGG_UNLOCK();
+ plot_bool_property_set(L, &sg_plot::sync_mode, false);
return 0;
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月13日 01:19:45 +0000

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