Browse Source

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

v5-2
Roberto Ierusalimschy 27 years ago
parent
commit
d97af0de26
  1. 19
      ldo.c
  2. 4
      lua.h
  3. 23
      manual.tex

19
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 ** Stack and Call structure of Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -392,30 +392,25 @@ int lua_dofile (char *filename)
#define SSIZE_PREF "20" #define SSIZE_PREF "20"
int lua_dostring (char *str) int lua_dostring (char *str) {
{
int status;
char name[SIZE_PREF+25]; char name[SIZE_PREF+25];
char *temp; char *temp;
ZIO z; if (str == NULL || *str == ID_CHUNK) return 1;
if (str == NULL) return 1;
sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str); sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
temp = strchr(name, '\n'); temp = strchr(name, '\n');
if (temp) { /* end string after first line */ if (temp) { /* end string after first line */
*temp = '"'; *temp = '"';
*(temp+1) = 0; *(temp+1) = 0;
} }
luaZ_sopen(&z, str, name); return lua_dobuffer(str, strlen(str), name);
status = do_main(&z, 0);
return status;
} }
int lua_dobuffer (char *buff, int size) { int lua_dobuffer (char *buff, int size, char *name) {
int status; int status;
ZIO z; ZIO z;
luaZ_mopen(&z, buff, size, "(buffer)"); luaZ_mopen(&z, buff, size, (name==NULL) ? "(buffer)" : name);
status = do_main(&z, 1); status = do_main(&z, buff[0]==ID_CHUNK);
return status; return status;
} }

4
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 ** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br ** e-mail: lua@tecgraf.puc-rio.br
@ -41,7 +41,7 @@ void lua_settag (int tag); /* In: object */
void lua_error (char *s); void lua_error (char *s);
int lua_dofile (char *filename); /* Out: returns */ int lua_dofile (char *filename); /* Out: returns */
int lua_dostring (char *string); /* 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 */ /* Out: returns */
int lua_callfunction (lua_Object f); int lua_callfunction (lua_Object f);
/* In: parameters; Out: returns */ /* In: parameters; Out: returns */

23
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} \documentclass[11pt]{article}
\usepackage{fullpage,bnf} \usepackage{fullpage,bnf}
@ -39,7 +39,7 @@ Waldemar Celes
\tecgraf\ --- Computer Science Department --- PUC-Rio \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 \maketitle
@ -1575,7 +1575,7 @@ using the following functions:
\begin{verbatim} \begin{verbatim}
int lua_dofile (char *filename); int lua_dofile (char *filename);
int lua_dostring (char *string); int lua_dostring (char *string);
int lua_dobuffer (char *buff, int size); int lua_dobuffer (char *buff, int size, char *name);
\end{verbatim} \end{verbatim}
All these functions return an error code: All these functions return an error code:
0, in case of success; non zero, in case of errors. 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. it could not open the file.
The function \verb|lua_dofile|, if called with argument \verb|NULL|, The function \verb|lua_dofile|, if called with argument \verb|NULL|,
executes the \verb|stdin| stream. executes the \verb|stdin| stream.
Function \verb|lua_dofile| is also able to execute pre-compiled chunks. Functions \verb|lua_dofile| and \verb|lua_dobuffer|
It automatically detects whether the file is text or binary, are both able to execute pre-compiled chunks.
and loads it accordingly (see program \IndexVerb{luac}). They automatically detect whether the chunk is text or binary,
Function \verb|lua_dostring| executes only source code, and load it accordingly (see program \IndexVerb{luac}).
and function \verb|lua_dobuffer| executes only pre-compiled chunks. 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, These functions return, in structure lua2C,
any values eventually returned by the chunks. any values eventually returned by the chunks.

Loading…
Cancel
Save