aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-15 18:34:14 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-15 18:34:14 -0300
commitd97af0de26cc4eabe5ff9d1b851a6a5110473d1a (patch)
treeccc2ec1ec4d917c3b75e447eedd5e59bc3e47205
parent1917149fdd737752451da2c5f2dfbe1adde72c20 (diff)
downloadlua-d97af0de26cc4eabe5ff9d1b851a6a5110473d1a.tar.gz
lua-d97af0de26cc4eabe5ff9d1b851a6a5110473d1a.tar.bz2
lua-d97af0de26cc4eabe5ff9d1b851a6a5110473d1a.zip
"lua_dobuffer" gets an extra argument, with the chunk name
-rw-r--r--ldo.c19
-rw-r--r--lua.h4
-rw-r--r--manual.tex23
3 files changed, 24 insertions, 22 deletions
diff --git a/ldo.c b/ldo.c
index 03126473..fe644c7b 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.24 1998/01/29 15:59:35 roberto Exp roberto $ 2** $Id: ldo.c,v 1.25 1998/05/31 22:22:00 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -392,30 +392,25 @@ int lua_dofile (char *filename)
392#define SSIZE_PREF "20" 392#define SSIZE_PREF "20"
393 393
394 394
395int lua_dostring (char *str) 395int lua_dostring (char *str) {
396{
397 int status;
398 char name[SIZE_PREF+25]; 396 char name[SIZE_PREF+25];
399 char *temp; 397 char *temp;
400 ZIO z; 398 if (str == NULL || *str == ID_CHUNK) return 1;
401 if (str == NULL) return 1;
402 sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str); 399 sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
403 temp = strchr(name, '\n'); 400 temp = strchr(name, '\n');
404 if (temp) { /* end string after first line */ 401 if (temp) { /* end string after first line */
405 *temp = '"'; 402 *temp = '"';
406 *(temp+1) = 0; 403 *(temp+1) = 0;
407 } 404 }
408 luaZ_sopen(&z, str, name); 405 return lua_dobuffer(str, strlen(str), name);
409 status = do_main(&z, 0);
410 return status;
411} 406}
412 407
413 408
414int lua_dobuffer (char *buff, int size) { 409int lua_dobuffer (char *buff, int size, char *name) {
415 int status; 410 int status;
416 ZIO z; 411 ZIO z;
417 luaZ_mopen(&z, buff, size, "(buffer)"); 412 luaZ_mopen(&z, buff, size, (name==NULL) ? "(buffer)" : name);
418 status = do_main(&z, 1); 413 status = do_main(&z, buff[0]==ID_CHUNK);
419 return status; 414 return status;
420} 415}
421 416
diff --git a/lua.h b/lua.h
index 66d0f1dd..c30bd4cf 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.20 1998/06/05 22:17:44 roberto Exp roberto $ 2** $Id: lua.h,v 1.21 1998/06/06 21:05:52 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: lua@tecgraf.puc-rio.br 5** e-mail: lua@tecgraf.puc-rio.br
@@ -41,7 +41,7 @@ void lua_settag (int tag); /* In: object */
41void lua_error (char *s); 41void lua_error (char *s);
42int lua_dofile (char *filename); /* Out: returns */ 42int lua_dofile (char *filename); /* Out: returns */
43int lua_dostring (char *string); /* Out: returns */ 43int lua_dostring (char *string); /* Out: returns */
44int lua_dobuffer (char *buff, int size); 44int lua_dobuffer (char *buff, int size, char *name);
45 /* Out: returns */ 45 /* Out: returns */
46int lua_callfunction (lua_Object f); 46int lua_callfunction (lua_Object f);
47 /* In: parameters; Out: returns */ 47 /* In: parameters; Out: returns */
diff --git a/manual.tex b/manual.tex
index 6725b893..5bc36b80 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.12 1998/06/02 20:37:04 roberto Exp roberto $ 1% $Id: manual.tex,v 1.13 1998/06/06 21:05:52 roberto Exp roberto $
2 2
3\documentclass[11pt]{article} 3\documentclass[11pt]{article}
4\usepackage{fullpage,bnf} 4\usepackage{fullpage,bnf}
@@ -39,7 +39,7 @@ Waldemar Celes
39\tecgraf\ --- Computer Science Department --- PUC-Rio 39\tecgraf\ --- Computer Science Department --- PUC-Rio
40} 40}
41 41
42%\date{\small \verb$Date: 1998/06/02 20:37:04 $} 42%\date{\small \verb$Date: 1998/06/06 21:05:52 $}
43 43
44\maketitle 44\maketitle
45 45
@@ -1575,7 +1575,7 @@ using the following functions:
1575\begin{verbatim} 1575\begin{verbatim}
1576int lua_dofile (char *filename); 1576int lua_dofile (char *filename);
1577int lua_dostring (char *string); 1577int lua_dostring (char *string);
1578int lua_dobuffer (char *buff, int size); 1578int lua_dobuffer (char *buff, int size, char *name);
1579\end{verbatim} 1579\end{verbatim}
1580All these functions return an error code: 1580All these functions return an error code:
15810, in case of success; non zero, in case of errors. 15810, 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
1583it could not open the file. 1583it could not open the file.
1584The function \verb|lua_dofile|, if called with argument \verb|NULL|, 1584The function \verb|lua_dofile|, if called with argument \verb|NULL|,
1585executes the \verb|stdin| stream. 1585executes the \verb|stdin| stream.
1586Function \verb|lua_dofile| is also able to execute pre-compiled chunks. 1586Functions \verb|lua_dofile| and \verb|lua_dobuffer|
1587It automatically detects whether the file is text or binary, 1587are both able to execute pre-compiled chunks.
1588and loads it accordingly (see program \IndexVerb{luac}). 1588They automatically detect whether the chunk is text or binary,
1589Function \verb|lua_dostring| executes only source code, 1589and load it accordingly (see program \IndexVerb{luac}).
1590and function \verb|lua_dobuffer| executes only pre-compiled chunks. 1590Function \verb|lua_dostring| executes only source code.
1591
1592The third parameter to \verb|lua_dobuffer| (\verb|name|)
1593is the ``name of the chunk'',
1594used in error messages and debug information.
1595In files this name is the file name,
1596and \verb|lua_dostring| uses a small prefix
1597of the string as the chunk name.
1591 1598
1592These functions return, in structure lua2C, 1599These functions return, in structure lua2C,
1593any values eventually returned by the chunks. 1600any values eventually returned by the chunks.