Cały nasz kod znajduje się do tej pory w luarc. To dobre miejsce na rozwój kodu, ale niekoniecznie do jego dystrybucji. Potrzebujemy umieścić go w odpowiednim module lua. W tym celu zapiszemy kod w odrębnym pliku (w tym przypadku 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 poszuka skryptów (zgodnie z regułami lua) w standardowych katalogach plus $CONFIGDIR/lua/*.lua. Nasz skrypt może więc być wywoływany poprzez proste dodanie require "scp-storage" w pliku luarc. Jeszcze tylko kilka uwag…

  • 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.

Once you have filled all the fields, checked your code, you can upload it to our script page here .