diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-05-22 20:09:14 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-05-22 20:09:14 +0300 |
commit | 851f31425ca3ec878cbaf516b8e3dad55164d80d (patch) | |
tree | 42cdbdbfdc918d774c11bd03e409df368dd49fd5 | |
parent | 328d5c17c44b4c7cb0623103c926dbae215745e4 (diff) | |
parent | eec27d0dcaab9444b874ce25ea7e3e551290b730 (diff) |
Merge pull request #7 from zakattacktwitter/master
Adding extname to complement basename.
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | paths.c | 18 |
2 files changed, 23 insertions, 0 deletions
@@ -41,6 +41,11 @@ This is similar to the well know shell command `"basename"`. Return the name of directory containing file `path`. This is similar to the well known shell command `"dirname"`. +<a name="paths.extname"/> +### paths.extname(path) ### + +Return the extension of the `path` or nil if none is found. + <a name="paths.concat"/> ### paths.concat([path1,....,pathn]) ### @@ -339,6 +339,23 @@ lua_dirname(lua_State *L) } +static int +lua_extname(lua_State *L) +{ + const char *fname = luaL_checkstring(L, 1); + const char *p; + + p = fname + strlen(fname) - 1; + while (p >= fname) { + if (*p == '.') { + lua_pushstring(L, p + 1); + return 1; + } + p--; + } + return 0; +} + /* ------------------------------------------------------ */ /* cwd and concat */ @@ -1095,6 +1112,7 @@ static const struct luaL_Reg paths__ [] = { {"dirp", lua_dirp}, {"basename", lua_basename}, {"dirname", lua_dirname}, + {"extname", lua_extname}, {"cwd", lua_cwd}, {"concat", lua_concatfname}, {"execdir", lua_execdir}, |