aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-07-13 16:02:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-07-13 16:02:42 -0300
commitd6ff5d9f46be3db99dd3fec0c12504b7ba1854e1 (patch)
tree268a21e18ee7d43fd9147f89b6039b1b11b2536d /lauxlib.c
parenta05190fa3b5c3685b0772f0235f136e05587fa9c (diff)
downloadlua-d6ff5d9f46be3db99dd3fec0c12504b7ba1854e1.tar.gz
lua-d6ff5d9f46be3db99dd3fec0c12504b7ba1854e1.tar.bz2
lua-d6ff5d9f46be3db99dd3fec0c12504b7ba1854e1.zip
searchpath is "private affair" of loadlib
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c35
1 files changed, 1 insertions, 34 deletions
diff --git a/lauxlib.c b/lauxlib.c
index ace7df42..8e954149 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.139 2005/07/11 16:41:51 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.140 2005/07/12 14:32:48 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -325,16 +325,6 @@ LUALIB_API int luaL_getn (lua_State *L, int t) {
325/* }====================================================== */ 325/* }====================================================== */
326 326
327 327
328static const char *pushnexttemplate (lua_State *L, const char *path) {
329 const char *l;
330 while (*path == *LUA_PATHSEP) path++; /* skip separators */
331 if (*path == '\0') return NULL; /* no more templates */
332 l = strchr(path, *LUA_PATHSEP); /* find next separator */
333 if (l == NULL) l = path+strlen(path);
334 lua_pushlstring(L, path, l - path); /* template */
335 return l;
336}
337
338 328
339LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, 329LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
340 const char *r) { 330 const char *r) {
@@ -353,29 +343,6 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
353} 343}
354 344
355 345
356static int readable (const char *fname) {
357 FILE *f = fopen(fname, "r"); /* try to open file */
358 if (f == NULL) return 0; /* open failed */
359 fclose(f);
360 return 1;
361}
362
363
364LUALIB_API const char *luaL_searchpath (lua_State *L, const char *name,
365 const char *path) {
366 const char *p = path;
367 for (;;) {
368 const char *fname;
369 if ((p = pushnexttemplate(L, p)) == NULL)
370 return NULL;
371 fname = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name);
372 lua_remove(L, -2); /* remove path template */
373 if (readable(fname)) /* does file exist and is readable? */
374 return fname; /* return that file name */
375 lua_pop(L, 1); /* remove file name */
376 }
377}
378
379 346
380LUALIB_API const char *luaL_getfield (lua_State *L, int idx, 347LUALIB_API const char *luaL_getfield (lua_State *L, int idx,
381 const char *fname) { 348 const char *fname) {