diff options
Diffstat (limited to 'doc/it/weechat_scripting.it.adoc')
-rw-r--r-- | doc/it/weechat_scripting.it.adoc | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/doc/it/weechat_scripting.it.adoc b/doc/it/weechat_scripting.it.adoc index 2a1b96a66..68c9976c0 100644 --- a/doc/it/weechat_scripting.it.adoc +++ b/doc/it/weechat_scripting.it.adoc @@ -1097,26 +1097,54 @@ weechat.hook_timer(60 * 1000, 60, 0, "timer_cb", "") callback verrà chiamata quando i dati sono pronti. Può essere chiamata più volte. -Per l'ultima chiamata alla callback, _rc_ è impostato a zero o su un +Per l'ultima chiamata alla callback, _return_code_ è impostato a zero o su un valore positivo, è il codice restituito dal comando. Esempio: [source,python] ---- -process_output = "" - -def my_process_cb(data, command, rc, out, err): - global process_output - if out != "": - process_output += out - if int(rc) >= 0: - weechat.prnt("", process_output) +def my_process_cb(data, command, return_code, out, err): + if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: + weechat.prnt("", "Error with command '%s'" % command) + return weechat.WEECHAT_RC_OK + if return_code >= 0: + weechat.prnt("", "return_code = %d" % return_code) + if out: + weechat.prnt("", "stdout: %s" % out) + if err: + weechat.prnt("", "stderr: %s" % err) return weechat.WEECHAT_RC_OK weechat.hook_process("/bin/ls -l /etc", 10 * 1000, "my_process_cb", "") ---- +// TRANSLATION MISSING +You can also call directly a script function that does something blocking, +instead of an external command: + +[source,python] +---- +def get_status(data): + # do something blocking... + # ... + return "this is the result" + +def my_process_cb(data, command, return_code, out, err): + if return_code == weechat.WEECHAT_HOOK_PROCESS_ERROR: + weechat.prnt("", "Error with command '%s'" % command) + return weechat.WEECHAT_RC_OK + if return_code >= 0: + weechat.prnt("", "return_code = %d" % return_code) + if out: + weechat.prnt("", "stdout: %s" % out) + if err: + weechat.prnt("", "stderr: %s" % err) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_process("func:get_status", 5000, "my_process_cb", "") +---- + [[url_transfer]] ==== Trasferimento URL @@ -1129,17 +1157,18 @@ delle opzioni per il trasferimento dell'URL. Esempio di trasferimento di un URL senza opzioni: la pagina HTML verrà ricevuta come "out" nella callback (output standard di un processo): +// TRANSLATION MISSING [source,python] ---- -# Mostra la versione stabile corrente di WeeChat. -weechat_version = "" +# Display latest stable version of WeeChat. +weechat_latest_version = "" -def weechat_process_cb(data, command, rc, out, err): - global weechat_version - if out != "": - weechat_version += out - if int(rc) >= 0: - weechat.prnt("", "Current WeeChat stable is: %s" % weechat_version) +def weechat_process_cb(data, command, return_code, out, err): + global weechat_latest_version + if out: + weechat_latest_version += out + if return_code >= 0: + weechat.prnt("", "Latest WeeChat version: %s" % weechat_latest_version) return weechat.WEECHAT_RC_OK weechat.hook_process("url:https://weechat.org/dev/info/stable/", @@ -1155,9 +1184,9 @@ di sviluppo di WeeChat nel file _/tmp/weechat-devel.tar.gz_: [source,python] ---- -def my_process_cb(data, command, rc, out, err): - if int(rc) >= 0: - weechat.prnt("", "End of transfer (rc=%s)" % rc) +def my_process_cb(data, command, return_code, out, err): + if return_code >= 0: + weechat.prnt("", "End of transfer (return code = %d)" % return_code) return weechat.WEECHAT_RC_OK weechat.hook_process_hashtable("url:https://weechat.org/files/src/weechat-devel.tar.gz", |