0
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-07-26 12:14:28 -04: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 void
api_init(void) api_init(void)
{ {
PyObject *pName, *pModule, *pFunc; PyObject *pName, *pModule, *pProfInit, *pProfOnStart, *pArgs;
Py_Initialize(); Py_Initialize();
Py_InitModule("prof", apiMethods); Py_InitModule("prof", apiMethods);
@ -54,20 +54,20 @@ api_init(void)
Py_DECREF(pName); Py_DECREF(pName);
if (pModule != NULL) { if (pModule != NULL) {
pProfInit = PyObject_GetAttrString(pModule, "prof_init");
pFunc = PyObject_GetAttrString(pModule, "prof_on_start"); if (pProfInit && PyCallable_Check(pProfInit)) {
pArgs = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS);
if (pFunc == NULL) { PyObject_CallObject(pProfInit, pArgs);
cons_show("NULL pfunc"); // Py_XDECREF(pArgs);
} }
Py_XDECREF(pProfInit);
if (pFunc && PyCallable_Check(pFunc)) { pProfOnStart = PyObject_GetAttrString(pModule, "prof_on_start");
PyObject_CallObject(pFunc, NULL); if (pProfOnStart && PyCallable_Check(pProfOnStart)) {
PyObject_CallObject(pProfOnStart, NULL);
} }
else { Py_XDECREF(pProfOnStart);
cons_show("Could not find function");
}
Py_XDECREF(pFunc);
Py_DECREF(pModule); Py_DECREF(pModule);
} }
else { else {