diff options
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | doc/contents.html | 4 | ||||
-rw-r--r-- | doc/manual.html | 172 | ||||
-rw-r--r-- | src/ldo.c | 27 | ||||
-rw-r--r-- | src/liolib.c | 4 | ||||
-rw-r--r-- | src/loadlib.c | 52 | ||||
-rw-r--r-- | src/lstrlib.c | 26 | ||||
-rw-r--r-- | src/luaconf.h | 8 |
8 files changed, 139 insertions, 156 deletions
@@ -1,5 +1,5 @@ -This is Lua 5.2 (beta), released on 27 Jun 2011. +This is Lua 5.2 (beta), released on 28 Jun 2011. For installation instructions, license details, and further information about Lua, see doc/readme.html. diff --git a/doc/contents.html b/doc/contents.html index 13b33b08..788bf6c8 100644 --- a/doc/contents.html +++ b/doc/contents.html @@ -288,10 +288,10 @@ Freely available under the terms of the <A HREF="manual.html#pdf-package.config">package.config</A><BR> <A HREF="manual.html#pdf-package.cpath">package.cpath</A><BR> <A HREF="manual.html#pdf-package.loaded">package.loaded</A><BR> -<A HREF="manual.html#pdf-package.loaders">package.loaders</A><BR> <A HREF="manual.html#pdf-package.loadlib">package.loadlib</A><BR> <A HREF="manual.html#pdf-package.path">package.path</A><BR> <A HREF="manual.html#pdf-package.preload">package.preload</A><BR> +<A HREF="manual.html#pdf-package.searchers">package.searchers</A><BR> <A HREF="manual.html#pdf-package.searchpath">package.searchpath</A><BR> <P> @@ -522,7 +522,7 @@ Freely available under the terms of the <HR> <SMALL CLASS="footer"> Last update: -Mon Jun 20 08:55:58 BRT 2011 +Tue Jun 28 14:53:13 BRT 2011 </SMALL> <!-- Last change: revised for Lua 5.2.0 (beta) diff --git a/doc/manual.html b/doc/manual.html index 02fe012f..25322089 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -38,7 +38,7 @@ Freely available under the terms of the <!-- ====================================================================== --> <p> -<!-- $Id: manual.of,v 1.80 2011/06/27 18:26:28 roberto Exp $ --> +<!-- $Id: manual.of,v 1.82 2011/06/28 17:17:36 roberto Exp $ --> @@ -880,7 +880,7 @@ the execution of the regular code. <p> Because the object being collected must still be used by the finalizer -and even <em>resurrected</em>resurrection +and even <em>resurrected</em> (e.g., stored by the finalizer in a global variable), the object memory is freed only when it becomes completely inaccessible (that is, in the next garbage-collection cycle unless it was resurrected). @@ -7245,11 +7245,11 @@ Otherwise, it tries to find a <em>loader</em> for the module. <p> To find a loader, -<code>require</code> is guided by the <a href="#pdf-package.loaders"><code>package.loaders</code></a> sequence. +<code>require</code> is guided by the <a href="#pdf-package.searchers"><code>package.searchers</code></a> sequence. By changing this sequence, we can change how <code>require</code> looks for a module. The following explanation is based on the default configuration -for <a href="#pdf-package.loaders"><code>package.loaders</code></a>. +for <a href="#pdf-package.searchers"><code>package.searchers</code></a>. <p> @@ -7261,7 +7261,7 @@ path stored in <a href="#pdf-package.path"><code>package.path</code></a>. If that also fails, it searches for a C loader using the path stored in <a href="#pdf-package.cpath"><code>package.cpath</code></a>. If that also fails, -it tries an <em>all-in-one</em> loader (see <a href="#pdf-package.loaders"><code>package.loaders</code></a>). +it tries an <em>all-in-one</em> loader (see <a href="#pdf-package.searchers"><code>package.searchers</code></a>). <p> @@ -7359,7 +7359,84 @@ table used by <a href="#pdf-require"><code>require</code></a>. <p> -<hr><h3><a name="pdf-package.loaders"><code>package.loaders</code></a></h3> +<hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3> + + +<p> +Dynamically links the host program with the C library <code>libname</code>. + + +<p> +If <code>funcname</code> is "<code>*</code>", +then it only links with the library, +making the symbols exported by the library +available to other dynamically linked libraries. +Otherwise, +it looks for a function <code>funcname</code> inside the library +and returns this function as a C function. +(So, <code>funcname</code> must follow the protocol (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>)). + + +<p> +This is a low-level function. +It completely bypasses the package and module system. +Unlike <a href="#pdf-require"><code>require</code></a>, +it does not perform any path searching and +does not automatically adds extensions. +<code>libname</code> must be the complete file name of the C library, +including if necessary a path and an extension. +<code>funcname</code> must be the exact name exported by the C library +(which may depend on the C compiler and linker used). + + +<p> +This function is not supported by Standard C. +As such, it is only available on some platforms +(Windows, Linux, Mac OS X, Solaris, BSD, +plus other Unix systems that support the <code>dlfcn</code> standard). + + + + +<p> +<hr><h3><a name="pdf-package.path"><code>package.path</code></a></h3> + + +<p> +The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader. + + +<p> +At start-up, Lua initializes this variable with +the value of the environment variable <a name="pdf-LUA_PATH_5_2"><code>LUA_PATH_5_2</code></a> or +the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or +with a default path defined in <code>luaconf.h</code>, +if the environment variable is not defined. +Any "<code>;;</code>" in the value of the environment variable +is replaced by the default path. + + + + +<p> +<hr><h3><a name="pdf-package.preload"><code>package.preload</code></a></h3> + + +<p> +A table to store loaders for specific modules +(see <a href="#pdf-require"><code>require</code></a>). + + +<p> +This variable is only a reference to the real table; +assignments to this variable do not change the +table used by <a href="#pdf-require"><code>require</code></a>. + + + + +<p> +<hr><h3><a name="pdf-package.searchers"><code>package.searchers</code></a></h3> <p> @@ -7445,83 +7522,6 @@ The first searcher returns no extra value. <p> -<hr><h3><a name="pdf-package.loadlib"><code>package.loadlib (libname, funcname)</code></a></h3> - - -<p> -Dynamically links the host program with the C library <code>libname</code>. - - -<p> -If <code>funcname</code> is "<code>*</code>", -then it only links with the library, -making the symbols exported by the library -available to other dynamically linked libraries. -Otherwise, -it looks for a function <code>funcname</code> inside the library -and returns this function as a C function. -(So, <code>funcname</code> must follow the protocol (see <a href="#lua_CFunction"><code>lua_CFunction</code></a>)). - - -<p> -This is a low-level function. -It completely bypasses the package and module system. -Unlike <a href="#pdf-require"><code>require</code></a>, -it does not perform any path searching and -does not automatically adds extensions. -<code>libname</code> must be the complete file name of the C library, -including if necessary a path and an extension. -<code>funcname</code> must be the exact name exported by the C library -(which may depend on the C compiler and linker used). - - -<p> -This function is not supported by Standard C. -As such, it is only available on some platforms -(Windows, Linux, Mac OS X, Solaris, BSD, -plus other Unix systems that support the <code>dlfcn</code> standard). - - - - -<p> -<hr><h3><a name="pdf-package.path"><code>package.path</code></a></h3> - - -<p> -The path used by <a href="#pdf-require"><code>require</code></a> to search for a Lua loader. - - -<p> -At start-up, Lua initializes this variable with -the value of the environment variable <a name="pdf-LUA_PATH_5_2"><code>LUA_PATH_5_2</code></a> or -the environment variable <a name="pdf-LUA_PATH"><code>LUA_PATH</code></a> or -with a default path defined in <code>luaconf.h</code>, -if the environment variable is not defined. -Any "<code>;;</code>" in the value of the environment variable -is replaced by the default path. - - - - -<p> -<hr><h3><a name="pdf-package.preload"><code>package.preload</code></a></h3> - - -<p> -A table to store loaders for specific modules -(see <a href="#pdf-require"><code>require</code></a>). - - -<p> -This variable is only a reference to the real table; -assignments to this variable do not change the -table used by <a href="#pdf-require"><code>require</code></a>. - - - - -<p> <hr><h3><a name="pdf-package.searchpath"><code>package.searchpath (name, path [, sep])</code></a></h3> @@ -10032,6 +10032,10 @@ as now patterns may contain '<code>\0</code>' as a regular character. </li> <li> +The table <code>package.loaders</code> was renamed <code>package.searchers</code>. +</li> + +<li> Lua does not have bytecode verification anymore. So, all functions that load code (<a href="#pdf-load"><code>load</code></a> and <a href="#pdf-loadfile"><code>loadfile</code></a>) @@ -10203,7 +10207,7 @@ Here is the complete syntax of Lua in extended BNF. <HR> <SMALL CLASS="footer"> Last update: -Mon Jun 27 15:48:15 BRT 2011 +Tue Jun 28 14:51:18 BRT 2011 </SMALL> <!-- Last change: revised for Lua 5.2.0 (beta) @@ -1,11 +1,10 @@ /* -** $Id: ldo.c,v 2.97 2011/06/20 16:36:03 roberto Exp $ +** $Id: ldo.c,v 2.98 2011/06/28 15:42:04 roberto Exp $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ -#include <locale.h> #include <setjmp.h> #include <stdlib.h> #include <string.h> @@ -613,22 +612,8 @@ struct SParser { /* data to `f_parser' */ Mbuffer buff; /* dynamic structure used by the scanner */ Dyndata dyd; /* dynamic structures used by the parser */ const char *name; - TString *savedlocale; }; - -/* -** save current locale and set locale to "C" for calling the parser -*/ -static Proto *callparser (lua_State *L, struct SParser *p, int c) { - const char *oldloc = setlocale(LC_ALL, NULL); /* get current locale */ - p->savedlocale = luaS_new(L, oldloc); /* make a copy */ - setsvalue2s(L, L->top - 1, p->savedlocale); /* anchor it */ - (void)setlocale(LC_ALL, "C"); /* standard locale for parsing Lua files */ - return luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); -} - - static void f_parser (lua_State *L, void *ud) { int i; Proto *tf; @@ -636,7 +621,8 @@ static void f_parser (lua_State *L, void *ud) { struct SParser *p = cast(struct SParser *, ud); int c = zgetc(p->z); /* read first character */ tf = (c == LUA_SIGNATURE[0]) - ? luaU_undump(L, p->z, &p->buff, p->name) : callparser(L, p, c); + ? luaU_undump(L, p->z, &p->buff, p->name) + : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); setptvalue2s(L, L->top, tf); incr_top(L); cl = luaF_newLclosure(L, tf); @@ -649,9 +635,8 @@ static void f_parser (lua_State *L, void *ud) { int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { struct SParser p; int status; - setnilvalue(L->top++); /* reserve space for anchoring locale */ L->nny++; /* cannot yield during parsing */ - p.z = z; p.name = name; p.savedlocale = NULL; + p.z = z; p.name = name; p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; p.dyd.label.arr = NULL; p.dyd.label.size = 0; @@ -662,10 +647,6 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size); luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size); L->nny--; - if (p.savedlocale) /* locale was changed? */ - (void)setlocale(LC_ALL, getstr(p.savedlocale)); /* restore old locale */ - setobjs2s(L, L->top - 2, L->top - 1); /* remove reserved space */ - --L->top; return status; } diff --git a/src/liolib.c b/src/liolib.c index a29a53ec..41e7ec55 100644 --- a/src/liolib.c +++ b/src/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.100 2011/06/21 13:43:48 roberto Exp $ +** $Id: liolib.c,v 2.101 2011/06/27 19:42:31 roberto Exp $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -49,7 +49,7 @@ #endif /* } */ -#define IO_PREFIX "lua_io_" +#define IO_PREFIX "_IO_" #define IO_INPUT (IO_PREFIX "input") #define IO_OUTPUT (IO_PREFIX "output") diff --git a/src/loadlib.c b/src/loadlib.c index ce3c2e6e..32c6ed25 100644 --- a/src/loadlib.c +++ b/src/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.98 2011/04/08 19:17:36 roberto Exp $ +** $Id: loadlib.c,v 1.99 2011/06/28 17:13:28 roberto Exp $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -376,7 +376,7 @@ static int checkload (lua_State *L, int stat, const char *filename) { } -static int loader_Lua (lua_State *L) { +static int searcher_Lua (lua_State *L) { const char *filename; const char *name = luaL_checkstring(L, 1); filename = findfile(L, name, "path"); @@ -403,7 +403,7 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) { } -static int loader_C (lua_State *L) { +static int searcher_C (lua_State *L) { const char *name = luaL_checkstring(L, 1); const char *filename = findfile(L, name, "cpath"); if (filename == NULL) return 1; /* module not found in this path */ @@ -411,7 +411,7 @@ static int loader_C (lua_State *L) { } -static int loader_Croot (lua_State *L) { +static int searcher_Croot (lua_State *L) { const char *filename; const char *name = luaL_checkstring(L, 1); const char *p = strchr(name, '.'); @@ -434,7 +434,7 @@ static int loader_Croot (lua_State *L) { } -static int loader_preload (lua_State *L) { +static int searcher_preload (lua_State *L) { const char *name = luaL_checkstring(L, 1); lua_getfield(L, LUA_REGISTRYINDEX, "_PRELOAD"); lua_getfield(L, -1, name); @@ -452,30 +452,30 @@ static int ll_require (lua_State *L) { lua_getfield(L, 2, name); if (lua_toboolean(L, -1)) /* is it there? */ return 1; /* package is already loaded */ - /* else must load it; iterate over available loaders */ - lua_getfield(L, lua_upvalueindex(1), "loaders"); + /* else must load it; iterate over available seachers to find a loader */ + lua_getfield(L, lua_upvalueindex(1), "searchers"); if (!lua_istable(L, -1)) - luaL_error(L, LUA_QL("package.loaders") " must be a table"); + luaL_error(L, LUA_QL("package.searchers") " must be a table"); lua_pushliteral(L, ""); /* error message accumulator */ for (i=1; ; i++) { - lua_rawgeti(L, -2, i); /* get a loader */ - if (lua_isnil(L, -1)) + lua_rawgeti(L, -2, i); /* get a seacher */ + if (lua_isnil(L, -1)) /* no more searchers? */ luaL_error(L, "module " LUA_QS " not found:%s", name, lua_tostring(L, -2)); lua_pushstring(L, name); lua_call(L, 1, 2); /* call it */ - if (lua_isfunction(L, -2)) /* did it find module? */ - break; /* module loaded successfully */ - else if (lua_isstring(L, -2)) { /* loader returned error message? */ + if (lua_isfunction(L, -2)) /* did it find a loader? */ + break; /* module loader found */ + else if (lua_isstring(L, -2)) { /* searcher returned error message? */ lua_pop(L, 1); /* remove extra return */ lua_concat(L, 2); /* accumulate error message */ } else lua_pop(L, 2); /* remove both returns */ } - lua_pushstring(L, name); /* pass name as argument to module */ + lua_pushstring(L, name); /* pass name as argument to module loader */ lua_insert(L, -2); /* name is 1st argument (before search data) */ - lua_call(L, 2, 1); /* run loaded module */ + lua_call(L, 2, 1); /* run loader to load module */ if (!lua_isnil(L, -1)) /* non-nil return? */ lua_setfield(L, 2, name); /* _LOADED[name] = returned value */ lua_getfield(L, 2, name); @@ -622,8 +622,8 @@ static const luaL_Reg ll_funcs[] = { }; -static const lua_CFunction loaders[] = - {loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; +static const lua_CFunction searchers[] = + {searcher_preload, searcher_Lua, searcher_C, searcher_Croot, NULL}; LUAMOD_API int luaopen_package (lua_State *L) { @@ -634,15 +634,19 @@ LUAMOD_API int luaopen_package (lua_State *L) { lua_setfield(L, -2, "__gc"); /* create `package' table */ luaL_newlib(L, pk_funcs); - /* create `loaders' table */ - lua_createtable(L, sizeof(loaders)/sizeof(loaders[0]) - 1, 0); - /* fill it with pre-defined loaders */ - for (i=0; loaders[i] != NULL; i++) { - lua_pushvalue(L, -2); /* set 'package' as upvalue for all loaders */ - lua_pushcclosure(L, loaders[i], 1); + /* create 'searchers' table */ + lua_createtable(L, sizeof(searchers)/sizeof(searchers[0]) - 1, 0); + /* fill it with pre-defined searchers */ + for (i=0; searchers[i] != NULL; i++) { + lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */ + lua_pushcclosure(L, searchers[i], 1); lua_rawseti(L, -2, i+1); } - lua_setfield(L, -2, "loaders"); /* put it in field `loaders' */ +#if defined(LUA_COMPAT_LOADERS) + lua_pushvalue(L, -1); /* make a copy of 'searchers' table */ + lua_setfield(L, -3, "loaders"); /* put it in field `loaders' */ +#endif + lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ /* set field 'path' */ setpath(L, "path", LUA_PATHVERSION, LUA_PATH, LUA_PATH_DEFAULT); /* set field 'cpath' */ diff --git a/src/lstrlib.c b/src/lstrlib.c index 465f9ff4..5e200f1c 100644 --- a/src/lstrlib.c +++ b/src/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.169 2011/06/16 14:14:05 roberto Exp $ +** $Id: lstrlib.c,v 1.170 2011/06/28 17:13:52 roberto Exp $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -917,15 +917,6 @@ static int str_format (lua_State *L) { /* }====================================================== */ -static int noindex (lua_State *L) { - const char *f = lua_tostring(L, 2); - if (f) - return luaL_error(L, "no field '%s' in strings", f); - else - return luaL_error(L, "no such field in strings"); -} - - static const luaL_Reg strlib[] = { {"byte", str_byte}, {"char", str_char}, @@ -941,22 +932,19 @@ static const luaL_Reg strlib[] = { {"reverse", str_reverse}, {"sub", str_sub}, {"upper", str_upper}, - {"__index", noindex}, {NULL, NULL} }; static void createmetatable (lua_State *L) { - /* setmetatable("", {__index = string}) */ + lua_createtable(L, 0, 1); /* table to be metatable for strings */ lua_pushliteral(L, ""); /* dummy string */ - lua_createtable(L, 0, 1); /* create metatable for strings */ - lua_pushvalue(L, -3); /* set the string library... */ - lua_setfield(L, -2, "__index"); /* ...as the __index metamethod */ - lua_setmetatable(L, -2); /* set metatable for strings */ + lua_pushvalue(L, -2); /* copy table */ + lua_setmetatable(L, -2); /* set table as metatable for strings */ lua_pop(L, 1); /* pop dummy string */ - /* setmetatable(string, string) */ - lua_pushvalue(L, -1); /* push string library */ - lua_setmetatable(L, -2); /* set it as its own metatable */ + lua_pushvalue(L, -2); /* get string library */ + lua_setfield(L, -2, "__index"); /* metatable.__index = string */ + lua_pop(L, 1); /* pop metatable */ } diff --git a/src/luaconf.h b/src/luaconf.h index 72a1689a..e1ffee7e 100644 --- a/src/luaconf.h +++ b/src/luaconf.h @@ -1,5 +1,5 @@ /* -** $Id: luaconf.h,v 1.159 2011/06/13 14:13:06 roberto Exp $ +** $Id: luaconf.h,v 1.160 2011/06/28 17:14:12 roberto Exp $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ @@ -246,6 +246,12 @@ #define LUA_COMPAT_UNPACK /* +@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'. +** You can replace it with 'package.searchers'. +*/ +#define LUA_COMPAT_LOADERS + +/* @@ macro 'lua_cpcall' emulates deprecated function lua_cpcall. ** You can call your C function directly (with light C functions). */ |