mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Basic ruby api functions
This commit is contained in:
parent
fd3419b8af
commit
d5818f49db
@ -29,100 +29,82 @@
|
||||
#include "plugins/ruby_api.h"
|
||||
#include "plugins/callbacks.h"
|
||||
|
||||
static PyObject*
|
||||
ruby_api_cons_alert(PyObject *self, PyObject *args)
|
||||
static VALUE
|
||||
ruby_api_cons_alert(VALUE self)
|
||||
{
|
||||
api_cons_alert();
|
||||
return Py_BuildValue("");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
ruby_api_cons_show(VALUE self, const char * const message)
|
||||
ruby_api_cons_show(VALUE self, VALUE v_message)
|
||||
{
|
||||
char *message = STR2CSTR(v_message);
|
||||
|
||||
if (message != NULL) {
|
||||
api_cons_show(message);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
ruby_api_register_command(PyObject *self, PyObject *args)
|
||||
static VALUE
|
||||
ruby_api_register_command(VALUE self, VALUE v_command_name, VALUE v_min_args,
|
||||
VALUE v_max_args, VALUE v_usage, VALUE v_short_help, VALUE v_long_help,
|
||||
VALUE v_callback)
|
||||
{
|
||||
const char *command_name = NULL;
|
||||
int min_args = 0;
|
||||
int max_args = 0;
|
||||
const char *usage = NULL;
|
||||
const char *short_help = NULL;
|
||||
const char *long_help = NULL;
|
||||
PyObject *p_callback = NULL;
|
||||
const char *command_name = STR2CSTR(v_command_name);
|
||||
int min_args = NUM2INT(v_min_args);
|
||||
int max_args = NUM2INT(v_max_args);
|
||||
const char *usage = STR2CSTR(v_usage);
|
||||
const char *short_help = STR2CSTR(v_short_help);
|
||||
const char *long_help = STR2CSTR(v_long_help);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "siisssO", &command_name, &min_args, &max_args,
|
||||
&usage, &short_help, &long_help, &p_callback)) {
|
||||
return NULL;
|
||||
}
|
||||
api_register_command(command_name, min_args, max_args, usage,
|
||||
short_help, long_help, (void *)v_callback, ruby_command_callback);
|
||||
|
||||
if (p_callback && PyCallable_Check(p_callback)) {
|
||||
api_register_command(command_name, min_args, max_args, usage,
|
||||
short_help, long_help, p_callback, ruby_command_callback);
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ruby_api_register_timed(PyObject *self, PyObject *args)
|
||||
static VALUE
|
||||
ruby_api_register_timed(VALUE self, VALUE v_callback, VALUE v_interval_seconds)
|
||||
{
|
||||
PyObject *p_callback = NULL;
|
||||
int interval_seconds = 0;
|
||||
int interval_seconds = NUM2INT(v_interval_seconds);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "Oi", &p_callback, &interval_seconds)) {
|
||||
return NULL;
|
||||
}
|
||||
api_register_timed((void*)v_callback, interval_seconds, ruby_timed_callback);
|
||||
|
||||
if (p_callback && PyCallable_Check(p_callback)) {
|
||||
api_register_timed(p_callback, interval_seconds, ruby_timed_callback);
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
ruby_api_notify(PyObject *self, PyObject *args)
|
||||
static VALUE
|
||||
ruby_api_notify(VALUE self, VALUE v_message, VALUE v_timeout_ms, VALUE v_category)
|
||||
{
|
||||
const char *message = NULL;
|
||||
const char *category = NULL;
|
||||
int timeout_ms = 5000;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sis", &message, &timeout_ms, &category)) {
|
||||
return NULL;
|
||||
}
|
||||
const char *message = STR2CSTR(v_message);
|
||||
const char *category = STR2CSTR(v_category);
|
||||
int timeout_ms = NUM2INT(v_timeout_ms);
|
||||
|
||||
api_notify(message, category, timeout_ms);
|
||||
|
||||
return Py_BuildValue("");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
ruby_api_send_line(PyObject *self, PyObject *args)
|
||||
static VALUE
|
||||
ruby_api_send_line(VALUE self, VALUE v_line)
|
||||
{
|
||||
char *line = NULL;
|
||||
if (!PyArg_ParseTuple(args, "s", &line)) {
|
||||
return NULL;
|
||||
}
|
||||
char *line = STR2CSTR(v_line);
|
||||
|
||||
api_send_line(line);
|
||||
|
||||
return Py_BuildValue("");
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
ruby_api_get_current_recipient(PyObject *self, PyObject *args)
|
||||
static VALUE
|
||||
ruby_api_get_current_recipient(VALUE self)
|
||||
{
|
||||
char *recipient = api_get_current_recipient();
|
||||
if (recipient != NULL) {
|
||||
return Py_BuildValue("s", recipient);
|
||||
return rb_str_new2(recipient);
|
||||
} else {
|
||||
return Py_BuildValue("");
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,5 +161,11 @@ void
|
||||
ruby_api_init(void)
|
||||
{
|
||||
prof_module = rb_define_module("prof");
|
||||
rb_define_module_function(prof_module, "cons_alert", RUBY_METHOD_FUNC(ruby_api_cons_alert), 0);
|
||||
rb_define_module_function(prof_module, "cons_show", RUBY_METHOD_FUNC(ruby_api_cons_show), 1);
|
||||
rb_define_module_function(prof_module, "register_command", RUBY_METHOD_FUNC(ruby_api_register_command), 7);
|
||||
rb_define_module_function(prof_module, "register_timed", RUBY_METHOD_FUNC(ruby_api_register_timed), 2);
|
||||
rb_define_module_function(prof_module, "send_line", RUBY_METHOD_FUNC(ruby_api_send_line), 1);
|
||||
rb_define_module_function(prof_module, "notify", RUBY_METHOD_FUNC(ruby_api_notify), 3);
|
||||
rb_define_module_function(prof_module, "get_current_recipient", RUBY_METHOD_FUNC(ruby_api_get_current_recipient), 0);
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ ruby_env_init(void)
|
||||
ruby_check_error();
|
||||
ruby_api_init();
|
||||
ruby_check_error();
|
||||
// TODO change to use XDG spec
|
||||
GString *path = g_string_new(Py_GetPath());
|
||||
g_string_append(path, ":./plugins/");
|
||||
PySys_SetPath(path->str);
|
||||
ruby_check_error();
|
||||
g_string_free(path, TRUE);
|
||||
// TODO set loadpath for ruby interpreter
|
||||
//GString *path = g_string_new(Py_GetPath());
|
||||
//g_string_append(path, ":./plugins/");
|
||||
//PySys_SetPath(path->str);
|
||||
//ruby_check_error();
|
||||
//g_string_free(path, TRUE);
|
||||
}
|
||||
|
||||
ProfPlugin *
|
||||
@ -72,6 +72,7 @@ ruby_plugin_create(const char * const filename)
|
||||
void
|
||||
ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * const status)
|
||||
{
|
||||
/* TODO
|
||||
PyObject *p_args = Py_BuildValue("ss", version, status);
|
||||
PyObject *p_function;
|
||||
|
||||
@ -85,11 +86,13 @@ ruby_init_hook(ProfPlugin *plugin, const char * const version, const char * cons
|
||||
Py_XDECREF(p_function);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ruby_on_start_hook(ProfPlugin *plugin)
|
||||
{
|
||||
/*
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
@ -102,11 +105,13 @@ ruby_on_start_hook(ProfPlugin *plugin)
|
||||
Py_XDECREF(p_function);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ruby_on_connect_hook(ProfPlugin *plugin)
|
||||
{
|
||||
/*
|
||||
PyObject *p_function;
|
||||
|
||||
PyObject *p_module = plugin->module;
|
||||
@ -119,11 +124,13 @@ ruby_on_connect_hook(ProfPlugin *plugin)
|
||||
Py_XDECREF(p_function);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char * const message)
|
||||
{
|
||||
/* TODO
|
||||
PyObject *p_args = Py_BuildValue("ss", jid, message);
|
||||
PyObject *p_function;
|
||||
|
||||
@ -137,19 +144,24 @@ ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const
|
||||
Py_XDECREF(p_function);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ruby_check_error(void)
|
||||
{
|
||||
/* TODO
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
ruby_shutdown(void)
|
||||
{
|
||||
/* TODO
|
||||
Py_Finalize();
|
||||
*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user