diff --git a/lua.lyx b/lua.lyx index df87eee6..3e71bedc 100644 --- a/lua.lyx +++ b/lua.lyx @@ -120,8 +120,8 @@ Expanded to string token containing path and filename of this Lua script. \begin_layout Standard In practicular, this is suitable to be passed as base argument of various - functions like loadfile, dofile, gui.bitmap_load, gui.bitmap_load_png and - gui.bitmap_load_pal. + functions like loadfile, dofile, resolve_filename, gui.bitmap_load, gui.bitmap_lo +ad_png and gui.bitmap_load_pal. \end_layout \begin_layout Section @@ -388,6 +388,18 @@ Execute lua script from , resolved relative to (if empty, current directory) and return all return values. \end_layout +\begin_layout Subsection +resolve_filename: Resolve name of file relative to another +\end_layout + +\begin_layout Itemize +Syntax: string resolve_file(string filename, string base) +\end_layout + +\begin_layout Standard +Resolve name of file relative to and return the result. +\end_layout + \begin_layout Standard \begin_inset Newpage pagebreak \end_inset diff --git a/lua.pdf b/lua.pdf index 63c86ca2..7693a539 100644 Binary files a/lua.pdf and b/lua.pdf differ diff --git a/src/lua/loadfile.cpp b/src/lua/loadfile.cpp index cbad9c2b..15bb87e4 100644 --- a/src/lua/loadfile.cpp +++ b/src/lua/loadfile.cpp @@ -199,4 +199,15 @@ namespace int new_sp = lua_gettop(L.handle()); return new_sp - (old_sp - 1); }); + + function_ptr_luafun resolvefile(LS, "resolve_filename", [](lua_state& L, const std::string& fname) + { + std::string file2; + std::string file1 = L.get_string(1, fname.c_str()); + if(L.type(2) != LUA_TNIL && L.type(2) != LUA_TNONE) + file2 = L.get_string(2, fname.c_str()); + std::string absfilename = resolve_file_relative(file1, file2); + L.pushlstring(absfilename); + return 1; + }); }