From 048fc44cfafd12f8aca5bb6a7bb05f898a8f5d2c Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 21 Feb 2012 23:32:58 +0000 Subject: [PATCH] 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. --- aegisub/src/auto4_lua.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index bb97e10ec..9538b1dc2 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -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(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);