Add aegisub.file_name() to get the file name of the subtitles file

If called during a macro processing or validation function when the
subtitles have a valid file name (i.e. they've been saved and are not
Untitled), this returns the name of the file, without the path. If
called at any other time, it returns nil.

Originally committed to SVN as r6498.
This commit is contained in:
Thomas Goyne 2012-02-21 23:32:58 +00:00
parent 2dd01747f8
commit 048fc44cfa
1 changed files with 11 additions and 0 deletions

View File

@ -142,6 +142,16 @@ namespace {
return c;
}
int get_file_name(lua_State *L)
{
const agi::Context *c = get_context(L);
if (c && c->ass->filename.size())
lua_pushstring(L, wxFileName(c->ass->filename).GetFullName().utf8_str());
else
lua_pushnil(L);
return 1;
}
inline wxRegEx *get_regex(lua_State *L)
{
return static_cast<wxRegEx*>(luaL_checkudata(L, 1, "aegisub.regex"));
@ -392,6 +402,7 @@ namespace Automation4 {
set_field(L, "cancel", LuaCancel);
set_field(L, "lua_automation_version", 4);
set_field(L, "__init_regex", regex_init);
set_field(L, "file_name", get_file_name);
// store aegisub table to globals
lua_settable(L, LUA_GLOBALSINDEX);