Browse Source

"lua_dobuffer" gets an extra argument, with the chunk name

Roberto Ierusalimschy 27 years ago
parent
commit
d97af0de26
3 changed files with 24 additions and 22 deletions
  1. 7 12
      ldo.c
  2. 2 2
      lua.h
  3. 15 8
      manual.tex

+ 7 - 12
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 1.24 1998/01/29 15:59:35 roberto Exp roberto $
+** $Id: ldo.c,v 1.25 1998/05/31 22:22:00 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -392,30 +392,25 @@ int lua_dofile (char *filename)
 #define SSIZE_PREF "20"
 
 
-int lua_dostring (char *str)
-{
-  int status;
+int lua_dostring (char *str) {
   char name[SIZE_PREF+25];
   char *temp;
-  ZIO z;
-  if (str == NULL) return 1;
+  if (str == NULL || *str == ID_CHUNK) return 1;
   sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
   temp = strchr(name, '\n');
   if (temp) {  /* end string after first line */
    *temp = '"';
    *(temp+1) = 0;
   }
-  luaZ_sopen(&z, str, name);
-  status = do_main(&z, 0);
-  return status;
+  return lua_dobuffer(str, strlen(str), name);
 }
 
 
-int lua_dobuffer (char *buff, int size) {
+int lua_dobuffer (char *buff, int size, char *name) {
   int status;
   ZIO z;
-  luaZ_mopen(&z, buff, size, "(buffer)");
-  status = do_main(&z, 1);
+  luaZ_mopen(&z, buff, size, (name==NULL) ? "(buffer)" : name);
+  status = do_main(&z, buff[0]==ID_CHUNK);
   return status;
 }
 

+ 2 - 2
lua.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.h,v 1.20 1998/06/05 22:17:44 roberto Exp roberto $
+** $Id: lua.h,v 1.21 1998/06/06 21:05:52 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
@@ -41,7 +41,7 @@ void           lua_settag		(int tag); /* In: object */
 void           lua_error		(char *s);
 int            lua_dofile 		(char *filename); /* Out: returns */
 int            lua_dostring 		(char *string); /* Out: returns */
-int            lua_dobuffer		(char *buff, int size);
+int            lua_dobuffer		(char *buff, int size, char *name);
 					  /* Out: returns */
 int            lua_callfunction		(lua_Object f);
 					  /* In: parameters; Out: returns */

+ 15 - 8
manual.tex

@@ -1,4 +1,4 @@
-% $Id: manual.tex,v 1.12 1998/06/02 20:37:04 roberto Exp roberto $
+% $Id: manual.tex,v 1.13 1998/06/06 21:05:52 roberto Exp roberto $
 
 \documentclass[11pt]{article}
 \usepackage{fullpage,bnf}
@@ -39,7 +39,7 @@ Waldemar Celes
 \tecgraf\ --- Computer Science Department --- PUC-Rio
 }
 
-%\date{\small \verb$Date: 1998/06/02 20:37:04 $}
+%\date{\small \verb$Date: 1998/06/06 21:05:52 $}
 
 \maketitle
 
@@ -1575,7 +1575,7 @@ using the following functions:
 \begin{verbatim}
 int lua_dofile   (char *filename);
 int lua_dostring (char *string);
-int lua_dobuffer (char *buff, int size);
+int lua_dobuffer (char *buff, int size, char *name);
 \end{verbatim}
 All these functions return an error code:
 0, in case of success; non zero, in case of errors.
@@ -1583,11 +1583,18 @@ More specifically, \verb|lua_dofile| returns 2 if for any reason
 it could not open the file.
 The function \verb|lua_dofile|, if called with argument \verb|NULL|,
 executes the \verb|stdin| stream.
-Function \verb|lua_dofile| is also able to execute pre-compiled chunks.
-It automatically detects whether the file is text or binary,
-and loads it accordingly (see program \IndexVerb{luac}).
-Function \verb|lua_dostring| executes only source code,
-and function \verb|lua_dobuffer| executes only pre-compiled chunks.
+Functions \verb|lua_dofile| and \verb|lua_dobuffer|
+are both able to execute pre-compiled chunks.
+They automatically detect whether the chunk is text or binary,
+and load it accordingly (see program \IndexVerb{luac}).
+Function \verb|lua_dostring| executes only source code.
+
+The third parameter to \verb|lua_dobuffer| (\verb|name|)
+is the ``name of the chunk'',
+used in error messages and debug information.
+In files this name is the file name,
+and \verb|lua_dostring| uses a small prefix
+of the string as the chunk name.
 
 These functions return, in structure lua2C,
 any values eventually returned by the chunks.