aboutsummaryrefslogtreecommitdiff
path: root/lua.c
diff options
context:
space:
mode:
Diffstat (limited to 'lua.c')
-rw-r--r--lua.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/lua.c b/lua.c
index d8eca6a8..a7b80e5f 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.56 2001/01/10 16:58:11 roberto Exp roberto $ 2** $Id: lua.c,v 1.57 2001/01/22 18:01:38 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,17 +16,27 @@
16#include "lualib.h" 16#include "lualib.h"
17 17
18 18
19static lua_State *L = NULL; 19#ifdef _POSIX_SOURCE
20#include <unistd.h>
21#else
22static int isatty (int x) { return x==0; } /* assume stdin is a tty */
23#endif
24
20 25
21 26
22#ifndef PROMPT 27#ifndef PROMPT
23#define PROMPT "> " 28#define PROMPT "> "
24#endif 29#endif
25 30
26#ifdef _POSIX_SOURCE 31
27#include <unistd.h> 32#ifndef LUA_USERINIT
28#else 33#define LUA_USERINIT(L) (lua_baselibopen(L), lua_iolibopen(L), \
29static int isatty (int x) { return x==0; } /* assume stdin is a tty */ 34 lua_strlibopen(L), lua_mathlibopen(L), lua_dblibopen(L))
35#endif
36
37
38#ifndef LUA_USERFINI
39#define LUA_USERFINI
30#endif 40#endif
31 41
32 42
@@ -39,6 +49,9 @@ struct Options {
39}; 49};
40 50
41 51
52static lua_State *L = NULL;
53
54
42typedef void (*handler)(int); /* type for signal actions */ 55typedef void (*handler)(int); /* type for signal actions */
43 56
44static void laction (int i); 57static void laction (int i);
@@ -48,15 +61,6 @@ static lua_Hook old_linehook = NULL;
48static lua_Hook old_callhook = NULL; 61static lua_Hook old_callhook = NULL;
49 62
50 63
51static void userinit (void) {
52 lua_baselibopen(L);
53 lua_iolibopen(L);
54 lua_strlibopen(L);
55 lua_mathlibopen(L);
56 lua_dblibopen(L);
57 /* add your libraries here */
58}
59
60 64
61static handler lreset (void) { 65static handler lreset (void) {
62 return signal(SIGINT, laction); 66 return signal(SIGINT, laction);
@@ -312,7 +316,7 @@ int main (int argc, char *argv[]) {
312 opt.toclose = 0; 316 opt.toclose = 0;
313 getstacksize(argc, argv, &opt); /* handle option `-s' */ 317 getstacksize(argc, argv, &opt); /* handle option `-s' */
314 L = lua_open(NULL, opt.stacksize); /* create state */ 318 L = lua_open(NULL, opt.stacksize); /* create state */
315 userinit(); /* open libraries */ 319 LUA_USERINIT(L); /* open libraries */
316 register_getargs(argv); /* create `getargs' function */ 320 register_getargs(argv); /* create `getargs' function */
317 status = handle_argv(argv+1, &opt); 321 status = handle_argv(argv+1, &opt);
318 if (opt.toclose) 322 if (opt.toclose)