1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Pass data to plugin init function

This commit is contained in:
James Booth 2013-07-30 23:37:46 +01:00
parent 586ea10071
commit 5cb28822eb
4 changed files with 34 additions and 21 deletions

View File

@ -1,7 +0,0 @@
import prof
def prof_on_start():
helloworld()
def helloworld():
prof.cons_show("Hello world!")

22
plugins/helloworld.py Normal file
View File

@ -0,0 +1,22 @@
import prof
package_version = None
package_status = None
# hooks
def prof_init(version, status):
global package_version
global package_status
package_version = version
package_status = status
def prof_on_start():
helloworld()
# local functions
def helloworld():
global package_version
global package_status
prof.cons_show("Hello world! (" + package_version + " - " + package_status + ")")

View File

@ -1,2 +0,0 @@
def plugin_name():
return "plugin james"

View File

@ -45,7 +45,7 @@ static PyMethodDef apiMethods[] = {
void
api_init(void)
{
PyObject *pName, *pModule, *pFunc;
PyObject *pName, *pModule, *pProfInit, *pProfOnStart, *pArgs;
Py_Initialize();
Py_InitModule("prof", apiMethods);
@ -54,20 +54,20 @@ api_init(void)
Py_DECREF(pName);
if (pModule != NULL) {
pFunc = PyObject_GetAttrString(pModule, "prof_on_start");
if (pFunc == NULL) {
cons_show("NULL pfunc");
pProfInit = PyObject_GetAttrString(pModule, "prof_init");
if (pProfInit && PyCallable_Check(pProfInit)) {
pArgs = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS);
PyObject_CallObject(pProfInit, pArgs);
// Py_XDECREF(pArgs);
}
Py_XDECREF(pProfInit);
if (pFunc && PyCallable_Check(pFunc)) {
PyObject_CallObject(pFunc, NULL);
pProfOnStart = PyObject_GetAttrString(pModule, "prof_on_start");
if (pProfOnStart && PyCallable_Check(pProfOnStart)) {
PyObject_CallObject(pProfOnStart, NULL);
}
else {
cons_show("Could not find function");
}
Py_XDECREF(pFunc);
Py_XDECREF(pProfOnStart);
Py_DECREF(pModule);
}
else {