diff options
author | Robin Gareus <robin@gareus.org> | 2019-01-02 22:26:19 +0100 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2019-01-02 22:26:19 +0100 |
commit | e612be90376ff139bdbf82cea31f34b9f18c84fe (patch) | |
tree | 3b7562dfeca59034140486b2f6bb483084df3660 /scripts | |
parent | 86a78dc1000ab9a5e54c94f6df2e41c95e9b5098 (diff) |
Add an example plugin to demonstrate Lua global variables
Note: this only works when loading the script action.
Window > Scripting doesn't run the factory method for upindex variables
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/_remember_file.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/_remember_file.lua b/scripts/_remember_file.lua new file mode 100644 index 0000000000..7a79fc861b --- /dev/null +++ b/scripts/_remember_file.lua @@ -0,0 +1,37 @@ +ardour { + ["type"] = "EditorAction", + name = "File Name Test", + author = "Ardour Lua Taskforce", + description = [[Example Plugin to show to to select a file and remember the most recently used file.]] +} + +function factory () + local file_name_testscript_last_filename -- this acts as "global" variable, use a unique name + return function () + print (file_name_testscript_last_filename) -- debug + + --set filename to most recently used, fall back to use a default + local fn = file_name_testscript_last_filename or ARDOUR.LuaAPI.build_filename (Session:path (), Session:name () .. ".ardour") + + -- prepare a dialog + local dialog_options = { + { type = "file", key = "file", title = "Select a File", path = fn } + } + + -- show dialog + local od = LuaDialog.Dialog ("title", dialog_options) + local rv = od:run() + + if rv then + -- remember most recently selected file + file_name_testscript_last_filename = rv['file'] + LuaDialog.Message ("title", "set path to " .. file_name_testscript_last_filename, LuaDialog.MessageType.Info, LuaDialog.ButtonType.Close):run() + else + -- unset most recently used filename on dialog "cancel" + file_name_testscript_last_filename = nil + end + + od = nil + collectgarbage () + end +end |