diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-06-19 15:47:06 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-06-19 15:47:06 -0300 |
commit | df0df08bc537d4f2c13446fee20f8a4335f9d9d2 (patch) | |
tree | 9ddf500c4019037c2a2b80f9d94709c28258f30a | |
parent | 9618aaf07d0d82ccbac91db22cb42451ec17d7ed (diff) | |
download | lua-df0df08bc537d4f2c13446fee20f8a4335f9d9d2.tar.gz lua-df0df08bc537d4f2c13446fee20f8a4335f9d9d2.tar.bz2 lua-df0df08bc537d4f2c13446fee20f8a4335f9d9d2.zip |
"dostring" accepts chunk name.
-rw-r--r-- | lbuiltin.c | 11 | ||||
-rw-r--r-- | ldo.c | 37 | ||||
-rw-r--r-- | llex.c | 4 | ||||
-rw-r--r-- | manual.tex | 11 |
4 files changed, 41 insertions, 22 deletions
@@ -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 | ||
115 | static void internaldostring (void) | 116 | static 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 | } |
@@ -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 | ||
395 | int lua_dostring (char *str) { | 395 | static 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 | |||
410 | int lua_dostring (char *str) { | ||
411 | return lua_dobuffer(str, strlen(str), NULL); | ||
406 | } | 412 | } |
407 | 413 | ||
408 | 414 | ||
409 | int lua_dobuffer (char *buff, int size, char *name) { | 415 | int 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 | } |
@@ -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) | |||
48 | void luaX_syntaxerror (LexState *ls, char *s, char *token) { | 48 | void 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 | ||
@@ -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. | |||
1602 | The third parameter to \verb|lua_dobuffer| (\verb|name|) | 1602 | The third parameter to \verb|lua_dobuffer| (\verb|name|) |
1603 | is the ``name of the chunk'', | 1603 | is the ``name of the chunk'', |
1604 | used in error messages and debug information. | 1604 | used in error messages and debug information. |
1605 | If \verb|name| is \verb|NULL|, | ||
1606 | Lua gives a default name to the chunk. | ||
1605 | In files this name is the file name, | 1607 | In files this name is the file name, |
1606 | and \verb|lua_dostring| uses a small prefix | 1608 | and \verb|lua_dostring| uses a small prefix |
1607 | of the string as the chunk name. | 1609 | of the string as the chunk name. |
@@ -1949,12 +1951,15 @@ or a non \nil\ value if the chunk returns no values. | |||
1949 | It issues an error when called with a non string argument. | 1951 | It 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} |
1953 | This function executes a given string as a Lua chunk. | 1955 | This function executes a given string as a Lua chunk. |
1954 | If there is any error executing the string, | 1956 | If there is any error executing the string, |
1955 | \verb|dostring| returns \nil. | 1957 | \verb|dostring| returns \nil. |
1956 | Otherwise, it returns the values returned by the chunk, | 1958 | Otherwise, it returns the values returned by the chunk, |
1957 | or a non \nil\ value if the chunk returns no values. | 1959 | or a non \nil\ value if the chunk returns no values. |
1960 | An optional second parameter (\verb|chunkname|) | ||
1961 | is the ``name of the chunk'', | ||
1962 | used 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} |