gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/gsl-shell.c
diff options
context:
space:
mode:
authorfr4nko <francesco.bbt@gmail.com>2010年06月29日 11:48:05 +0200
committerfr4nko <francesco.bbt@gmail.com>2010年06月29日 11:48:05 +0200
commit1beceb467757384bd5695f5e7ed9acfba590bd4a (patch)
tree009f1a0df1484ebf721a93a6e3f2b1d135e4f4ba /gsl-shell.c
parentb5f50727239483643508795750262bc3ab6723ca (diff)
downloadgsl-shell-1beceb467757384bd5695f5e7ed9acfba590bd4a.tar.gz
added new c++ version of agg
Now the agg graphical modules have a different implementations. Now lua code is written directly in C++. We have also changed the memory reference system: now lua is responsable of freeing everything.
Diffstat (limited to 'gsl-shell.c')
-rw-r--r--gsl-shell.c 64
1 files changed, 61 insertions, 3 deletions
diff --git a/gsl-shell.c b/gsl-shell.c
index c03cacb5..efbaa18b 100644
--- a/gsl-shell.c
+++ b/gsl-shell.c
@@ -50,6 +50,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <pthread.h>
#define lua_c
@@ -58,11 +59,18 @@
#include <lauxlib.h>
#include <lualib.h>
#include "llimits.h"
+#include "gsl-shell.h"
#include "lua-gsl.h"
#include "lua-utils.h"
#define report error_report
+struct window_unref_cell {
+ int id;
+ struct window_unref_cell *next;
+};
+
+static struct window_unref_cell *window_unref_list = NULL;
static lua_State *globalL = NULL;
static const char *progname = LUA_PROGNAME;
@@ -84,6 +92,8 @@ static const luaL_Reg gshlibs[] = {
{NULL, NULL}
};
+pthread_mutex_t gsl_shell_mutex[1];
+
static void lstop (lua_State *L, lua_Debug *ar) {
(void)ar; /* unused arg. */
lua_sethook(L, NULL, 0, 0);
@@ -113,7 +123,6 @@ static void print_usage (void) {
fflush(stderr);
}
-
void
gsl_shell_openlibs (lua_State *L)
{
@@ -266,8 +275,12 @@ static int pushline (lua_State *L, int firstline) {
char *b = buffer;
size_t l;
const char *prmt = get_prompt(L, firstline);
+
if (lua_readline(L, b, prmt) == 0)
- return 0; /* no input */
+ {
+ return 0; /* no input */
+ }
+
l = strlen(b);
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
b[l-1] = '0円'; /* remove it */
@@ -310,9 +323,40 @@ static int loadline (lua_State *L) {
static void dotty (lua_State *L) {
- int status;
const char *oldprogname = progname;
progname = NULL;
+ for (;;)
+ {
+ struct window_unref_cell *wu;
+ int status = loadline(L);
+ if (status == -1)
+ break;
+ if (status == 0)
+ status = docall(L, 0, 0);
+ report(L, status);
+ if (status == 0 && lua_gettop(L) > 0)
+ { /* any result to print? */
+ lua_getglobal(L, "print");
+ lua_insert(L, 1);
+ if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
+ {
+ const char *fstr = "error calling " LUA_QL("print") " (%s)";
+ const char *emsg = lua_pushfstring(L, fstr, lua_tostring(L, -1));
+ l_message(progname, emsg);
+ }
+ }
+ GSL_SHELL_LOCK();
+ for (wu = window_unref_list; wu != NULL; /* */)
+ {
+ struct window_unref_cell *nxt = wu->next;
+ mlua_window_unref (L, wu->id);
+ free (wu);
+ wu = nxt;
+ }
+ window_unref_list = NULL;
+ GSL_SHELL_UNLOCK();
+ }
+#if 0
while ((status = loadline(L)) != -1) {
if (status == 0) status = docall(L, 0, 0);
report(L, status);
@@ -325,6 +369,7 @@ static void dotty (lua_State *L) {
lua_tostring(L, -1)));
}
}
+#endif
lua_settop(L, 0); /* clear stack */
fputs("\n", stdout);
fflush(stdout);
@@ -481,6 +526,8 @@ int main (int argc, char **argv) {
int status;
struct Smain s;
+ pthread_mutex_init (gsl_shell_mutex, NULL);
+
lua_State *L = lua_open(); /* create state */
if (L == NULL) {
l_message(argv[0], "cannot create state: not enough memory");
@@ -500,3 +547,14 @@ int main (int argc, char **argv) {
lua_close(L);
return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
+
+void
+gsl_shell_unref_plot (int id)
+{
+ struct window_unref_cell *cell = malloc(sizeof(struct window_unref_cell));
+
+ cell->id = id;
+ cell->next = window_unref_list;
+
+ window_unref_list = cell;
+}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月17日 01:14:15 +0000

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