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:
parent
2fd1633a6f
commit
21b823750e
@ -1,6 +1,8 @@
|
|||||||
module RubyTest
|
module RubyTest
|
||||||
def RubyTest.prof_init(version, status)
|
def RubyTest.prof_init(version, status)
|
||||||
Prof::cons_show("RubyTest: 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
|
end
|
||||||
|
|
||||||
def RubyTest.prof_on_start()
|
def RubyTest.prof_on_start()
|
||||||
@ -14,4 +16,22 @@ module RubyTest
|
|||||||
def RubyTest.prof_on_message_received(jid, message)
|
def RubyTest.prof_on_message_received(jid, message)
|
||||||
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
|
Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message)
|
||||||
end
|
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
|
end
|
||||||
|
@ -111,48 +111,37 @@ ruby_api_get_current_recipient(VALUE self)
|
|||||||
void
|
void
|
||||||
ruby_command_callback(PluginCommand *command, gchar **args)
|
ruby_command_callback(PluginCommand *command, gchar **args)
|
||||||
{
|
{
|
||||||
PyObject *p_args = NULL;
|
|
||||||
int num_args = g_strv_length(args);
|
int num_args = g_strv_length(args);
|
||||||
if (num_args == 0) {
|
if (num_args == 0) {
|
||||||
if (command->max_args == 1) {
|
if (command->max_args == 1) {
|
||||||
p_args = Py_BuildValue("(O)", Py_BuildValue(""));
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 1, Qnil);
|
||||||
PyObject_CallObject(command->callback, p_args);
|
|
||||||
Py_XDECREF(p_args);
|
|
||||||
} else {
|
} else {
|
||||||
PyObject_CallObject(command->callback, p_args);
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 0);
|
||||||
}
|
}
|
||||||
} else if (num_args == 1) {
|
} else if (num_args == 1) {
|
||||||
p_args = Py_BuildValue("(s)", args[0]);
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
|
||||||
PyObject_CallObject(command->callback, p_args);
|
rb_str_new2(args[0]));
|
||||||
Py_XDECREF(p_args);
|
|
||||||
} else if (num_args == 2) {
|
} else if (num_args == 2) {
|
||||||
p_args = Py_BuildValue("ss", args[0], args[1]);
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
|
||||||
PyObject_CallObject(command->callback, p_args);
|
rb_str_new2(args[0]), rb_str_new2(args[1]));
|
||||||
Py_XDECREF(p_args);
|
|
||||||
} else if (num_args == 3) {
|
} else if (num_args == 3) {
|
||||||
p_args = Py_BuildValue("sss", args[0], args[1], args[2]);
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
|
||||||
PyObject_CallObject(command->callback, p_args);
|
rb_str_new2(args[0]), rb_str_new2(args[1]), rb_str_new2(args[2]));
|
||||||
Py_XDECREF(p_args);
|
|
||||||
} else if (num_args == 4) {
|
} else if (num_args == 4) {
|
||||||
p_args = Py_BuildValue("ssss", args[0], args[1], args[2], args[3]);
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
|
||||||
PyObject_CallObject(command->callback, p_args);
|
rb_str_new2(args[0]), rb_str_new2(args[1]), rb_str_new2(args[2]),
|
||||||
Py_XDECREF(p_args);
|
rb_str_new2(args[3]));
|
||||||
} else if (num_args == 5) {
|
} else if (num_args == 5) {
|
||||||
p_args = Py_BuildValue("sssss", args[0], args[1], args[2], args[3], args[4]);
|
rb_funcall((VALUE)command->callback, rb_intern("call"), 1,
|
||||||
PyObject_CallObject(command->callback, p_args);
|
rb_str_new2(args[0]), rb_str_new2(args[1]), rb_str_new2(args[2]),
|
||||||
Py_XDECREF(p_args);
|
rb_str_new2(args[3]), rb_str_new2(args[4]));
|
||||||
}
|
|
||||||
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
PyErr_Print();
|
|
||||||
PyErr_Clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_timed_callback(PluginTimedFunction *timed_function)
|
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;
|
static VALUE prof_module;
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <ruby.h>
|
#include <ruby.h>
|
||||||
|
|
||||||
#include "config/preferences.h"
|
#include "config/preferences.h"
|
||||||
@ -38,12 +37,6 @@ ruby_env_init(void)
|
|||||||
ruby_init_loadpath();
|
ruby_init_loadpath();
|
||||||
ruby_api_init();
|
ruby_api_init();
|
||||||
ruby_check_error();
|
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 *
|
ProfPlugin *
|
||||||
@ -103,12 +96,6 @@ ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const
|
|||||||
void
|
void
|
||||||
ruby_check_error(void)
|
ruby_check_error(void)
|
||||||
{
|
{
|
||||||
/* TODO
|
|
||||||
if (PyErr_Occurred()) {
|
|
||||||
PyErr_Print();
|
|
||||||
PyErr_Clear();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user