On 15 March 2010 12:03, Taco Hoekwater <t...@elvenkind.com> wrote: > > Oh, alright then. Patch applied (#3494)
Thanks. One more patch for your consideration for something I needed recently: getting absolute, canonical file paths. In principle this can be implemented in pure Lua with the current lfs module, but getting all the corner cases right (e.g. foo/bar/./../baz) is not so easy. Perhaps having a convenience function for this is not such a bad idea (and using proper system APIs will guarantee that the result is correct). There is no Unix counterpart in the patch, because I didn't know how to implement it (with a call to realpath?) and I would have no way to test it anyway. Cheers, Tomek
Index: lfs.c =================================================================== --- lfs.c (revision 3491) +++ lfs.c (working copy) @@ -698,6 +698,10 @@ /* simply do nothing */ return 1; } +static int get_real_path (lua_State *L) { + /* to be implemented */ + return 1; +} #else static int link_info (lua_State *L) { lua_pushboolean(L, 0); @@ -729,6 +733,26 @@ lua_pushlstring(L, (const char *)buffer, (size_t)length); return 1; } +static int get_real_path (lua_State *L) { + long length = 0; + TCHAR* buffer = NULL; + const char *lpszPath = luaL_checkstring (L, 1); + length = GetFullPathName(lpszPath, 0, NULL, NULL); + if (length == 0) { + lua_pushnil(L); + lua_pushfstring(L, "operating system error: %d", (int)GetLastError()); + return 2; + } + buffer = (TCHAR *)xmalloc(length * sizeof(TCHAR)); + length = GetFullPathName(lpszPath, length, buffer, NULL); + if (length == 0) { + lua_pushnil(L); + lua_pushfstring(L, "operating system error: %d", (int)GetLastError()); + return 2; + } + lua_pushlstring(L, (const char *)buffer, (size_t)length); + return 1; +} #endif @@ -800,6 +824,7 @@ {"symlinkattributes", link_info}, {"readlink", read_link}, {"shortname", get_short_name}, + {"realpath", get_real_path}, {"setmode", lfs_f_setmode}, {"touch", file_utime}, {"unlock", file_unlock},
_______________________________________________ dev-luatex mailing list dev-luatex@ntg.nl http://www.ntg.nl/mailman/listinfo/dev-luatex