Add script prototypes and examples in plugin API reference

v2.8-utf8proc
Sebastien Helleu 2009-10-09 15:46:29 +02:00
parent 5535ec5f46
commit bfb9ab6a2a
9 changed files with 4538 additions and 693 deletions

View File

@ -13,17 +13,17 @@
| logger | logger_buffer | list of logger buffers
| lua | lua_script | list of lua scripts
| lua | lua_script | liste des scripts lua
| perl | perl_script | list of perl scripts
| perl | perl_script | liste des scripts perl
| python | python_script | list of python scripts
| python | python_script | liste des scripts python
| relay | relay | list of relay clients
| ruby | ruby_script | list of ruby scripts
| ruby | ruby_script | liste des scripts ruby
| tcl | tcl_script | list of tcl scripts
| tcl | tcl_script | liste des scripts tcl
| weechat | bar | list of bars

File diff suppressed because it is too large Load Diff

View File

@ -146,9 +146,9 @@ $ cd ~/.weechat/perl/autoload
$ ln -s ../script.pl
----------------------------------------
[[script_api]]
Script API
----------
[[differences_with_c_api]]
Differences with C API
----------------------
Script API is almost the same as C plugin API.
You can look at 'WeeChat Plugin API Reference' for detail about each function
@ -176,6 +176,60 @@ previous path:
WeeChat core -------> python plugin (python.so) -------> test.py
........................................
Pointers
~~~~~~~~
As you probably know, there is not really "pointers" in scripts. So when API
functions return pointer, it is converted to string for script.
For example, if function return pointer 0x1234ab56, script will get string
"0x1234ab56".
And when an API function expects a pointer in arguments, script must give that
string value. C plugin will convert it to real pointer before calling C API
function.
Empty string or "0x0" are allowed, they means NULL in C.
For example, to print data on core buffer (WeeChat main buffer), you can do:
[source,python]
----------------------------------------
weechat.prnt("", "hi!")
----------------------------------------
[WARNING]
In many functions, for speed reasons, WeeChat does not check if your pointer
is correct or not. It's your job to check you're giving a valid pointer,
otherwise you may see a nice crash report ;)
Callbacks
~~~~~~~~~
Almost all WeeChat callbacks must return WEECHAT_RC_OK or WEECHAT_RC_ERROR
(exception is modifier callback, which returns a string).
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:
[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)
return weechat.WEECHAT_RC_OK
----------------------------------------
[[script_api]]
Script API
----------
For more information about functions in API, please read
'WeeChat Plugin API Reference'.
Functions
~~~~~~~~~
@ -274,18 +328,21 @@ List of functions in script API:
** 'unhook_all'
* buffers:
** 'buffer_new'
** 'buffer_search'
** 'current_buffer'
** 'buffer_search'
** 'buffer_search_main'
** 'buffer_clear'
** 'buffer_close'
** 'buffer_merge'
** 'buffer_unmerge'
** 'buffer_get_integer'
** 'buffer_get_string'
** 'buffer_get_pointer'
** 'buffer_set'
** 'buffer_string_replace_local_var'
* windows:
** 'current_window'
** 'window_get_integer'
** 'window_get_string'
** 'window_get_pointer'
** 'window_set_title'
* nicklist:
@ -312,6 +369,7 @@ List of functions in script API:
** 'info_get'
* infolists:
** 'infolist_new'
** 'infolist_new_item'
** 'infolist_new_var_integer'
** 'infolist_new_var_string'
** 'infolist_new_var_pointer'
@ -319,6 +377,7 @@ List of functions in script API:
** 'infolist_get'
** 'infolist_next'
** 'infolist_prev'
** 'infolist_reset_item_cursor'
** 'infolist_fields'
** 'infolist_integer'
** 'infolist_string'
@ -374,53 +433,3 @@ List of constants in script API:
* 'WEECHAT_HOOK_SIGNAL_STRING'
* 'WEECHAT_HOOK_SIGNAL_INT'
* 'WEECHAT_HOOK_SIGNAL_POINTER'
Differences with C API
~~~~~~~~~~~~~~~~~~~~~~
Pointers
^^^^^^^^
As you probably know, there is not really "pointers" in scripts. So when API
functions return pointer, it is converted to string for script.
For example, if function return pointer 0x1234ab56, script will get string
"0x1234ab56".
And when an API function expects a pointer in arguments, script must give that
string value. C plugin will convert it to real pointer before calling C API
function.
Empty string or "0x0" are allowed, they means NULL in C.
For example, to print data on core buffer (WeeChat main buffer), you can do:
[source,python]
----------------------------------------
weechat.prnt("", "hi!")
----------------------------------------
[WARNING]
In many functions, for speed reasons, WeeChat does not check if your pointer
is correct or not. It's your job to check you're giving a valid pointer,
otherwise you may see a nice crash report ;)
Callbacks
^^^^^^^^^
Almost all WeeChat callbacks must return WEECHAT_RC_OK or WEECHAT_RC_ERROR
(exception is modifier callback, which returns a string).
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:
[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)
return weechat.WEECHAT_RC_OK
----------------------------------------

View File

@ -13,17 +13,17 @@
| logger | logger_buffer | liste des enregistreurs de tampons (loggers)
| lua | lua_script | list of lua scripts
| lua | lua_script | liste des scripts lua
| perl | perl_script | list of perl scripts
| perl | perl_script | liste des scripts perl
| python | python_script | list of python scripts
| python | python_script | liste des scripts python
| relay | relay | liste des clients pour le relai
| ruby | ruby_script | list of ruby scripts
| ruby | ruby_script | liste des scripts ruby
| tcl | tcl_script | list of tcl scripts
| tcl | tcl_script | liste des scripts tcl
| weechat | bar | liste des barres

View File

@ -33,8 +33,8 @@
| weechat | weechat_sharedir | répertoire "share" de WeeChat
| weechat | weechat_site | Site WeeChat
| weechat | weechat_site | site WeeChat
| weechat | weechat_site_download | Site WeeChat, page de téléchargement
| weechat | weechat_site_download | site WeeChat, page de téléchargement
|========================================

File diff suppressed because it is too large Load Diff

View File

@ -149,9 +149,9 @@ $ cd ~/.weechat/perl/autoload
$ ln -s ../script.pl
----------------------------------------
[[script_api]]
API script
----------
[[differences_with_c_api]]
Différences avec l'API C
------------------------
L'API script est quasiment identique à l'API C.
Vous pouvez consulter la 'Référence API Extension WeeChat' pour le détail de
@ -180,6 +180,65 @@ est inversé :
WeeChat core -------> extension plugin (python.so) -------> test.py
........................................
Pointeurs
~~~~~~~~~
Comme vous le savez probablement, il n'y a pas vraiment de "pointeurs" dans les
scripts. Donc quand les fonctions de l'API retournent un pointeur, il est
converti en chaîne pour le script.
Par exemple, si une fonction retourne le pointeur 0x1234ab56, le script recevra
la chaîne "0x1234ab56".
Et quand une fonction de l'API attend un pointeur dans ses paramètres, le
script doit envoyer cette valeur sous forme de chaîne. L'extension C la
convertira en pointeur réel avant d'appeler la fonction de l'API C.
Une chaîne vide ou "0x0" sont autorisées, cela signifie le pointeur NULL en C.
Par exemple, pour afficher un message sur le tampon core (tampon principal
WeeChat), vous pouvez faire :
[source,python]
----------------------------------------
weechat.prnt("", "bonjour !")
----------------------------------------
[WARNING]
Dans beaucoup de fonctions, pour des raisons de vitesse, WeeChat ne vérifie pas
si votre pointeur est correct ou pas. Il est de votre responsabilité de
vérifier que vous donnez un pointeur valide, sinon vous pourriez voir un joli
rapport de crash ;)
Callbacks
~~~~~~~~~
Tous les "callbacks" WeeChat doivent retourner WEECHAT_RC_OK ou
WEECHAT_RC_ERROR (l'exception est le callback du "modifier", qui retourne une
chaîne de caractères).
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 :
[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)
return weechat.WEECHAT_RC_OK
----------------------------------------
[[script_api]]
API script
----------
Pour plus d'informations sur les fonctions de l'API, merci de consulter la
'Référence API Extension WeeChat'.
Fonctions
~~~~~~~~~
@ -278,18 +337,21 @@ Liste des fonctions de l'API script :
** 'unhook_all'
* tampons :
** 'buffer_new'
** 'buffer_search'
** 'current_buffer'
** 'buffer_search'
** 'buffer_search_main'
** 'buffer_clear'
** 'buffer_close'
** 'buffer_merge'
** 'buffer_unmerge'
** 'buffer_get_integer'
** 'buffer_get_string'
** 'buffer_get_pointer'
** 'buffer_set'
** 'buffer_string_replace_local_var'
* fenêtres :
** 'current_window'
** 'window_get_integer'
** 'window_get_string'
** 'window_get_pointer'
** 'window_set_title'
* liste des pseudos :
@ -316,6 +378,7 @@ Liste des fonctions de l'API script :
** 'info_get'
* infolists :
** 'infolist_new'
** 'infolist_new_item'
** 'infolist_new_var_integer'
** 'infolist_new_var_string'
** 'infolist_new_var_pointer'
@ -323,6 +386,7 @@ Liste des fonctions de l'API script :
** 'infolist_get'
** 'infolist_next'
** 'infolist_prev'
** 'infolist_reset_item_cursor'
** 'infolist_fields'
** 'infolist_integer'
** 'infolist_string'
@ -378,58 +442,3 @@ Liste des constantes de l'API script :
* 'WEECHAT_HOOK_SIGNAL_STRING'
* 'WEECHAT_HOOK_SIGNAL_INT'
* 'WEECHAT_HOOK_SIGNAL_POINTER'
Différences avec l'API C
~~~~~~~~~~~~~~~~~~~~~~~~
Pointeurs
^^^^^^^^^
Comme vous le savez probablement, il n'y a pas vraiment de "pointeurs" dans les
scripts. Donc quand les fonctions de l'API retournent un pointeur, il est
converti en chaîne pour le script.
Par exemple, si une fonction retourne le pointeur 0x1234ab56, le script recevra
la chaîne "0x1234ab56".
Et quand une fonction de l'API attend un pointeur dans ses paramètres, le
script doit envoyer cette valeur sous forme de chaîne. L'extension C la
convertira en pointeur réel avant d'appeler la fonction de l'API C.
Une chaîne vide ou "0x0" sont autorisées, cela signifie le pointeur NULL en C.
Par exemple, pour afficher un message sur le tampon core (tampon principal
WeeChat), vous pouvez faire :
[source,python]
----------------------------------------
weechat.prnt("", "bonjour !")
----------------------------------------
[WARNING]
Dans beaucoup de fonctions, pour des raisons de vitesse, WeeChat ne vérifie pas
si votre pointeur est correct ou pas. Il est de votre responsabilité de
vérifier que vous donnez un pointeur valide, sinon vous pourriez voir un joli
rapport de crash ;)
Callbacks
^^^^^^^^^
Tous les "callbacks" WeeChat doivent retourner WEECHAT_RC_OK ou
WEECHAT_RC_ERROR (l'exception est le callback du "modifier", qui retourne une
chaîne de caractères).
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 :
[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)
return weechat.WEECHAT_RC_OK
----------------------------------------

View File

@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: WeeChat 0.3.1-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2009-10-03 12:06+0200\n"
"PO-Revision-Date: 2009-10-03 12:09+0200\n"
"PO-Revision-Date: 2009-10-09 11:12+0200\n"
"Last-Translator: FlashCode <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"MIME-Version: 1.0\n"
@ -4868,10 +4868,10 @@ msgid "WeeChat \"locale\" directory"
msgstr "répertoire \"locale\" de WeeChat"
msgid "WeeChat site"
msgstr "Site WeeChat"
msgstr "site WeeChat"
msgid "WeeChat site, download page"
msgstr "Site WeeChat, page de téléchargement"
msgstr "site WeeChat, page de téléchargement"
msgid "terminal charset"
msgstr "charset du terminal"

View File

@ -279,7 +279,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
callback_completion, NULL);
snprintf (infolist_description, sizeof (infolist_description),
/* TRANSLATORS: %s is language (for example "perl") */
N_("list of %s scripts"), weechat_plugin->name);
_("list of %s scripts"), weechat_plugin->name);
weechat_hook_infolist (string, infolist_description,
callback_infolist, NULL);
free (string);