"dostring" accepts chunk name.
This commit is contained in:
11
lbuiltin.c
11
lbuiltin.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lbuiltin.c,v 1.29 1998/06/05 22:17:44 roberto Exp roberto $
|
** $Id: lbuiltin.c,v 1.30 1998/06/19 16:14:09 roberto Exp roberto $
|
||||||
** Built-in functions
|
** Built-in functions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "ltable.h"
|
#include "ltable.h"
|
||||||
#include "ltm.h"
|
#include "ltm.h"
|
||||||
#include "lua.h"
|
#include "lua.h"
|
||||||
|
#include "lundump.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -114,9 +115,11 @@ static void foreach (void)
|
|||||||
|
|
||||||
static void internaldostring (void)
|
static void internaldostring (void)
|
||||||
{
|
{
|
||||||
if (lua_getparam(2) != LUA_NOOBJECT)
|
long l;
|
||||||
lua_error("invalid 2nd argument (probably obsolete code)");
|
char *s = luaL_check_lstr(1, &l);
|
||||||
if (lua_dostring(luaL_check_string(1)) == 0)
|
if (*s == ID_CHUNK)
|
||||||
|
lua_error("`dostring' cannot run pre-compiled code");
|
||||||
|
if (lua_dobuffer(s, l, luaL_opt_string(2, NULL)) == 0)
|
||||||
if (luaA_passresults() == 0)
|
if (luaA_passresults() == 0)
|
||||||
lua_pushuserdata(NULL); /* at least one result to signal no errors */
|
lua_pushuserdata(NULL); /* at least one result to signal no errors */
|
||||||
}
|
}
|
||||||
|
|||||||
37
ldo.c
37
ldo.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldo.c,v 1.25 1998/05/31 22:22:00 roberto Exp roberto $
|
** $Id: ldo.c,v 1.26 1998/06/15 21:34:14 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,24 +392,35 @@ int lua_dofile (char *filename)
|
|||||||
#define SSIZE_PREF "20"
|
#define SSIZE_PREF "20"
|
||||||
|
|
||||||
|
|
||||||
int lua_dostring (char *str) {
|
static void build_name (char *str, char *name) {
|
||||||
char name[SIZE_PREF+25];
|
if (str == NULL || *str == ID_CHUNK)
|
||||||
char *temp;
|
strcpy(name, "(buffer)");
|
||||||
if (str == NULL || *str == ID_CHUNK) return 1;
|
else {
|
||||||
sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
|
char *temp;
|
||||||
temp = strchr(name, '\n');
|
sprintf(name, "(dostring) >> \"%." SSIZE_PREF "s\"", str);
|
||||||
if (temp) { /* end string after first line */
|
temp = strchr(name, '\n');
|
||||||
*temp = '"';
|
if (temp) { /* end string after first line */
|
||||||
*(temp+1) = 0;
|
*temp = '"';
|
||||||
|
*(temp+1) = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return lua_dobuffer(str, strlen(str), name);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int lua_dostring (char *str) {
|
||||||
|
return lua_dobuffer(str, strlen(str), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int lua_dobuffer (char *buff, int size, char *name) {
|
int lua_dobuffer (char *buff, int size, char *name) {
|
||||||
int status;
|
char newname[SIZE_PREF+25];
|
||||||
ZIO z;
|
ZIO z;
|
||||||
luaZ_mopen(&z, buff, size, (name==NULL) ? "(buffer)" : name);
|
int status;
|
||||||
|
if (name==NULL) {
|
||||||
|
build_name(buff, newname);
|
||||||
|
name = newname;
|
||||||
|
}
|
||||||
|
luaZ_mopen(&z, buff, size, name);
|
||||||
status = do_main(&z, buff[0]==ID_CHUNK);
|
status = do_main(&z, buff[0]==ID_CHUNK);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
4
llex.c
4
llex.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 1.20 1998/06/06 20:44:05 roberto Exp roberto $
|
** $Id: llex.c,v 1.21 1998/06/18 16:57:03 roberto Exp roberto $
|
||||||
** Lexical Analizer
|
** Lexical Analizer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -48,7 +48,7 @@ void luaX_init (void)
|
|||||||
void luaX_syntaxerror (LexState *ls, char *s, char *token) {
|
void luaX_syntaxerror (LexState *ls, char *s, char *token) {
|
||||||
if (token[0] == 0)
|
if (token[0] == 0)
|
||||||
token = "<eof>";
|
token = "<eof>";
|
||||||
luaL_verror("%.100s;\n last token read: `%.50s' at line %d in file %.50s",
|
luaL_verror("%.100s;\n last token read: `%.50s' at line %d in chunk `%.50s'",
|
||||||
s, token, ls->linenumber, zname(ls->lex_z));
|
s, token, ls->linenumber, zname(ls->lex_z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
manual.tex
11
manual.tex
@@ -1,4 +1,4 @@
|
|||||||
% $Id: manual.tex,v 1.14 1998/06/15 21:34:14 roberto Exp roberto $
|
% $Id: manual.tex,v 1.15 1998/06/18 17:36:27 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/15 21:34:14 $}
|
%\date{\small \verb$Date: 1998/06/18 17:36:27 $}
|
||||||
|
|
||||||
\maketitle
|
\maketitle
|
||||||
|
|
||||||
@@ -1602,6 +1602,8 @@ Function \verb|lua_dostring| executes only source code.
|
|||||||
The third parameter to \verb|lua_dobuffer| (\verb|name|)
|
The third parameter to \verb|lua_dobuffer| (\verb|name|)
|
||||||
is the ``name of the chunk'',
|
is the ``name of the chunk'',
|
||||||
used in error messages and debug information.
|
used in error messages and debug information.
|
||||||
|
If \verb|name| is \verb|NULL|,
|
||||||
|
Lua gives a default name to the chunk.
|
||||||
In files this name is the file name,
|
In files this name is the file name,
|
||||||
and \verb|lua_dostring| uses a small prefix
|
and \verb|lua_dostring| uses a small prefix
|
||||||
of the string as the chunk name.
|
of the string as the chunk name.
|
||||||
@@ -1949,12 +1951,15 @@ or a non \nil\ value if the chunk returns no values.
|
|||||||
It issues an error when called with a non string argument.
|
It issues an error when called with a non string argument.
|
||||||
\verb|dofile| is equivalent to the API function \verb|lua_dofile|.
|
\verb|dofile| is equivalent to the API function \verb|lua_dofile|.
|
||||||
|
|
||||||
\subsubsection*{\ff \T{dostring (string)}}\Deffunc{dostring}
|
\subsubsection*{\ff \T{dostring (string [, chunkname])}}\Deffunc{dostring}
|
||||||
This function executes a given string as a Lua chunk.
|
This function executes a given string as a Lua chunk.
|
||||||
If there is any error executing the string,
|
If there is any error executing the string,
|
||||||
\verb|dostring| returns \nil.
|
\verb|dostring| returns \nil.
|
||||||
Otherwise, it returns the values returned by the chunk,
|
Otherwise, it returns the values returned by the chunk,
|
||||||
or a non \nil\ value if the chunk returns no values.
|
or a non \nil\ value if the chunk returns no values.
|
||||||
|
An optional second parameter (\verb|chunkname|)
|
||||||
|
is the ``name of the chunk'',
|
||||||
|
used in error messages and debug information.
|
||||||
\verb|dostring| is equivalent to the API function \verb|lua_dostring|.
|
\verb|dostring| is equivalent to the API function \verb|lua_dostring|.
|
||||||
|
|
||||||
\subsubsection*{\ff \T{newtag ()}}\Deffunc{newtag}\label{pdf-newtag}
|
\subsubsection*{\ff \T{newtag ()}}\Deffunc{newtag}\label{pdf-newtag}
|
||||||
|
|||||||
Reference in New Issue
Block a user