Lua: Implement function to resolve filename w.r.t. another
This commit is contained in:
parent
25f63a8c09
commit
3cb5d08c86
3 changed files with 25 additions and 2 deletions
16
lua.lyx
16
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 <filename>, resolved relative to <base> (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 <filename> relative to <base> and return the result.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
\begin_inset Newpage pagebreak
|
||||
\end_inset
|
||||
|
|
BIN
lua.pdf
BIN
lua.pdf
Binary file not shown.
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue