Browse Source

"dofile" and "dostring" may return values.

Roberto Ierusalimschy 29 years ago
parent
commit
6d383202dc
3 changed files with 27 additions and 15 deletions
  1. 17 6
      inout.c
  2. 8 6
      lua.c
  3. 2 3
      opcode.c

+ 17 - 6
inout.c

@@ -5,7 +5,7 @@
 ** 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 <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
 */
 void lua_internaldostring (void)
 {
- lua_Object obj = lua_getparam (1);
- if (lua_isstring(obj) && !lua_dostring(lua_getstring(obj)))
-  lua_pushnumber(1);
+  lua_Object obj = lua_getparam (1);
+  if (lua_isstring(obj) && lua_dostring(lua_getstring(obj)) == 0)
+    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)
    lua_error("invalid argument to function `dofile'");
  /* else fname = NULL */
- if (!lua_dofile(fname))
-  lua_pushnumber(1);
+ if (lua_dofile(fname) == 0)
+    if (passresults() == 0)
+      lua_pushuserdata(NULL);  /* at least one result to signal no errors */
 }
  
 

+ 8 - 6
lua.c

@@ -3,7 +3,7 @@
 ** 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 <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)
 {
-  if (isatty(0))
-  {
-   char buffer[250];
-   while (fgets(buffer, sizeof(buffer), stdin) != 0)
-     lua_dostring(buffer);
+  if (isatty(0)) {
+    char buffer[250];
+    while (fgets(buffer, sizeof(buffer), stdin) != 0) {
+      lua_beginblock();
+      lua_dostring(buffer);
+      lua_endblock();
+    }
   }
   else
     lua_dofile(NULL);  /* executes stdin as a file */

+ 2 - 3
opcode.c

@@ -3,7 +3,7 @@
 ** 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 <stdio.h>
@@ -481,8 +481,7 @@ int luaI_dorun (TFunc *tf)
   adjustC(1);  /* one slot for the pseudo-function */
   stack[CLS_current.base].tag = LUA_T_FUNCTION;
   stack[CLS_current.base].value.tf = tf;
-  status = do_protectedrun(0);
-  adjustC(0);
+  status = do_protectedrun(MULT_RET);
   return status;
 }