Update Lua Action scripts from local file when possible
This commit is contained in:
parent
682f4dafd3
commit
2f61071974
|
@ -1197,9 +1197,27 @@ LuaInstance::~LuaInstance ()
|
||||||
_callbacks.clear();
|
_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
|
void
|
||||||
LuaInstance::init ()
|
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 (
|
lua.do_command (
|
||||||
"function ScriptManager ()"
|
"function ScriptManager ()"
|
||||||
" local self = { scripts = {}, instances = {}, icons = {} }"
|
" local self = { scripts = {}, instances = {}, icons = {} }"
|
||||||
|
@ -1302,10 +1320,20 @@ LuaInstance::init ()
|
||||||
" collectgarbage()"
|
" collectgarbage()"
|
||||||
" end"
|
" end"
|
||||||
""
|
""
|
||||||
|
" local get_factory_bytecode = Internal.get_factory_bytecode"
|
||||||
|
" local read_script = Internal.read_script"
|
||||||
" local restore = function (state)"
|
" local restore = function (state)"
|
||||||
" clear()"
|
" clear()"
|
||||||
" load (state)()"
|
" load (state)()"
|
||||||
" for i, s in pairs (scripts) do"
|
" 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'])"
|
" addinternal (i, s['n'], s['s'], load(s['f']), type (s['c']) ~= \"string\" or s['c'] == '' or load (s['c']), s['a'])"
|
||||||
" end"
|
" end"
|
||||||
" collectgarbage()"
|
" collectgarbage()"
|
||||||
|
@ -1323,6 +1351,7 @@ LuaInstance::init ()
|
||||||
try {
|
try {
|
||||||
luabridge::LuaRef lua_mgr = luabridge::getGlobal (L, "manager");
|
luabridge::LuaRef lua_mgr = luabridge::getGlobal (L, "manager");
|
||||||
lua.do_command ("manager = nil"); // hide it.
|
lua.do_command ("manager = nil"); // hide it.
|
||||||
|
lua.do_command ("Internal = nil");
|
||||||
lua.do_command ("collectgarbage()");
|
lua.do_command ("collectgarbage()");
|
||||||
|
|
||||||
_lua_add_action = new luabridge::LuaRef(lua_mgr["add"]);
|
_lua_add_action = new luabridge::LuaRef(lua_mgr["add"]);
|
||||||
|
|
|
@ -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 (int, max_note_height, "max-note-height", 20)
|
||||||
UI_CONFIG_VARIABLE (bool, prefer_tap_tempo, "prefer-tap-tempo", false)
|
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, 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 */
|
/* 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)
|
UI_CONFIG_VARIABLE (bool, show_on_cue_page, "show-on-cue-page", true)
|
||||||
|
|
Loading…
Reference in New Issue