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 = NULL;
|
||||
PyObject *p_module;
|
||||
|
||||
// initialse python and path
|
||||
Py_Initialize();
|
||||
@ -57,22 +56,11 @@ plugins_init(void)
|
||||
{
|
||||
gchar *filename = plugins_load[i];
|
||||
if (g_str_has_suffix(filename, ".py")) {
|
||||
gchar *module_name = g_strndup(filename, strlen(filename) - 3);
|
||||
p_module = PyImport_ImportModule(module_name);
|
||||
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;
|
||||
ProfPlugin *plugin = python_plugin_create(filename);
|
||||
if (plugin != NULL) {
|
||||
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 "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
|
||||
python_init_hook(ProfPlugin *plugin, const char * const version, const char * const status)
|
||||
{
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
#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_on_start_hook(ProfPlugin *plugin);
|
||||
void python_on_connect_hook(ProfPlugin *plugin);
|
||||
|
Loading…
Reference in New Issue
Block a user