summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ldo.c27
-rw-r--r--src/liolib.c4
-rw-r--r--src/loadlib.c52
-rw-r--r--src/lstrlib.c26
-rw-r--r--src/luaconf.h8
5 files changed, 48 insertions, 69 deletions
diff --git a/src/ldo.c b/src/ldo.c
index 99868aee..a34b0d0b 100644
--- a/src/ldo.c
+++ b/src/ldo.c
@@ -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).
*/