diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-03-11 09:08:13 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-03-11 09:08:13 -0300 |
| commit | 430d6db92827ae2797f435dd5019b5cd115859ef (patch) | |
| tree | 15aed8a4b2dc415e5e1064c2cc5f50f8128c14cf | |
| parent | 7c3857cdeda673d011313501492a61efa1462d46 (diff) | |
| download | lua-430d6db92827ae2797f435dd5019b5cd115859ef.tar.gz lua-430d6db92827ae2797f435dd5019b5cd115859ef.tar.bz2 lua-430d6db92827ae2797f435dd5019b5cd115859ef.zip | |
LUA_PATH components may have multiple interrogation marks
| -rw-r--r-- | lbaselib.c | 24 |
1 files changed, 17 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.124 2003/02/27 11:52:30 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.125 2003/03/06 19:36:16 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -408,6 +408,10 @@ static int luaB_newproxy (lua_State *L) { | |||
| 408 | #define LUA_PATH_SEP ';' | 408 | #define LUA_PATH_SEP ';' |
| 409 | #endif | 409 | #endif |
| 410 | 410 | ||
| 411 | #ifndef LUA_PATH_MARK | ||
| 412 | #define LUA_PATH_MARK '?' | ||
| 413 | #endif | ||
| 414 | |||
| 411 | #ifndef LUA_PATH_DEFAULT | 415 | #ifndef LUA_PATH_DEFAULT |
| 412 | #define LUA_PATH_DEFAULT "?;?.lua" | 416 | #define LUA_PATH_DEFAULT "?;?.lua" |
| 413 | #endif | 417 | #endif |
| @@ -438,12 +442,18 @@ static const char *pushnextpath (lua_State *L, const char *path) { | |||
| 438 | 442 | ||
| 439 | static void pushcomposename (lua_State *L) { | 443 | static void pushcomposename (lua_State *L) { |
| 440 | const char *path = lua_tostring(L, -1); | 444 | const char *path = lua_tostring(L, -1); |
| 441 | const char *wild = strchr(path, '?'); | 445 | const char *wild; |
| 442 | if (wild == NULL) return; /* no wild char; path is the file name */ | 446 | int n = 1; |
| 443 | lua_pushlstring(L, path, wild - path); | 447 | while ((wild = strchr(path, LUA_PATH_MARK)) != NULL) { |
| 444 | lua_pushvalue(L, 1); /* package name */ | 448 | /* is there stack space for prefix, name, and eventual last sufix? */ |
| 445 | lua_pushstring(L, wild + 1); | 449 | luaL_checkstack(L, 3, "too many marks in a path component"); |
| 446 | lua_concat(L, 3); | 450 | lua_pushlstring(L, path, wild - path); /* push prefix */ |
| 451 | lua_pushvalue(L, 1); /* push package name (in place of MARK) */ | ||
| 452 | path = wild + 1; /* continue after MARK */ | ||
| 453 | n += 2; | ||
| 454 | } | ||
| 455 | lua_pushstring(L, path); /* push last sufix (`n' already includes this) */ | ||
| 456 | lua_concat(L, n); | ||
| 447 | } | 457 | } |
| 448 | 458 | ||
| 449 | 459 | ||
