diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-01-26 08:22:04 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-01-26 08:22:04 +0100 |
commit | 95bcc4906313e3c30a3cc89f44f4a71dff9f4cd3 (patch) | |
tree | 5cc571bacefa4d81040d790ef8ce44f47cbbbbc7 /doc/en | |
parent | 3d9886f82eac4b76aca772c42158d7a914d85609 (diff) | |
download | weechat-95bcc4906313e3c30a3cc89f44f4a71dff9f4cd3.zip |
doc: add example of callback in each language (scripting guide)
Diffstat (limited to 'doc/en')
-rw-r--r-- | doc/en/weechat_scripting.en.txt | 72 |
1 files changed, 67 insertions, 5 deletions
diff --git a/doc/en/weechat_scripting.en.txt b/doc/en/weechat_scripting.en.txt index f1d88c0a4..20eaa111a 100644 --- a/doc/en/weechat_scripting.en.txt +++ b/doc/en/weechat_scripting.en.txt @@ -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 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: -def my_timer_cb(data, remaining_calls): - # this will display: "my data" - weechat.prnt("", data) +[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]] |