"dofile" and "dostring" may return values.

This commit is contained in:
Roberto Ierusalimschy 1996-09-24 14:30:28 -03:00
parent 7b8166d7b3
commit 6d383202dc
3 changed files with 27 additions and 15 deletions

23
inout.c
View File

@ -5,7 +5,7 @@
** Also provides some predefined lua functions. ** Also provides some predefined lua functions.
*/ */
char *rcs_inout="$Id: inout.c,v 2.39 1996/09/09 14:11:11 roberto Exp roberto $"; char *rcs_inout="$Id: inout.c,v 2.40 1996/09/11 21:53:02 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -111,15 +111,25 @@ static void check_arg (int cond, char *func)
} }
} }
static int passresults (void)
{
int arg = 0;
lua_Object obj;
while ((obj = lua_getresult(++arg)) != LUA_NOOBJECT)
lua_pushobject(obj);
return arg-1;
}
/* /*
** Internal function: do a string ** Internal function: do a string
*/ */
void lua_internaldostring (void) void lua_internaldostring (void)
{ {
lua_Object obj = lua_getparam (1); lua_Object obj = lua_getparam (1);
if (lua_isstring(obj) && !lua_dostring(lua_getstring(obj))) if (lua_isstring(obj) && lua_dostring(lua_getstring(obj)) == 0)
lua_pushnumber(1); if (passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */
} }
/* /*
@ -134,8 +144,9 @@ void lua_internaldofile (void)
else if (obj != LUA_NOOBJECT) else if (obj != LUA_NOOBJECT)
lua_error("invalid argument to function `dofile'"); lua_error("invalid argument to function `dofile'");
/* else fname = NULL */ /* else fname = NULL */
if (!lua_dofile(fname)) if (lua_dofile(fname) == 0)
lua_pushnumber(1); if (passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */
} }

14
lua.c
View File

@ -3,7 +3,7 @@
** Linguagem para Usuarios de Aplicacao ** Linguagem para Usuarios de Aplicacao
*/ */
char *rcs_lua="$Id: lua.c,v 1.12 1996/07/05 20:55:43 roberto Exp roberto $"; char *rcs_lua="$Id: lua.c,v 1.13 1996/07/06 20:20:35 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <string.h> #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 $";
static void manual_input (void) static void manual_input (void)
{ {
if (isatty(0)) if (isatty(0)) {
{ char buffer[250];
char buffer[250]; while (fgets(buffer, sizeof(buffer), stdin) != 0) {
while (fgets(buffer, sizeof(buffer), stdin) != 0) lua_beginblock();
lua_dostring(buffer); lua_dostring(buffer);
lua_endblock();
}
} }
else else
lua_dofile(NULL); /* executes stdin as a file */ lua_dofile(NULL); /* executes stdin as a file */

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_opcode="$Id: opcode.c,v 3.73 1996/09/02 21:57:51 roberto Exp roberto $"; char *rcs_opcode="$Id: opcode.c,v 3.74 1996/09/20 12:51:16 roberto Exp roberto $";
#include <setjmp.h> #include <setjmp.h>
#include <stdio.h> #include <stdio.h>
@ -481,8 +481,7 @@ int luaI_dorun (TFunc *tf)
adjustC(1); /* one slot for the pseudo-function */ adjustC(1); /* one slot for the pseudo-function */
stack[CLS_current.base].tag = LUA_T_FUNCTION; stack[CLS_current.base].tag = LUA_T_FUNCTION;
stack[CLS_current.base].value.tf = tf; stack[CLS_current.base].value.tf = tf;
status = do_protectedrun(0); status = do_protectedrun(MULT_RET);
adjustC(0);
return status; return status;
} }