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

Added ruby callbacks

This commit is contained in:
James Booth 2013-08-18 23:54:56 +01:00
parent 2fd1633a6f
commit 21b823750e
3 changed files with 35 additions and 39 deletions

View File

@ -1,6 +1,8 @@
module RubyTest
def RubyTest.prof_init(version, status)
Prof::cons_show("RubyTest: init, " + version + ", " + status)
Prof::register_command("/ruby", 0, 1, "/ruby", "RubyTest", "RubyTest", cmd_ruby)
Prof::register_timed(timer_test, 5)
end
def RubyTest.prof_on_start()
@ -14,4 +16,22 @@ module RubyTest
def RubyTest.prof_on_message_received(jid, message)
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
end
def RubyTest.cmd_ruby()
return Proc.new {
| msg |
if msg
Prof::cons_show("Ruby command called: " + msg)
else
Prof::cons_show("Ruby command called with no arg")
end
}
end
def RubyTest.timer_test()
return Proc.new {
Prof::cons_show("Ruby timer fired.")
}
end
end

View File

@ -111,48 +111,37 @@ ruby_api_get_current_recipient(VALUE self)
void
ruby_command_callback(PluginCommand *command, gchar **args)
{
PyObject *p_args = NULL;
int num_args = g_strv_length(args);
if (num_args == 0) {
if (command->max_args == 1) {
p_args = Py_BuildValue("(O)", Py_BuildValue(""));
PyObject_CallObject(command->callback, p_args);
Py_XDECREF(p_args);
rb_funcall((VALUE)command->callback, rb_intern("call"), 1, Qnil);
} else {
PyObject_CallObject(command->callback, p_args);
rb_funcall((VALUE)command->callback, rb_intern("call"), 0);
}
} else if (num_args == 1) {
p_args = Py_BuildValue("(s)", args[0]);
PyObject_CallObject(command->callback, p_args);
Py_XDECREF(p_args);
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
rb_str_new2(args[0]));
} else if (num_args == 2) {
p_args = Py_BuildValue("ss", args[0], args[1]);
PyObject_CallObject(command->callback, p_args);
Py_XDECREF(p_args);
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
rb_str_new2(args[0]), rb_str_new2(args[1]));
} else if (num_args == 3) {
p_args = Py_BuildValue("sss", args[0], args[1], args[2]);
PyObject_CallObject(command->callback, p_args);
Py_XDECREF(p_args);
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
rb_str_new2(args[0]), rb_str_new2(args[1]), rb_str_new2(args[2]));
} else if (num_args == 4) {
p_args = Py_BuildValue("ssss", args[0], args[1], args[2], args[3]);
PyObject_CallObject(command->callback, p_args);
Py_XDECREF(p_args);
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
rb_str_new2(args[0]), rb_str_new2(args[1]), rb_str_new2(args[2]),
rb_str_new2(args[3]));
} else if (num_args == 5) {
p_args = Py_BuildValue("sssss", args[0], args[1], args[2], args[3], args[4]);
PyObject_CallObject(command->callback, p_args);
Py_XDECREF(p_args);
}
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
rb_str_new2(args[0]), rb_str_new2(args[1]), rb_str_new2(args[2]),
rb_str_new2(args[3]), rb_str_new2(args[4]));
}
}
void
ruby_timed_callback(PluginTimedFunction *timed_function)
{
PyObject_CallObject(timed_function->callback, NULL);
rb_funcall((VALUE)timed_function->callback, rb_intern("call"), 0);
}
static VALUE prof_module;

View File

@ -20,7 +20,6 @@
*
*/
#include <Python.h>
#include <ruby.h>
#include "config/preferences.h"
@ -38,12 +37,6 @@ ruby_env_init(void)
ruby_init_loadpath();
ruby_api_init();
ruby_check_error();
// 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 *
@ -103,12 +96,6 @@ ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const
void
ruby_check_error(void)
{
/* TODO
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
}
*/
}
void