aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-19 15:47:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-06-19 15:47:06 -0300
commitdf0df08bc537d4f2c13446fee20f8a4335f9d9d2 (patch)
tree9ddf500c4019037c2a2b80f9d94709c28258f30a
parent9618aaf07d0d82ccbac91db22cb42451ec17d7ed (diff)
downloadlua-df0df08bc537d4f2c13446fee20f8a4335f9d9d2.tar.gz
lua-df0df08bc537d4f2c13446fee20f8a4335f9d9d2.tar.bz2
lua-df0df08bc537d4f2c13446fee20f8a4335f9d9d2.zip
"dostring" accepts chunk name.
-rw-r--r--lbuiltin.c11
-rw-r--r--ldo.c37
-rw-r--r--llex.c4
-rw-r--r--manual.tex11
4 files changed, 41 insertions, 22 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 35053865..c555ddf9 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.29 1998/06/05 22:17:44 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.30 1998/06/19 16:14:09 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -22,6 +22,7 @@
22#include "ltable.h" 22#include "ltable.h"
23#include "ltm.h" 23#include "ltm.h"
24#include "lua.h" 24#include "lua.h"
25#include "lundump.h"
25 26
26 27
27 28
@@ -114,9 +115,11 @@ static void foreach (void)
114 115
115static void internaldostring (void) 116static void internaldostring (void)
116{ 117{
117 if (lua_getparam(2) != LUA_NOOBJECT) 118 long l;
118 lua_error("invalid 2nd argument (probably obsolete code)"); 119 char *s = luaL_check_lstr(1, &l);
119 if (lua_dostring(luaL_check_string(1)) == 0) 120 if (*s == ID_CHUNK)
121 lua_error("`dostring' cannot run pre-compiled code");
122 if (lua_dobuffer(s, l, luaL_opt_string(2, NULL)) == 0)
120 if (luaA_passresults() == 0) 123 if (luaA_passresults() == 0)
121 lua_pushuserdata(NULL); /* at least one result to signal no errors */ 124 lua_pushuserdata(NULL); /* at least one result to signal no errors */
122} 125}
diff --git a/ldo.c b/ldo.c
index fe644c7b..116d6eb0 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.25 1998/05/31 22:22:00 roberto Exp roberto $ 2** $Id: ldo.c,v 1.26 1998/06/15 21:34:14 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,24 +392,35 @@ int lua_dofile (char *filename)
392#define SSIZE_PREF "20" 392#define SSIZE_PREF "20"
393 393
394 394
395int lua_dostring (char *str) { 395static void build_name (char *str, char *name) {
396 char name[SIZE_PREF+25]; 396 if (str == NULL || *str == ID_CHUNK)
397 char *temp; 397 strcpy(name, "(buffer)");
398 if (str == NULL || *str == ID_CHUNK) return 1; 398 else {
399 sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str); 399 char *temp;
400 temp = strchr(name, '\n'); 400 sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
401 if (temp) { /* end string after first line */ 401 temp = strchr(name, '\n');
402 *temp = '"'; 402 if (temp) { /* end string after first line */
403 *(temp+1) = 0; 403 *temp = '"';
404 *(temp+1) = 0;
405 }
404 } 406 }
405 return lua_dobuffer(str, strlen(str), name); 407}
408
409
410int lua_dostring (char *str) {
411 return lua_dobuffer(str, strlen(str), NULL);
406} 412}
407 413
408 414
409int lua_dobuffer (char *buff, int size, char *name) { 415int lua_dobuffer (char *buff, int size, char *name) {
410 int status; 416 char newname[SIZE_PREF+25];
411 ZIO z; 417 ZIO z;
412 luaZ_mopen(&z, buff, size, (name==NULL) ? "(buffer)" : name); 418 int status;
419 if (name==NULL) {
420 build_name(buff, newname);
421 name = newname;
422 }
423 luaZ_mopen(&z, buff, size, name);
413 status = do_main(&z, buff[0]==ID_CHUNK); 424 status = do_main(&z, buff[0]==ID_CHUNK);
414 return status; 425 return status;
415} 426}
diff --git a/llex.c b/llex.c
index 8bd60aaf..8ae01d08 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.20 1998/06/06 20:44:05 roberto Exp roberto $ 2** $Id: llex.c,v 1.21 1998/06/18 16:57:03 roberto Exp roberto $
3** Lexical Analizer 3** Lexical Analizer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -48,7 +48,7 @@ void luaX_init (void)
48void luaX_syntaxerror (LexState *ls, char *s, char *token) { 48void luaX_syntaxerror (LexState *ls, char *s, char *token) {
49 if (token[0] == 0) 49 if (token[0] == 0)
50 token = "<eof>"; 50 token = "<eof>";
51 luaL_verror("%.100s;\n last token read: `%.50s' at line %d in file %.50s", 51 luaL_verror("%.100s;\n last token read: `%.50s' at line %d in chunk `%.50s'",
52 s, token, ls->linenumber, zname(ls->lex_z)); 52 s, token, ls->linenumber, zname(ls->lex_z));
53} 53}
54 54
diff --git a/manual.tex b/manual.tex
index 7b64e2a3..f8c40ba2 100644
--- a/manual.tex
+++ b/manual.tex
@@ -1,4 +1,4 @@
1% $Id: manual.tex,v 1.14 1998/06/15 21:34:14 roberto Exp roberto $ 1% $Id: manual.tex,v 1.15 1998/06/18 17:36:27 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/15 21:34:14 $} 42%\date{\small \verb$Date: 1998/06/18 17:36:27 $}
43 43
44\maketitle 44\maketitle
45 45
@@ -1602,6 +1602,8 @@ Function \verb|lua_dostring| executes only source code.
1602The third parameter to \verb|lua_dobuffer| (\verb|name|) 1602The third parameter to \verb|lua_dobuffer| (\verb|name|)
1603is the ``name of the chunk'', 1603is the ``name of the chunk'',
1604used in error messages and debug information. 1604used in error messages and debug information.
1605If \verb|name| is \verb|NULL|,
1606Lua gives a default name to the chunk.
1605In files this name is the file name, 1607In files this name is the file name,
1606and \verb|lua_dostring| uses a small prefix 1608and \verb|lua_dostring| uses a small prefix
1607of the string as the chunk name. 1609of the string as the chunk name.
@@ -1949,12 +1951,15 @@ or a non \nil\ value if the chunk returns no values.
1949It issues an error when called with a non string argument. 1951It issues an error when called with a non string argument.
1950\verb|dofile| is equivalent to the API function \verb|lua_dofile|. 1952\verb|dofile| is equivalent to the API function \verb|lua_dofile|.
1951 1953
1952\subsubsection*{\ff \T{dostring (string)}}\Deffunc{dostring} 1954\subsubsection*{\ff \T{dostring (string [, chunkname])}}\Deffunc{dostring}
1953This function executes a given string as a Lua chunk. 1955This function executes a given string as a Lua chunk.
1954If there is any error executing the string, 1956If there is any error executing the string,
1955\verb|dostring| returns \nil. 1957\verb|dostring| returns \nil.
1956Otherwise, it returns the values returned by the chunk, 1958Otherwise, it returns the values returned by the chunk,
1957or a non \nil\ value if the chunk returns no values. 1959or a non \nil\ value if the chunk returns no values.
1960An optional second parameter (\verb|chunkname|)
1961is the ``name of the chunk'',
1962used in error messages and debug information.
1958\verb|dostring| is equivalent to the API function \verb|lua_dostring|. 1963\verb|dostring| is equivalent to the API function \verb|lua_dostring|.
1959 1964
1960\subsubsection*{\ff \T{newtag ()}}\Deffunc{newtag}\label{pdf-newtag} 1965\subsubsection*{\ff \T{newtag ()}}\Deffunc{newtag}\label{pdf-newtag}