aboutsummaryrefslogtreecommitdiff
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-67feed49f189e8e6318a5ef63461e10e2d174a82.tar.gz
lua-67feed49f189e8e6318a5ef63461e10e2d174a82.tar.bz2
lua-67feed49f189e8e6318a5ef63461e10e2d174a82.zip
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 @@
1/* 1/*
2** $Id: loadlib.c,v 1.93 2010/11/10 18:05:36 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.94 2010/11/10 20:00:04 roberto Exp roberto $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5** 5**
@@ -321,8 +321,10 @@ static const char *pushnexttemplate (lua_State *L, const char *path) {
321 321
322 322
323static const char *searchpath (lua_State *L, const char *name, 323static const char *searchpath (lua_State *L, const char *name,
324 const char *path) { 324 const char *path,
325 name = luaL_gsub(L, name, ".", LUA_DIRSEP); 325 const char *sep) {
326 if (*sep != '\0') /* non-empty separator? */
327 name = luaL_gsub(L, name, sep, LUA_DIRSEP); /* replace it by proper one */
326 lua_pushliteral(L, ""); /* error accumulator */ 328 lua_pushliteral(L, ""); /* error accumulator */
327 while ((path = pushnexttemplate(L, path)) != NULL) { 329 while ((path = pushnexttemplate(L, path)) != NULL) {
328 const char *filename = luaL_gsub(L, lua_tostring(L, -1), 330 const char *filename = luaL_gsub(L, lua_tostring(L, -1),
@@ -339,7 +341,9 @@ static const char *searchpath (lua_State *L, const char *name,
339 341
340 342
341static int ll_searchpath (lua_State *L) { 343static int ll_searchpath (lua_State *L) {
342 const char *f = searchpath(L, luaL_checkstring(L, 1), luaL_checkstring(L, 2)); 344 const char *f = searchpath(L, luaL_checkstring(L, 1),
345 luaL_checkstring(L, 2),
346 luaL_optstring(L, 3, "."));
343 if (f != NULL) return 1; 347 if (f != NULL) return 1;
344 else { /* error message is on top of the stack */ 348 else { /* error message is on top of the stack */
345 lua_pushnil(L); 349 lua_pushnil(L);
@@ -356,7 +360,7 @@ static const char *findfile (lua_State *L, const char *name,
356 path = lua_tostring(L, -1); 360 path = lua_tostring(L, -1);
357 if (path == NULL) 361 if (path == NULL)
358 luaL_error(L, LUA_QL("package.%s") " must be a string", pname); 362 luaL_error(L, LUA_QL("package.%s") " must be a string", pname);
359 return searchpath(L, name, path); 363 return searchpath(L, name, path, ".");
360} 364}
361 365
362 366