diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-06-15 18:34:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-06-15 18:34:14 -0300 |
commit | d97af0de26cc4eabe5ff9d1b851a6a5110473d1a (patch) | |
tree | ccc2ec1ec4d917c3b75e447eedd5e59bc3e47205 | |
parent | 1917149fdd737752451da2c5f2dfbe1adde72c20 (diff) | |
download | lua-d97af0de26cc4eabe5ff9d1b851a6a5110473d1a.tar.gz lua-d97af0de26cc4eabe5ff9d1b851a6a5110473d1a.tar.bz2 lua-d97af0de26cc4eabe5ff9d1b851a6a5110473d1a.zip |
"lua_dobuffer" gets an extra argument, with the chunk name
-rw-r--r-- | ldo.c | 19 | ||||
-rw-r--r-- | lua.h | 4 | ||||
-rw-r--r-- | manual.tex | 23 |
3 files changed, 24 insertions, 22 deletions
@@ -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 | ||
395 | int lua_dostring (char *str) | 395 | int 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 | ||
414 | int lua_dobuffer (char *buff, int size) { | 409 | int 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 | ||
@@ -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 */ | |||
41 | void lua_error (char *s); | 41 | void lua_error (char *s); |
42 | int lua_dofile (char *filename); /* Out: returns */ | 42 | int lua_dofile (char *filename); /* Out: returns */ |
43 | int lua_dostring (char *string); /* Out: returns */ | 43 | int lua_dostring (char *string); /* Out: returns */ |
44 | int lua_dobuffer (char *buff, int size); | 44 | int lua_dobuffer (char *buff, int size, char *name); |
45 | /* Out: returns */ | 45 | /* Out: returns */ |
46 | int lua_callfunction (lua_Object f); | 46 | int lua_callfunction (lua_Object f); |
47 | /* In: parameters; Out: returns */ | 47 | /* In: parameters; Out: returns */ |
@@ -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} |
1576 | int lua_dofile (char *filename); | 1576 | int lua_dofile (char *filename); |
1577 | int lua_dostring (char *string); | 1577 | int lua_dostring (char *string); |
1578 | int lua_dobuffer (char *buff, int size); | 1578 | int lua_dobuffer (char *buff, int size, char *name); |
1579 | \end{verbatim} | 1579 | \end{verbatim} |
1580 | All these functions return an error code: | 1580 | All these functions return an error code: |
1581 | 0, in case of success; non zero, in case of errors. | 1581 | 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 | |||
1583 | it could not open the file. | 1583 | it could not open the file. |
1584 | The function \verb|lua_dofile|, if called with argument \verb|NULL|, | 1584 | The function \verb|lua_dofile|, if called with argument \verb|NULL|, |
1585 | executes the \verb|stdin| stream. | 1585 | executes the \verb|stdin| stream. |
1586 | Function \verb|lua_dofile| is also able to execute pre-compiled chunks. | 1586 | Functions \verb|lua_dofile| and \verb|lua_dobuffer| |
1587 | It automatically detects whether the file is text or binary, | 1587 | are both able to execute pre-compiled chunks. |
1588 | and loads it accordingly (see program \IndexVerb{luac}). | 1588 | They automatically detect whether the chunk is text or binary, |
1589 | Function \verb|lua_dostring| executes only source code, | 1589 | and load it accordingly (see program \IndexVerb{luac}). |
1590 | and function \verb|lua_dobuffer| executes only pre-compiled chunks. | 1590 | Function \verb|lua_dostring| executes only source code. |
1591 | |||
1592 | The third parameter to \verb|lua_dobuffer| (\verb|name|) | ||
1593 | is the ``name of the chunk'', | ||
1594 | used in error messages and debug information. | ||
1595 | In files this name is the file name, | ||
1596 | and \verb|lua_dostring| uses a small prefix | ||
1597 | of the string as the chunk name. | ||
1591 | 1598 | ||
1592 | These functions return, in structure lua2C, | 1599 | These functions return, in structure lua2C, |
1593 | any values eventually returned by the chunks. | 1600 | any values eventually returned by the chunks. |