1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add macro for C plugins register_timed

This commit is contained in:
James Booth 2016-06-23 00:36:26 +01:00
parent c6288d89f9
commit 1e37b755fe
4 changed files with 15 additions and 8 deletions

View File

@ -85,7 +85,7 @@ c_api_register_command(const char *filename, const char *command_name, int min_a
void(*callback)(char **args))
{
char *plugin_name = _c_plugin_name(filename);
log_debug("FILENAME : %s", plugin_name);
log_debug("Register command %s for %s", command_name, plugin_name);
CommandWrapper *wrapper = malloc(sizeof(CommandWrapper));
wrapper->func = callback;
@ -94,8 +94,11 @@ c_api_register_command(const char *filename, const char *command_name, int min_a
}
static void
c_api_register_timed(void(*callback)(void), int interval_seconds)
c_api_register_timed(const char *filename, void(*callback)(void), int interval_seconds)
{
char *plugin_name = _c_plugin_name(filename);
log_debug("Register timed for %s", plugin_name);
TimedWrapper *wrapper = malloc(sizeof(TimedWrapper));
wrapper->func = callback;
api_register_timed(wrapper, interval_seconds, c_timed_callback);
@ -303,7 +306,7 @@ c_api_init(void)
prof_cons_show_themed = c_api_cons_show_themed;
prof_cons_bad_cmd_usage = c_api_cons_bad_cmd_usage;
_prof_register_command = c_api_register_command;
prof_register_timed = c_api_register_timed;
_prof_register_timed = c_api_register_timed;
prof_completer_add = c_api_completer_add;
prof_completer_remove = c_api_completer_remove;
prof_completer_clear = c_api_completer_clear;

View File

@ -46,7 +46,7 @@ void (*_prof_register_command)(const char *filename, const char *command_name, i
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
void(*callback)(char **args)) = NULL;
void (*prof_register_timed)(void(*callback)(void), int interval_seconds) = NULL;
void (*_prof_register_timed)(const char *filename, void(*callback)(void), int interval_seconds) = NULL;
void (*prof_completer_add)(const char *key, char **items) = NULL;
void (*prof_completer_remove)(const char *key, char **items) = NULL;

View File

@ -36,6 +36,7 @@
#define PROF_API_H
#define prof_register_command(command_name, min_args, max_args, synopsis, description, arguments, examples, callback) _prof_register_command(__FILE__, command_name, min_args, max_args, synopsis, description, arguments, examples, callback)
#define prof_register_timed(callback, interval_seconds) _prof_register_timed(__FILE__, callback, interval_seconds)
typedef char* PROF_WIN_TAG;
@ -48,7 +49,7 @@ void (*_prof_register_command)(const char *filename, const char *command_name, i
const char **synopsis, const char *description, const char *arguments[][2], const char **examples,
void(*callback)(char **args));
void (*prof_register_timed)(void(*callback)(void), int interval_seconds);
void (*_prof_register_timed)(const char *filename, void(*callback)(void), int interval_seconds);
void (*prof_completer_add)(const char *key, char **items);
void (*prof_completer_remove)(const char *key, char **items);

View File

@ -119,6 +119,9 @@ python_api_register_command(PyObject *self, PyObject *args)
return Py_BuildValue("");
}
char *plugin_name = _python_plugin_name();
log_debug("Register command %s for %s", command_name, plugin_name);
if (p_callback && PyCallable_Check(p_callback)) {
Py_ssize_t len = PyList_Size(synopsis);
const char *c_synopsis[len == 0 ? 0 : len+1];
@ -161,9 +164,6 @@ python_api_register_command(PyObject *self, PyObject *args)
}
c_examples[len] = NULL;
char *plugin_name = _python_plugin_name();
log_debug("FILENAME : %s", plugin_name);
allow_python_threads();
api_register_command(command_name, min_args, max_args, c_synopsis,
description, c_arguments, c_examples, p_callback, python_command_callback);
@ -176,6 +176,9 @@ python_api_register_command(PyObject *self, PyObject *args)
static PyObject *
python_api_register_timed(PyObject *self, PyObject *args)
{
char *plugin_name = _python_plugin_name();
log_debug("Register timed for %s", plugin_name);
PyObject *p_callback = NULL;
int interval_seconds = 0;