summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2010-11-17 12:00:00 +0000
committerrepogen <>2010-11-17 12:00:00 +0000
commit850a3d8f8d2ef75c2e7579f31e3b301a72c279cd (patch)
tree579a35a77bca170f4a8fcb90442a7b226436b099 /src
parentccd28dfe034d5dfd130e5378a147e3e9fe7f6807 (diff)
downloadlua-github-850a3d8f8d2ef75c2e7579f31e3b301a72c279cd.tar.gz
Lua 5.2.0-alpha-rc25.2.0-alpha-rc2
Diffstat (limited to 'src')
-rw-r--r--src/lauxlib.h27
-rw-r--r--src/ldblib.c19
-rw-r--r--src/lstrlib.c18
3 files changed, 31 insertions, 33 deletions
diff --git a/src/lauxlib.h b/src/lauxlib.h
index f4e31bc8..39506456 100644
--- a/src/lauxlib.h
+++ b/src/lauxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.h,v 1.111 2010/11/10 18:05:36 roberto Exp $
+** $Id: lauxlib.h,v 1.113 2010/11/16 19:20:01 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -62,6 +62,10 @@ LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
const char *const lst[]);
+/* pre-defined references */
+#define LUA_NOREF (-2)
+#define LUA_REFNIL (-1)
+
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
@@ -120,8 +124,6 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
-#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
-
/*
** {======================================================
@@ -158,27 +160,14 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
/* }====================================================== */
+/* compatibility with old module system */
+
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
-
-/* compatibility with ref system */
-
-/* pre-defined references */
-#define LUA_NOREF (-2)
-#define LUA_REFNIL (-1)
-
-#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
- (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
-
-#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
-
-#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
-
-
-#define luaL_reg luaL_Reg
+#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
diff --git a/src/ldblib.c b/src/ldblib.c
index 04213159..d631dcba 100644
--- a/src/ldblib.c
+++ b/src/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.125 2010/11/10 18:06:10 roberto Exp $
+** $Id: ldblib.c,v 1.126 2010/11/16 18:01:28 roberto Exp $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -44,22 +44,19 @@ static int db_setmetatable (lua_State *L) {
}
-static void checkudata (lua_State *L, int narg) {
- if (lua_type(L, narg) == LUA_TLIGHTUSERDATA)
- luaL_argerror(L, narg, "full userdata expected, got light userdata");
- luaL_checktype(L, narg, LUA_TUSERDATA);
-}
-
-
static int db_getuservalue (lua_State *L) {
- checkudata(L, 1);
- lua_getuservalue(L, 1);
+ if (lua_type(L, 1) != LUA_TUSERDATA)
+ lua_pushnil(L);
+ else
+ lua_getuservalue(L, 1);
return 1;
}
static int db_setuservalue (lua_State *L) {
- checkudata(L, 1);
+ if (lua_type(L, 1) == LUA_TLIGHTUSERDATA)
+ luaL_argerror(L, 1, "full userdata expected, got light userdata");
+ luaL_checktype(L, 1, LUA_TUSERDATA);
if (!lua_isnoneornil(L, 2))
luaL_checktype(L, 2, LUA_TTABLE);
lua_settop(L, 2);
diff --git a/src/lstrlib.c b/src/lstrlib.c
index 1cd37def..82c2005e 100644
--- a/src/lstrlib.c
+++ b/src/lstrlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstrlib.c,v 1.157 2010/11/08 17:38:37 roberto Exp $
+** $Id: lstrlib.c,v 1.158 2010/11/16 20:39:41 roberto Exp $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@@ -505,6 +505,18 @@ static int push_captures (MatchState *ms, const char *s, const char *e) {
}
+/* check whether pattern has no special characters */
+static int nospecials (const char *p, size_t l) {
+ size_t upto = 0;
+ do {
+ if (strpbrk(p + upto, SPECIALS))
+ return 0; /* pattern has a special character */
+ upto += strlen(p + upto) + 1; /* may have more after \0 */
+ } while (upto <= l);
+ return 1; /* no special chars found */
+}
+
+
static int str_find_aux (lua_State *L, int find) {
size_t ls, lp;
const char *s = luaL_checklstring(L, 1, &ls);
@@ -515,8 +527,8 @@ static int str_find_aux (lua_State *L, int find) {
lua_pushnil(L); /* cannot find anything */
return 1;
}
- if (find && (lua_toboolean(L, 4) || /* explicit request? */
- strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
+ /* explicit request or no special characters? */
+ if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp);
if (s2) {