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/canvas-window.cpp 33
-rw-r--r--gsl-shell.c 86
-rw-r--r--gsl-shell.h 2
-rw-r--r--object-index.c 24
-rw-r--r--object-index.h 19
5 files changed, 50 insertions, 114 deletions
diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp
index e5b87376..911d504b 100644
--- a/agg-plot/canvas-window.cpp
+++ b/agg-plot/canvas-window.cpp
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <memory>
+
extern "C" {
#include "lua.h"
#include "lauxlib.h"
@@ -43,6 +45,13 @@ static void * canvas_thread_function (void *_win);
__END_DECLS
+struct canvas_thread_info {
+ lua_State *L;
+ canvas_window *win;
+
+ canvas_thread_info (lua_State *L, canvas_window *win) : L(L), win(win) {};
+};
+
void
canvas_window::on_resize(int sx, int sy)
{
@@ -67,7 +76,7 @@ canvas_window::start_new_thread (lua_State *L)
if (status != not_ready && status != closed)
return;
- this->id = object_index_add (L, OBJECT_WINDOW, -1);
+ this->id = object_index_add (L, -1);
pthread_attr_t attr[1];
pthread_t win_thread[1];
@@ -79,11 +88,13 @@ canvas_window::start_new_thread (lua_State *L)
this->status = canvas_window::starting;
- if (pthread_create(win_thread, attr, canvas_thread_function, (void*) this))
+ canvas_thread_info *inf = new canvas_thread_info(L, this);
+ if (pthread_create(win_thread, attr, canvas_thread_function, (void*) inf))
{
- object_index_remove (L, OBJECT_WINDOW, this->id);
-
+ delete inf;
+ object_index_remove (L, this->id);
pthread_attr_destroy (attr);
+
this->status = canvas_window::error;
luaL_error(L, "error creating thread");
@@ -93,11 +104,11 @@ canvas_window::start_new_thread (lua_State *L)
}
void *
-canvas_thread_function (void *_win)
+canvas_thread_function (void *_inf)
{
+ std::auto_ptr<canvas_thread_info> inf((canvas_thread_info *) _inf);
platform_support_ext::prepare();
-
- canvas_window *win = (canvas_window *) _win;
+ canvas_window *win = inf->win;
win->caption("GSL shell plot");
if (win->init(480, 480, agg::window_resize))
@@ -110,12 +121,12 @@ canvas_thread_function (void *_win)
{
win->status = canvas_window::error;
}
-
- GSL_SHELL_LOCK();
- gsl_shell_unref_plot (win->id);
- GSL_SHELL_UNLOCK();
win->unlock();
+ GSL_SHELL_LOCK();
+ object_index_remove (inf->L, win->id);
+ GSL_SHELL_UNLOCK();
+
return NULL;
}
diff --git a/gsl-shell.c b/gsl-shell.c
index 84fb16d8..928c8020 100644
--- a/gsl-shell.c
+++ b/gsl-shell.c
@@ -64,23 +64,8 @@
#include "lua-gsl.h"
#include "lua-utils.h"
-#ifdef AGG_PLOT_ENABLED
-#include "object-index.h"
-#include "window.h"
-#endif
-
#define report error_report
-struct window_unref_cell {
- int id;
- struct window_unref_cell *next;
-};
-
-#define UNREF_FIXED_SIZE 8
-static int unref_fixed_list[UNREF_FIXED_SIZE];
-static size_t unref_fixed_count = 0;
-
-static struct window_unref_cell *window_unref_list = NULL;
static lua_State *globalL = NULL;
static const char *progname = LUA_PROGNAME;
@@ -285,8 +270,13 @@ static int pushline (lua_State *L, int firstline) {
char *b = buffer;
size_t l;
const char *prmt = get_prompt(L, firstline);
+ int ok;
- if (lua_readline(L, b, prmt) == 0)
+ GSL_SHELL_UNLOCK();
+ ok = lua_readline(L, b, prmt);
+ GSL_SHELL_LOCK();
+
+ if (ok == 0)
{
return 0; /* no input */
}
@@ -335,35 +325,12 @@ static int loadline (lua_State *L) {
return status;
}
-static void do_windows_unref (lua_State *L)
-{
- struct window_unref_cell *wu;
- size_t j;
-
- GSL_SHELL_LOCK();
-
- for (j = 0; j < unref_fixed_count; j++)
- {
- object_index_remove (L, OBJECT_WINDOW, unref_fixed_list[j]);
- }
-
- unref_fixed_count = 0;
-
- for (wu = window_unref_list; wu != NULL; /* */)
- {
- struct window_unref_cell *nxt = wu->next;
- object_index_remove (L, OBJECT_WINDOW, wu->id);
- free (wu);
- wu = nxt;
- }
- window_unref_list = NULL;
-
- GSL_SHELL_UNLOCK();
-}
-
static void dotty (lua_State *L) {
const char *oldprogname = progname;
progname = NULL;
+
+ GSL_SHELL_LOCK();
+
for (;;)
{
int status = loadline(L);
@@ -384,24 +351,12 @@ static void dotty (lua_State *L) {
l_message(progname, emsg);
}
}
-
-#ifdef AGG_PLOT_ENABLED
- do_windows_unref (L);
-#endif
}
-#ifdef AGG_PLOT_ENABLED
- object_index_apply_all (L, OBJECT_WINDOW, window_close);
-
- do
- {
- do_windows_unref (L);
- }
- while (object_index_count (L, OBJECT_WINDOW) > 0);
-#endif
-
lua_settop(L, 0); /* clear stack */
+ GSL_SHELL_UNLOCK();
+
fputs("\n", stdout);
fflush(stdout);
progname = oldprogname;
@@ -589,22 +544,3 @@ int main (int argc, char **argv) {
return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
-
-void
-gsl_shell_unref_plot (int id)
-{
- if (unref_fixed_count < UNREF_FIXED_SIZE)
- {
- unref_fixed_list[unref_fixed_count] = id;
- unref_fixed_count ++;
- }
- else
- {
- struct window_unref_cell *cell = malloc(sizeof(struct window_unref_cell));
-
- cell->id = id;
- cell->next = window_unref_list;
-
- window_unref_list = cell;
- }
-}
diff --git a/gsl-shell.h b/gsl-shell.h
index 6ab23596..c2c09e97 100644
--- a/gsl-shell.h
+++ b/gsl-shell.h
@@ -6,8 +6,6 @@
__BEGIN_DECLS
-extern void gsl_shell_unref_plot (int id);
-
extern pthread_mutex_t gsl_shell_mutex[1];
__END_DECLS
diff --git a/object-index.c b/object-index.c
index fab7830e..4074511c 100644
--- a/object-index.c
+++ b/object-index.c
@@ -4,24 +4,24 @@
#include "object-index.h"
-static const char *table_name[] = {"GSL.reg.wins"};
+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[OBJECT_WINDOW]);
+ lua_setfield (L, LUA_REGISTRYINDEX, table_name);
}
int
-object_index_add(lua_State *L, int obj_class, int index)
+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[obj_class]);
+ lua_getfield (L, LUA_REGISTRYINDEX, table_name);
n = lua_objlen (L, -1);
@@ -33,26 +33,26 @@ object_index_add(lua_State *L, int obj_class, int index)
}
void
-object_index_get (lua_State *L, int obj_class, int id)
+object_index_get (lua_State *L, int id)
{
- lua_getfield (L, LUA_REGISTRYINDEX, table_name[obj_class]);
+ lua_getfield (L, LUA_REGISTRYINDEX, table_name);
lua_rawgeti (L, -1, id);
lua_remove (L, -2);
}
void
-object_index_remove (lua_State *L, int obj_class, int id)
+object_index_remove (lua_State *L, int id)
{
- lua_getfield (L, LUA_REGISTRYINDEX, table_name[obj_class]);
+ 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, int obj_class, lua_CFunction f)
+object_index_apply_all (lua_State *L, lua_CFunction f)
{
- lua_getfield (L, LUA_REGISTRYINDEX, table_name[obj_class]);
+ lua_getfield (L, LUA_REGISTRYINDEX, table_name);
lua_pushnil (L); /* first key */
while (lua_next(L, -2) != 0)
@@ -66,11 +66,11 @@ object_index_apply_all (lua_State *L, int obj_class, lua_CFunction f)
}
int
-object_index_count (lua_State *L, int obj_class)
+object_index_count (lua_State *L)
{
int count = 0;
- lua_getfield (L, LUA_REGISTRYINDEX, table_name[obj_class]);
+ lua_getfield (L, LUA_REGISTRYINDEX, table_name);
lua_pushnil (L); /* first key */
while (lua_next(L, -2) != 0)
diff --git a/object-index.h b/object-index.h
index dd19c3f6..a2bc0a73 100644
--- a/object-index.h
+++ b/object-index.h
@@ -7,21 +7,12 @@ __BEGIN_DECLS
#include "lua.h"
-/* We have currently just one class of objects that have a unique ID, windows.
- At some moments during development this machinary was also used for plots.
- Because we have just one object type that get an id the code could be
- potentially simplified. */
-enum object_class_e {
- OBJECT_WINDOW = 0,
- /* OBJECT_PLOT, */
-};
-
extern void object_index_prepare (lua_State *L);
-extern int object_index_add (lua_State *L, int obj_class, int index);
-extern void object_index_get (lua_State *L, int obj_class, int id);
-extern void object_index_remove (lua_State *L, int obj_class, int id);
-extern void object_index_apply_all (lua_State *L, int obj_class, lua_CFunction f);
-extern int object_index_count (lua_State *L, int obj_class);
+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
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月28日 03:08:52 +0000

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