doc: add example of callback in each language (scripting guide)
This commit is contained in:
parent
3d9886f82e
commit
95bcc49063
@ -274,16 +274,79 @@ C Callbacks nutzen ein "Data" Argument welches ein Pointer ist. In der
|
||||
Skript API ist "Data" ein String der jeden Wert haben darf (es handelt sich
|
||||
nicht um einen Pointer).
|
||||
|
||||
Beispiel:
|
||||
// TRANSLATION MISSING
|
||||
Example of callback, for each language:
|
||||
|
||||
* python:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
weechat.hook_timer(1000, 0, 1, "mein_timer_cb", "mein data")
|
||||
|
||||
def mein_timer_cb(data, verbleibende_aufrufe):
|
||||
# es wird "mein data" angezeigt
|
||||
weechat.prnt("", data)
|
||||
def timer_cb(data, remaining_calls):
|
||||
weechat.prnt("", "timer! data=%s" % data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* perl:
|
||||
|
||||
[source,perl]
|
||||
----------------------------------------
|
||||
sub timer_cb {
|
||||
my ($data, $remaining_calls) = @_;
|
||||
weechat::print("", "timer! data=$data");
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* ruby:
|
||||
|
||||
[source,ruby]
|
||||
----------------------------------------
|
||||
def timer_cb(data, remaining_calls)
|
||||
Weechat.print("", "timer! data=#{data}");
|
||||
return Weechat::WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* lua:
|
||||
|
||||
[source,lua]
|
||||
----------------------------------------
|
||||
function timer_cb(data, remaining_calls)
|
||||
weechat.print("", "timer! data="..data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* tcl:
|
||||
|
||||
[source,tcl]
|
||||
----------------------------------------
|
||||
proc timer_cb { data remaining_calls } {
|
||||
weechat::print {} "timer! data=$data"
|
||||
return $::weechat::WEECHAT_RC_OK
|
||||
}
|
||||
|
||||
weechat::hook_timer 1000 0 1 timer_cb test
|
||||
----------------------------------------
|
||||
|
||||
* guile (scheme):
|
||||
|
||||
[source,lisp]
|
||||
----------------------------------------
|
||||
(define (timer_cb args)
|
||||
(weechat:print "" (string-append "timer! data=" (list-ref args 0)))
|
||||
weechat:WEECHAT_RC_OK
|
||||
)
|
||||
|
||||
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
||||
----------------------------------------
|
||||
|
||||
[[script_api]]
|
||||
|
@ -266,16 +266,78 @@ Almost all WeeChat callbacks must return WEECHAT_RC_OK or WEECHAT_RC_ERROR
|
||||
C callbacks are using a "data" argument, which is a pointer. In script API,
|
||||
this "data" is a string with a any value (it's not a pointer).
|
||||
|
||||
For example:
|
||||
Example of callback, for each language:
|
||||
|
||||
* python:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
weechat.hook_timer(1000, 0, 1, "my_timer_cb", "my data")
|
||||
|
||||
def my_timer_cb(data, remaining_calls):
|
||||
# this will display: "my data"
|
||||
weechat.prnt("", data)
|
||||
def timer_cb(data, remaining_calls):
|
||||
weechat.prnt("", "timer! data=%s" % data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* perl:
|
||||
|
||||
[source,perl]
|
||||
----------------------------------------
|
||||
sub timer_cb {
|
||||
my ($data, $remaining_calls) = @_;
|
||||
weechat::print("", "timer! data=$data");
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* ruby:
|
||||
|
||||
[source,ruby]
|
||||
----------------------------------------
|
||||
def timer_cb(data, remaining_calls)
|
||||
Weechat.print("", "timer! data=#{data}");
|
||||
return Weechat::WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* lua:
|
||||
|
||||
[source,lua]
|
||||
----------------------------------------
|
||||
function timer_cb(data, remaining_calls)
|
||||
weechat.print("", "timer! data="..data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* tcl:
|
||||
|
||||
[source,tcl]
|
||||
----------------------------------------
|
||||
proc timer_cb { data remaining_calls } {
|
||||
weechat::print {} "timer! data=$data"
|
||||
return $::weechat::WEECHAT_RC_OK
|
||||
}
|
||||
|
||||
weechat::hook_timer 1000 0 1 timer_cb test
|
||||
----------------------------------------
|
||||
|
||||
* guile (scheme):
|
||||
|
||||
[source,lisp]
|
||||
----------------------------------------
|
||||
(define (timer_cb args)
|
||||
(weechat:print "" (string-append "timer! data=" (list-ref args 0)))
|
||||
weechat:WEECHAT_RC_OK
|
||||
)
|
||||
|
||||
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
||||
----------------------------------------
|
||||
|
||||
[[script_api]]
|
||||
|
@ -165,7 +165,7 @@ weechat::print "" "Bonjour, du script tcl !"
|
||||
Chargement du script
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Il est recommandé d'utiliser le plugin "script" pour charger les scripts,
|
||||
Il est recommandé d'utiliser l'extension "script" pour charger les scripts,
|
||||
par exemple :
|
||||
|
||||
----------------------------------------
|
||||
@ -275,16 +275,78 @@ Les "callbacks" C utilisent un paramètre "data", qui est un pointeur. Dans
|
||||
l'API script, ce "data" est une chaîne de caractères avec n'importe quelle
|
||||
valeur (ce n'est pas un pointeur).
|
||||
|
||||
Par exemple :
|
||||
Exemple de callback, pour chaque langage :
|
||||
|
||||
* python:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
weechat.hook_timer(1000, 0, 1, "mon_timer_cb", "mes données")
|
||||
|
||||
def mon_timer_cb(data, remaining_calls):
|
||||
# cela affichera : "mes données"
|
||||
weechat.prnt("", data)
|
||||
def timer_cb(data, remaining_calls):
|
||||
weechat.prnt("", "timer! data=%s" % data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* perl:
|
||||
|
||||
[source,perl]
|
||||
----------------------------------------
|
||||
sub timer_cb {
|
||||
my ($data, $remaining_calls) = @_;
|
||||
weechat::print("", "timer! data=$data");
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* ruby:
|
||||
|
||||
[source,ruby]
|
||||
----------------------------------------
|
||||
def timer_cb(data, remaining_calls)
|
||||
Weechat.print("", "timer! data=#{data}");
|
||||
return Weechat::WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* lua:
|
||||
|
||||
[source,lua]
|
||||
----------------------------------------
|
||||
function timer_cb(data, remaining_calls)
|
||||
weechat.print("", "timer! data="..data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* tcl:
|
||||
|
||||
[source,tcl]
|
||||
----------------------------------------
|
||||
proc timer_cb { data remaining_calls } {
|
||||
weechat::print {} "timer! data=$data"
|
||||
return $::weechat::WEECHAT_RC_OK
|
||||
}
|
||||
|
||||
weechat::hook_timer 1000 0 1 timer_cb test
|
||||
----------------------------------------
|
||||
|
||||
* guile (scheme):
|
||||
|
||||
[source,lisp]
|
||||
----------------------------------------
|
||||
(define (timer_cb args)
|
||||
(weechat:print "" (string-append "timer! data=" (list-ref args 0)))
|
||||
weechat:WEECHAT_RC_OK
|
||||
)
|
||||
|
||||
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
||||
----------------------------------------
|
||||
|
||||
[[script_api]]
|
||||
|
@ -277,16 +277,79 @@ Le callback in C utilizzano un argomento "data", che è un puntatore.
|
||||
Nelle API per gli script, questo "data" è una stringa con un qualsiasi
|
||||
valore (non è un puntatore).
|
||||
|
||||
Ad esempio:
|
||||
// TRANSLATION MISSING
|
||||
Example of callback, for each language:
|
||||
|
||||
* python:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
weechat.hook_timer(1000, 0, 1, "my_timer_cb", "my data")
|
||||
|
||||
def my_timer_cb(data, remaining_calls):
|
||||
# this will display: "my data"
|
||||
weechat.prnt("", data)
|
||||
def timer_cb(data, remaining_calls):
|
||||
weechat.prnt("", "timer! data=%s" % data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* perl:
|
||||
|
||||
[source,perl]
|
||||
----------------------------------------
|
||||
sub timer_cb {
|
||||
my ($data, $remaining_calls) = @_;
|
||||
weechat::print("", "timer! data=$data");
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* ruby:
|
||||
|
||||
[source,ruby]
|
||||
----------------------------------------
|
||||
def timer_cb(data, remaining_calls)
|
||||
Weechat.print("", "timer! data=#{data}");
|
||||
return Weechat::WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* lua:
|
||||
|
||||
[source,lua]
|
||||
----------------------------------------
|
||||
function timer_cb(data, remaining_calls)
|
||||
weechat.print("", "timer! data="..data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* tcl:
|
||||
|
||||
[source,tcl]
|
||||
----------------------------------------
|
||||
proc timer_cb { data remaining_calls } {
|
||||
weechat::print {} "timer! data=$data"
|
||||
return $::weechat::WEECHAT_RC_OK
|
||||
}
|
||||
|
||||
weechat::hook_timer 1000 0 1 timer_cb test
|
||||
----------------------------------------
|
||||
|
||||
* guile (scheme):
|
||||
|
||||
[source,lisp]
|
||||
----------------------------------------
|
||||
(define (timer_cb args)
|
||||
(weechat:print "" (string-append "timer! data=" (list-ref args 0)))
|
||||
weechat:WEECHAT_RC_OK
|
||||
)
|
||||
|
||||
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
||||
----------------------------------------
|
||||
|
||||
[[script_api]]
|
||||
|
@ -255,16 +255,79 @@ weechat.prnt("", "hi!")
|
||||
C コールバックはポインタ型の "data" 引数を利用します。スクリプト API
|
||||
では、"data" は文字列型で任意の値を取れます (ポインタ型ではありません)。
|
||||
|
||||
例:
|
||||
// TRANSLATION MISSING
|
||||
Example of callback, for each language:
|
||||
|
||||
* python:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
weechat.hook_timer(1000, 0, 1, "my_timer_cb", "my data")
|
||||
|
||||
def my_timer_cb(data, remaining_calls):
|
||||
# "my data" と表示
|
||||
weechat.prnt("", data)
|
||||
def timer_cb(data, remaining_calls):
|
||||
weechat.prnt("", "timer! data=%s" % data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* perl:
|
||||
|
||||
[source,perl]
|
||||
----------------------------------------
|
||||
sub timer_cb {
|
||||
my ($data, $remaining_calls) = @_;
|
||||
weechat::print("", "timer! data=$data");
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* ruby:
|
||||
|
||||
[source,ruby]
|
||||
----------------------------------------
|
||||
def timer_cb(data, remaining_calls)
|
||||
Weechat.print("", "timer! data=#{data}");
|
||||
return Weechat::WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* lua:
|
||||
|
||||
[source,lua]
|
||||
----------------------------------------
|
||||
function timer_cb(data, remaining_calls)
|
||||
weechat.print("", "timer! data="..data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* tcl:
|
||||
|
||||
[source,tcl]
|
||||
----------------------------------------
|
||||
proc timer_cb { data remaining_calls } {
|
||||
weechat::print {} "timer! data=$data"
|
||||
return $::weechat::WEECHAT_RC_OK
|
||||
}
|
||||
|
||||
weechat::hook_timer 1000 0 1 timer_cb test
|
||||
----------------------------------------
|
||||
|
||||
* guile (scheme):
|
||||
|
||||
[source,lisp]
|
||||
----------------------------------------
|
||||
(define (timer_cb args)
|
||||
(weechat:print "" (string-append "timer! data=" (list-ref args 0)))
|
||||
weechat:WEECHAT_RC_OK
|
||||
)
|
||||
|
||||
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
||||
----------------------------------------
|
||||
|
||||
[[script_api]]
|
||||
|
@ -268,16 +268,79 @@ Prawie wszystkie callbacki muszą zwrócić WEECHAT_RC_OK lub WEECHAT_RC_ERROR
|
||||
Callbacki C używają argumentu "data", który jest wskaźnikiem. W API skryptów,
|
||||
"data" jest ciągiem o dowolnej wartości (nie jest wskaźnikiem).
|
||||
|
||||
Na przykład:
|
||||
// TRANSLATION MISSING
|
||||
Example of callback, for each language:
|
||||
|
||||
* python:
|
||||
|
||||
[source,python]
|
||||
----------------------------------------
|
||||
weechat.hook_timer(1000, 0, 1, "my_timer_cb", "moje dane")
|
||||
|
||||
def my_timer_cb(data, remaining_calls):
|
||||
# wyświetli to: "moje dane"
|
||||
weechat.prnt("", data)
|
||||
def timer_cb(data, remaining_calls):
|
||||
weechat.prnt("", "timer! data=%s" % data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* perl:
|
||||
|
||||
[source,perl]
|
||||
----------------------------------------
|
||||
sub timer_cb {
|
||||
my ($data, $remaining_calls) = @_;
|
||||
weechat::print("", "timer! data=$data");
|
||||
return weechat::WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
weechat::hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* ruby:
|
||||
|
||||
[source,ruby]
|
||||
----------------------------------------
|
||||
def timer_cb(data, remaining_calls)
|
||||
Weechat.print("", "timer! data=#{data}");
|
||||
return Weechat::WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
Weechat.hook_timer(1000, 0, 1, "timer_cb", "test");
|
||||
----------------------------------------
|
||||
|
||||
* lua:
|
||||
|
||||
[source,lua]
|
||||
----------------------------------------
|
||||
function timer_cb(data, remaining_calls)
|
||||
weechat.print("", "timer! data="..data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
end
|
||||
|
||||
weechat.hook_timer(1000, 0, 1, "timer_cb", "test")
|
||||
----------------------------------------
|
||||
|
||||
* tcl:
|
||||
|
||||
[source,tcl]
|
||||
----------------------------------------
|
||||
proc timer_cb { data remaining_calls } {
|
||||
weechat::print {} "timer! data=$data"
|
||||
return $::weechat::WEECHAT_RC_OK
|
||||
}
|
||||
|
||||
weechat::hook_timer 1000 0 1 timer_cb test
|
||||
----------------------------------------
|
||||
|
||||
* guile (scheme):
|
||||
|
||||
[source,lisp]
|
||||
----------------------------------------
|
||||
(define (timer_cb args)
|
||||
(weechat:print "" (string-append "timer! data=" (list-ref args 0)))
|
||||
weechat:WEECHAT_RC_OK
|
||||
)
|
||||
|
||||
(weechat:hook_timer 1000 0 1 "timer_cb" "test")
|
||||
----------------------------------------
|
||||
|
||||
[[script_api]]
|
||||
|
Loading…
x
Reference in New Issue
Block a user