File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ This is similar to the well know shell command `"basename"`.
4141Return the name of directory containing file ` path ` .
4242This is similar to the well known shell command ` "dirname" ` .
4343
44+ <a name =" paths.extname " />
45+ ### paths.extname(path) ###
46+
47+ Return the extension of the ` path ` or nil if none is found.
48+
4449<a name =" paths.concat " />
4550### paths.concat([ path1,....,pathn] ) ###
4651
Original file line number Diff line number Diff line change @@ -339,6 +339,23 @@ lua_dirname(lua_State *L)
339339}
340340
341341
342+ static int
343+ lua_extname (lua_State * L )
344+ {
345+ const char * fname = luaL_checkstring (L , 1 );
346+ const char * p ;
347+
348+ p = fname + strlen (fname ) - 1 ;
349+ while (p >= fname ) {
350+ if (* p == '.' ) {
351+ lua_pushstring (L , p + 1 );
352+ return 1 ;
353+ }
354+ p -- ;
355+ }
356+ return 0 ;
357+ }
358+
342359
343360/* ------------------------------------------------------ */
344361/* cwd and concat */
@@ -1095,6 +1112,7 @@ static const struct luaL_Reg paths__ [] = {
10951112 {"dirp" , lua_dirp },
10961113 {"basename" , lua_basename },
10971114 {"dirname" , lua_dirname },
1115+ {"extname" , lua_extname },
10981116 {"cwd" , lua_cwd },
10991117 {"concat" , lua_concatfname },
11001118 {"execdir" , lua_execdir },
You can’t perform that action at this time.
0 commit comments