Fino a questo punto, tutto il nostro codice lua è in luarc. Questo è un buon modo per sviluppare il tuo script ma non è molto pratico per la distribuzione. Abbiamo bisogno di renderlo un modulo lua vero e proprio. Per fare ciò, salviamo il codice in un file separato (scp-storage.lua
in questo caso):
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 cercherà per gli script (seguendo le normali regole di lua) nella directory standard più $CONFIGDIR/lua/*.lua
. Quindi il nostro script può essere richiamato semplicemente aggiungendo require "scp-storage"
nel nostro file luarc. Un paio di note aggiuntive…
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 .