summaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-01-07 16:54:49 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-01-07 16:54:49 -0200
commit67feed49f189e8e6318a5ef63461e10e2d174a82 (patch)
treeb6c46f4a33e35e726d592c07c9dcfeb35b28a1c4 /loadlib.c
parentb63b0928cf22073a04be16c7376f2be255c4cc96 (diff)
downloadlua-github-67feed49f189e8e6318a5ef63461e10e2d174a82.tar.gz
optional argument 'sep' to 'searchpath'
Diffstat (limited to 'loadlib.c')
-rw-r--r--loadlib.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/loadlib.c b/loadlib.c
index 7365affe..c9e93ac7 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: loadlib.c,v 1.93 2010/11/10 18:05:36 roberto Exp roberto $
+** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp roberto $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@@ -321,8 +321,10 @@ static const char *pushnexttemplate (lua_State *L, const char *path) {
static const char *searchpath (lua_State *L, const char *name,
- const char *path) {
- name = luaL_gsub(L, name, ".", LUA_DIRSEP);
+ const char *path,
+ const char *sep) {
+ if (*sep != '\0') /* non-empty separator? */
+ name = luaL_gsub(L, name, sep, LUA_DIRSEP); /* replace it by proper one */
lua_pushliteral(L, ""); /* error accumulator */
while ((path = pushnexttemplate(L, path)) != NULL) {
const char *filename = luaL_gsub(L, lua_tostring(L, -1),
@@ -339,7 +341,9 @@ static const char *searchpath (lua_State *L, const char *name,
static int ll_searchpath (lua_State *L) {
- const char *f = searchpath(L, luaL_checkstring(L, 1), luaL_checkstring(L, 2));
+ const char *f = searchpath(L, luaL_checkstring(L, 1),
+ luaL_checkstring(L, 2),
+ luaL_optstring(L, 3, "."));
if (f != NULL) return 1;
else { /* error message is on top of the stack */
lua_pushnil(L);
@@ -356,7 +360,7 @@ static const char *findfile (lua_State *L, const char *name,
path = lua_tostring(L, -1);
if (path == NULL)
luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
- return searchpath(L, name, path);
+ return searchpath(L, name, path, ".");
}