From c632a662b2f43a1cd73f865ae88fefc8b309bcdc Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 28 Sep 2011 19:52:20 +0000 Subject: [PATCH] Change the naming scheme for lua commands to 'automation/lua/[Script File Name]/[Macro Name]' Originally committed to SVN as r5664. --- aegisub/src/auto4_lua.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/aegisub/src/auto4_lua.cpp b/aegisub/src/auto4_lua.cpp index 48af5618c..6cea78157 100644 --- a/aegisub/src/auto4_lua.cpp +++ b/aegisub/src/auto4_lua.cpp @@ -210,6 +210,7 @@ namespace Automation4 { lua_pushcfunction(L, luaopen_io); lua_call(L, 0, 0); lua_pushcfunction(L, luaopen_os); lua_call(L, 0, 0); _stackcheck.check_stack(0); + // dofile and loadfile are replaced with include lua_pushnil(L); lua_setglobal(L, "dofile"); @@ -240,6 +241,12 @@ namespace Automation4 { _stackcheck.check_stack(0); // prepare stuff in the registry + + // store the script's filename + lua_pushstring(L, wxFileName(GetFilename()).GetName().utf8_str().data()); + lua_setfield(L, LUA_REGISTRYINDEX, "filename"); + _stackcheck.check_stack(0); + // reference to the script object lua_pushlightuserdata(L, this); lua_setfield(L, LUA_REGISTRYINDEX, "aegisub"); @@ -539,11 +546,13 @@ namespace Automation4 { LuaCommand::LuaCommand(lua_State *L) : LuaFeature(L) - , cmd_name(std::string("automation/cmd/") + lua_tostring(L, 1)) , display(check_wxstring(L, 1)) , help(get_wxstring(L, 2)) , cmd_type(cmd::COMMAND_NORMAL) { + lua_getfield(L, LUA_REGISTRYINDEX, "filename"); + cmd_name = STD_STR(wxString::Format("automation/lua/%s/%s", get_wxstring(L, -1), check_wxstring(L, 1))); + if (!lua_isfunction(L, 3)) luaL_error(L, "The macro processing function must be a function");