mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added python_plugin_create()
This commit is contained in:
parent
580b14ab68
commit
2ac4a183d0
@ -35,7 +35,6 @@ void
|
|||||||
plugins_init(void)
|
plugins_init(void)
|
||||||
{
|
{
|
||||||
plugins = NULL;
|
plugins = NULL;
|
||||||
PyObject *p_module;
|
|
||||||
|
|
||||||
// initialse python and path
|
// initialse python and path
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
@ -57,22 +56,11 @@ plugins_init(void)
|
|||||||
{
|
{
|
||||||
gchar *filename = plugins_load[i];
|
gchar *filename = plugins_load[i];
|
||||||
if (g_str_has_suffix(filename, ".py")) {
|
if (g_str_has_suffix(filename, ".py")) {
|
||||||
gchar *module_name = g_strndup(filename, strlen(filename) - 3);
|
ProfPlugin *plugin = python_plugin_create(filename);
|
||||||
p_module = PyImport_ImportModule(module_name);
|
if (plugin != NULL) {
|
||||||
python_check_error();
|
|
||||||
if (p_module != NULL) {
|
|
||||||
cons_show("Loaded plugin: %s", module_name);
|
|
||||||
ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
|
|
||||||
plugin->name = module_name;
|
|
||||||
plugin->lang = PYTHON;
|
|
||||||
plugin->module = p_module;
|
|
||||||
plugin->init_func = python_init_hook;
|
|
||||||
plugin->on_start_func = python_on_start_hook;
|
|
||||||
plugin->on_connect_func = python_on_connect_hook;
|
|
||||||
plugin->on_message_func = python_on_message_hook;
|
|
||||||
plugins = g_slist_append(plugins, plugin);
|
plugins = g_slist_append(plugins, plugin);
|
||||||
|
cons_show("Loaded plugin: %s", filename);
|
||||||
}
|
}
|
||||||
g_free(module_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,29 @@
|
|||||||
#include "plugins/python_plugins.h"
|
#include "plugins/python_plugins.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
|
ProfPlugin *
|
||||||
|
python_plugin_create(const char * const filename)
|
||||||
|
{
|
||||||
|
gchar *module_name = g_strndup(filename, strlen(filename) - 3);
|
||||||
|
PyObject *p_module = PyImport_ImportModule(module_name);
|
||||||
|
python_check_error();
|
||||||
|
if (p_module != NULL) {
|
||||||
|
ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
|
||||||
|
plugin->name = module_name;
|
||||||
|
plugin->lang = PYTHON;
|
||||||
|
plugin->module = p_module;
|
||||||
|
plugin->init_func = python_init_hook;
|
||||||
|
plugin->on_start_func = python_on_start_hook;
|
||||||
|
plugin->on_connect_func = python_on_connect_hook;
|
||||||
|
plugin->on_message_func = python_on_message_hook;
|
||||||
|
g_free(module_name);
|
||||||
|
return plugin;
|
||||||
|
} else {
|
||||||
|
g_free(module_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status)
|
python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status)
|
||||||
{
|
{
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "plugins/plugins.h"
|
#include "plugins/plugins.h"
|
||||||
|
|
||||||
|
ProfPlugin* python_plugin_create(const char * const filename);
|
||||||
|
|
||||||
void python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);
|
void python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status);
|
||||||
void python_on_start_hook(ProfPlugin *plugin);
|
void python_on_start_hook(ProfPlugin *plugin);
|
||||||
void python_on_connect_hook(ProfPlugin *plugin);
|
void python_on_connect_hook(ProfPlugin *plugin);
|
||||||
|
Loading…
Reference in New Issue
Block a user