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

77 lines
1.8 KiB
C
Raw Normal View History

/*
* 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)
{
cons_show("Printed to console!");
return NULL;
}
static PyMethodDef apiMethods[] = {
{ "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." },
{ NULL, NULL, 0, NULL }
};
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");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (pModule != NULL) {
2013-07-22 19:40:03 -04:00
2013-07-24 19:54:31 -04:00
pFunc = PyObject_GetAttrString(pModule, "helloworld");
if (pFunc == NULL) {
cons_show("NULL pfunc");
}
if (pFunc && PyCallable_Check(pFunc)) {
2013-07-24 19:54:31 -04:00
PyObject_CallObject(pFunc, NULL);
}
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;
}