2013-07-21 18:31:09 -04:00
|
|
|
/*
|
|
|
|
* api.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Profanity is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
#include "ui/ui.h"
|
|
|
|
|
2013-07-24 19:54:31 -04:00
|
|
|
// API
|
|
|
|
|
|
|
|
static PyObject*
|
|
|
|
api_cons_show(PyObject *self, PyObject *args)
|
|
|
|
{
|
2013-07-24 20:13:41 -04:00
|
|
|
const char *message = NULL;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &message)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cons_show("%s", message);
|
2013-07-24 19:54:31 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef apiMethods[] = {
|
|
|
|
{ "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." },
|
|
|
|
{ NULL, NULL, 0, NULL }
|
|
|
|
};
|
|
|
|
|
2013-07-21 18:31:09 -04:00
|
|
|
void
|
|
|
|
api_init(void)
|
|
|
|
{
|
|
|
|
PyObject *pName, *pModule, *pFunc;
|
|
|
|
|
|
|
|
Py_Initialize();
|
2013-07-24 19:54:31 -04:00
|
|
|
Py_InitModule("prof", apiMethods);
|
|
|
|
pName = PyString_FromString("helloworld");
|
2013-07-21 18:31:09 -04:00
|
|
|
pModule = PyImport_Import(pName);
|
|
|
|
Py_DECREF(pName);
|
|
|
|
|
|
|
|
if (pModule != NULL) {
|
2013-07-22 19:40:03 -04:00
|
|
|
|
2013-07-24 20:17:45 -04:00
|
|
|
pFunc = PyObject_GetAttrString(pModule, "prof_on_start");
|
2013-07-21 18:31:09 -04:00
|
|
|
|
|
|
|
if (pFunc == NULL) {
|
|
|
|
cons_show("NULL pfunc");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pFunc && PyCallable_Check(pFunc)) {
|
2013-07-24 19:54:31 -04:00
|
|
|
PyObject_CallObject(pFunc, NULL);
|
2013-07-21 18:31:09 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cons_show("Could not find function");
|
|
|
|
}
|
|
|
|
Py_XDECREF(pFunc);
|
|
|
|
Py_DECREF(pModule);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cons_show("Failed to load plugin");
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
Py_Finalize();
|
2013-07-24 19:54:31 -04:00
|
|
|
return;
|
2013-07-21 18:31:09 -04:00
|
|
|
}
|
|
|
|
|