diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2005-10-28 07:31:21 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2005-10-28 07:31:21 +0000 |
commit | e26772dcdb42b1cd36c52b055d669210160ce1a0 (patch) | |
tree | 567c1de16434fb3bb5677d4a29f4664e522d4de4 /src/plugins/scripts/python | |
parent | 232b5684cad3ccfe03ccfbe3697fb347d5da44c9 (diff) | |
download | weechat-e26772dcdb42b1cd36c52b055d669210160ce1a0.zip |
Added new return codes for plugin handlers, to discard messages for WeeChat, plugins, or both.
Diffstat (limited to 'src/plugins/scripts/python')
-rw-r--r-- | src/plugins/scripts/python/weechat-python.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index dec287550..cd947cd5a 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -52,31 +52,41 @@ weechat_python_exec (t_weechat_plugin *plugin, PyObject *evMain; PyObject *evDict; PyObject *evFunc; - + PyObject *rc; + int ret; + PyThreadState_Swap (NULL); - + PyEval_AcquireLock (); - + PyThreadState_Swap (script->interpreter); - + evMain = PyImport_AddModule ((char *) "__main__"); evDict = PyModule_GetDict (evMain); evFunc = PyDict_GetItemString (evDict, function); - + if ( !(evFunc && PyCallable_Check (evFunc)) ) { plugin->printf_server (plugin, "Python error: unable to run function \"%s\"", function); PyEval_ReleaseLock(); - return 1; + return PLUGIN_RC_KO; + } + + ret = -1; + rc = PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments); + if (rc) + { + ret = (int) PyInt_AsLong(rc); + Py_XDECREF(rc); } - - PyObject_CallFunction(evFunc, "ss", server == NULL ? "" : server, arguments == NULL ? "" : arguments); - PyEval_ReleaseLock(); - - return 0; + + if (ret < 0) + return PLUGIN_RC_OK; + else + return ret; } /* @@ -91,9 +101,8 @@ weechat_python_handler (t_weechat_plugin *plugin, /* make gcc happy */ (void) command; - weechat_python_exec (plugin, (t_plugin_script *)handler_pointer, - handler_args, server, arguments); - return 1; + return weechat_python_exec (plugin, (t_plugin_script *)handler_pointer, + handler_args, server, arguments); } /* @@ -1104,7 +1113,7 @@ weechat_plugin_init (t_weechat_plugin *plugin) { plugin->printf_server (plugin, "Python error: unable to launch global interpreter"); - return 0; + return PLUGIN_RC_KO; } PySys_SetArgv(1, argv); @@ -1117,7 +1126,7 @@ weechat_plugin_init (t_weechat_plugin *plugin) { plugin->printf_server (plugin, "Python error: unable to get current interpreter state"); - return 0; + return PLUGIN_RC_KO; } PyEval_ReleaseLock (); @@ -1134,7 +1143,8 @@ weechat_plugin_init (t_weechat_plugin *plugin) weechat_script_auto_load (plugin, "python", weechat_python_load); - return 1; + /* init ok */ + return PLUGIN_RC_OK; } /* |