diff --git a/gtk2_ardour/luainstance.cc b/gtk2_ardour/luainstance.cc index 84436f576e..7e38443e78 100644 --- a/gtk2_ardour/luainstance.cc +++ b/gtk2_ardour/luainstance.cc @@ -1197,9 +1197,27 @@ LuaInstance::~LuaInstance () _callbacks.clear(); } +static std::string +lua_read_script (std::string const& fn) +{ + if (!UIConfiguration::instance().get_update_action_scripts ()) { + return ""; + } + try { + return Glib::file_get_contents (fn); + } catch (...) { } + return ""; +} + void LuaInstance::init () { + luabridge::getGlobalNamespace (lua.getState()) + .beginNamespace ("Internal") + .addFunction ("get_factory_bytecode", &LuaScripting::get_factory_bytecode) + .addFunction ("read_script", &lua_read_script) + .endNamespace (); + lua.do_command ( "function ScriptManager ()" " local self = { scripts = {}, instances = {}, icons = {} }" @@ -1302,10 +1320,20 @@ LuaInstance::init () " collectgarbage()" " end" "" + " local get_factory_bytecode = Internal.get_factory_bytecode" + " local read_script = Internal.read_script" " local restore = function (state)" " clear()" " load (state)()" " for i, s in pairs (scripts) do" + " if s['a']['x-script-origin'] then" + " local sc = read_script (s['a']['x-script-origin'])" + " if sc ~= '' then" + " fnc = nil load (get_factory_bytecode (sc, 'factory', 'fnc'))()" + " icn = nil load (get_factory_bytecode (sc, 'icon', 'icn'))()" + " if fnc ~= '' and type(fnc) == 'string' then s['f'] = fnc s['c'] = icn s['s'] = sc end " + " end" + " end" " addinternal (i, s['n'], s['s'], load(s['f']), type (s['c']) ~= \"string\" or s['c'] == '' or load (s['c']), s['a'])" " end" " collectgarbage()" @@ -1323,6 +1351,7 @@ LuaInstance::init () try { luabridge::LuaRef lua_mgr = luabridge::getGlobal (L, "manager"); lua.do_command ("manager = nil"); // hide it. + lua.do_command ("Internal = nil"); lua.do_command ("collectgarbage()"); _lua_add_action = new luabridge::LuaRef(lua_mgr["add"]); diff --git a/gtk2_ardour/ui_config_vars.h b/gtk2_ardour/ui_config_vars.h index 3a1cd67ade..2df950a475 100644 --- a/gtk2_ardour/ui_config_vars.h +++ b/gtk2_ardour/ui_config_vars.h @@ -156,6 +156,7 @@ UI_CONFIG_VARIABLE (std::string, freesound_dir, "freesound-dir", "") UI_CONFIG_VARIABLE (int, max_note_height, "max-note-height", 20) UI_CONFIG_VARIABLE (bool, prefer_tap_tempo, "prefer-tap-tempo", false) UI_CONFIG_VARIABLE (bool, sandbox_all_lua_scripts, "sandbox-all-lua-scripts", false) +UI_CONFIG_VARIABLE (bool, update_action_scripts, "update-action-scripts", true) /* these are visibility-type selections in the New Track dialog that we should make persistent for the user's choices */ UI_CONFIG_VARIABLE (bool, show_on_cue_page, "show-on-cue-page", true)