diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-09-24 14:30:28 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-09-24 14:30:28 -0300 |
commit | 6d383202dca4535866a339f17202e40b2775d160 (patch) | |
tree | b0f1eb749339f1ba917493afbc99a31a72ad7b29 | |
parent | 7b8166d7b3949839bffcc15e167269e4a6d4660c (diff) | |
download | lua-6d383202dca4535866a339f17202e40b2775d160.tar.gz lua-6d383202dca4535866a339f17202e40b2775d160.tar.bz2 lua-6d383202dca4535866a339f17202e40b2775d160.zip |
"dofile" and "dostring" may return values.
-rw-r--r-- | inout.c | 23 | ||||
-rw-r--r-- | lua.c | 14 | ||||
-rw-r--r-- | opcode.c | 5 |
3 files changed, 27 insertions, 15 deletions
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.39 1996/09/09 14:11:11 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.40 1996/09/11 21:53:02 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <string.h> | 11 | #include <string.h> |
@@ -111,15 +111,25 @@ static void check_arg (int cond, char *func) | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | |||
115 | static int passresults (void) | ||
116 | { | ||
117 | int arg = 0; | ||
118 | lua_Object obj; | ||
119 | while ((obj = lua_getresult(++arg)) != LUA_NOOBJECT) | ||
120 | lua_pushobject(obj); | ||
121 | return arg-1; | ||
122 | } | ||
114 | 123 | ||
115 | /* | 124 | /* |
116 | ** Internal function: do a string | 125 | ** Internal function: do a string |
117 | */ | 126 | */ |
118 | void lua_internaldostring (void) | 127 | void lua_internaldostring (void) |
119 | { | 128 | { |
120 | lua_Object obj = lua_getparam (1); | 129 | lua_Object obj = lua_getparam (1); |
121 | if (lua_isstring(obj) && !lua_dostring(lua_getstring(obj))) | 130 | if (lua_isstring(obj) && lua_dostring(lua_getstring(obj)) == 0) |
122 | lua_pushnumber(1); | 131 | if (passresults() == 0) |
132 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ | ||
123 | } | 133 | } |
124 | 134 | ||
125 | /* | 135 | /* |
@@ -134,8 +144,9 @@ void lua_internaldofile (void) | |||
134 | else if (obj != LUA_NOOBJECT) | 144 | else if (obj != LUA_NOOBJECT) |
135 | lua_error("invalid argument to function `dofile'"); | 145 | lua_error("invalid argument to function `dofile'"); |
136 | /* else fname = NULL */ | 146 | /* else fname = NULL */ |
137 | if (!lua_dofile(fname)) | 147 | if (lua_dofile(fname) == 0) |
138 | lua_pushnumber(1); | 148 | if (passresults() == 0) |
149 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ | ||
139 | } | 150 | } |
140 | 151 | ||
141 | 152 | ||
@@ -3,7 +3,7 @@ | |||
3 | ** Linguagem para Usuarios de Aplicacao | 3 | ** Linguagem para Usuarios de Aplicacao |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_lua="$Id: lua.c,v 1.12 1996/07/05 20:55:43 roberto Exp roberto $"; | 6 | char *rcs_lua="$Id: lua.c,v 1.13 1996/07/06 20:20:35 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -21,11 +21,13 @@ char *rcs_lua="$Id: lua.c,v 1.12 1996/07/05 20:55:43 roberto Exp roberto $"; | |||
21 | 21 | ||
22 | static void manual_input (void) | 22 | static void manual_input (void) |
23 | { | 23 | { |
24 | if (isatty(0)) | 24 | if (isatty(0)) { |
25 | { | 25 | char buffer[250]; |
26 | char buffer[250]; | 26 | while (fgets(buffer, sizeof(buffer), stdin) != 0) { |
27 | while (fgets(buffer, sizeof(buffer), stdin) != 0) | 27 | lua_beginblock(); |
28 | lua_dostring(buffer); | 28 | lua_dostring(buffer); |
29 | lua_endblock(); | ||
30 | } | ||
29 | } | 31 | } |
30 | else | 32 | else |
31 | lua_dofile(NULL); /* executes stdin as a file */ | 33 | lua_dofile(NULL); /* executes stdin as a file */ |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.73 1996/09/02 21:57:51 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.74 1996/09/20 12:51:16 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -481,8 +481,7 @@ int luaI_dorun (TFunc *tf) | |||
481 | adjustC(1); /* one slot for the pseudo-function */ | 481 | adjustC(1); /* one slot for the pseudo-function */ |
482 | stack[CLS_current.base].tag = LUA_T_FUNCTION; | 482 | stack[CLS_current.base].tag = LUA_T_FUNCTION; |
483 | stack[CLS_current.base].value.tf = tf; | 483 | stack[CLS_current.base].value.tf = tf; |
484 | status = do_protectedrun(0); | 484 | status = do_protectedrun(MULT_RET); |
485 | adjustC(0); | ||
486 | return status; | 485 | return status; |
487 | } | 486 | } |
488 | 487 | ||