Tot nu toe staat al onze lua-code in luarc. Dat is een goede manier om jou script te ontwikkelen, maar niet erg praktisch voor distributie. We moeten hier een goede lua-module van maken. Om dat te doen, slaan we de code op in een apart bestand (in dit geval 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 zoekt naar scripts (volgens de normale lua-regels) in de standaardmappen plus $CONFIGDIR/lua/*.lua. Ons script kan dus worden aangeroepen door simpelweg require "scp-storage" toe te voegen aan het luarc-bestand. Een paar extra opmerkingen…

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