Наразі весь наш код lua був у luarc. Це хороший спосіб розробити свій сценарій, але не дуже практичний для розповсюдження. Нам потрібно зробити це належним модулем lua. Для цього ми зберігаємо код в окремому файлі (в даному випадку scp-storage.lua):

 1--[[
 2SCP STORAGE
 3a simple storage to export images via scp
 4
 5AUTHOR
 6Jérémy Rosen (jeremy.rosen@enst-bretagne.fr)
 7
 8INSTALLATION
 9* copy this file in $CONFIGDIR/lua/ where CONFIGDIR
10is your Ansel configuration directory
11* add the following line in the file $CONFIGDIR/luarc
12  require "scp-storage"
13
14USAGE
15* select "Export via SCP" in the storage selection menu
16* set the target directory
17* export your images
18
19LICENSE
20GPLv2
21
22]]
23Ansel = require "Ansel"
24Ansel.configuration.check_version(...,{2,0,0})
25
26local scp_path = Ansel.new_widget("entry"){
27  tooltip ="Complete path to copy to. Can include user and hostname",
28  text = "",
29  reset_callback = function(self) self.text = "" end
30}
31
32Ansel.register_storage("scp_export","Export via scp",
33  function( storage, image, format, filename,
34     number, total, high_quality, extra_data)
35    if coroutine.yield("RUN_COMMAND","scp "..filename.." "..
36      scp_path.text
37    ) then
38      Ansel.print_error("scp failed for "..tostring(image))
39    end
40    end,
41    nil, --finalize
42    nil, --supported
43    nil, --initialize
44    Ansel.new_widget("box") {
45    orientation ="horizontal",
46    Ansel.new_widget("label"){label = "target SCP PATH "},
47    scp_path,
48})

Ansel will look for scripts (following the normal lua rules) in the standard directories plus $CONFIGDIR/lua/*.lua. So our script can be called by simply adding require "scp-storage" in the luarc file. A couple of extra notes…

  • The function Ansel.configuration.check_version will check compatibility for you. The “...” will turn into your script’s name and {2,0,0} is the API version you have tested your script with. You can add multiple API versions if you update your script for multiple versions of Ansel.

  • Make sure to declare all your functions as local so as not to pollute the general namespace.

  • Make sure you do not leave debug prints in your code – Ansel.print_error in particular allows you to leave debug prints in your final code without disturbing the console.

  • You are free to choose any license for your script but scripts that are uploaded on Ansel’s website need to be GPLv2.

Після заповнення всіх полів, перевірки коду, ви можете завантажити його на нашу сторінку сценаріїв тут .