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

Got basic hook working in ruby

This commit is contained in:
James Booth 2013-08-18 20:11:16 +01:00
parent d5818f49db
commit 1b8cff6def
7 changed files with 30 additions and 51 deletions

5
plugins/RubyTest.rb Normal file
View File

@ -0,0 +1,5 @@
module RubyTest
def RubyTest.prof_init(version, status)
$stderr.puts "From Ruby: " + version + " " + status
end
end

View File

@ -1,15 +0,0 @@
module RubyTest
include prof
prof_version = ""
prof_status = ""
def prof_init(version, status)
prof_version = version
prof_status = status
end
def prof_on_start()
prof.cons_show("RubyTest: " + prof_version + " " + prof_status)
end
end

View File

@ -33,7 +33,7 @@ c_plugin_create(const char * const filename)
plugin = malloc(sizeof(ProfPlugin));
plugin->name = g_strdup(filename);
plugin->lang = C;
plugin->lang = LANG_C;
plugin->module = handle;
plugin->init_func = c_init_hook;
plugin->on_start_func = c_on_start_hook;

View File

@ -133,7 +133,7 @@ plugins_shutdown(void)
while (curr != NULL) {
ProfPlugin *plugin = curr->data;
if (plugin->lang == C)
if (plugin->lang == LANG_C)
c_close_library (plugin);
curr = g_slist_next(curr);

View File

@ -24,8 +24,9 @@
#define PLUGINS_H
typedef enum {
PYTHON,
C
LANG_PYTHON,
LANG_RUBY,
LANG_C
} lang_t;
typedef struct prof_plugin_t {

View File

@ -54,7 +54,7 @@ python_plugin_create(const char * const filename)
if (p_module != NULL) {
ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
plugin->name = module_name;
plugin->lang = PYTHON;
plugin->lang = LANG_PYTHON;
plugin->module = p_module;
plugin->init_func = python_init_hook;
plugin->on_start_func = python_on_start_hook;

View File

@ -35,7 +35,8 @@ void
ruby_env_init(void)
{
ruby_init();
ruby_check_error();
ruby_script("prof");
ruby_init_loadpath();
ruby_api_init();
ruby_check_error();
// TODO set loadpath for ruby interpreter
@ -49,44 +50,31 @@ ruby_env_init(void)
ProfPlugin *
ruby_plugin_create(const char * const filename)
{
GString *path = g_string_new("./plugins/");
g_string_append(path, filename);
rb_require(path->str);
gchar *module_name = g_strndup(filename, strlen(filename) - 3);
PyObject *p_module = PyImport_ImportModule(module_name);
ruby_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 = ruby_init_hook;
plugin->on_start_func = ruby_on_start_hook;
plugin->on_connect_func = ruby_on_connect_hook;
plugin->on_message_received_func = ruby_on_message_received_hook;
g_free(module_name);
return plugin;
} else {
g_free(module_name);
return NULL;
}
ProfPlugin *plugin = malloc(sizeof(ProfPlugin));
plugin->name = module_name;
plugin->lang = LANG_RUBY;
plugin->module = NULL;
plugin->init_func = ruby_init_hook;
plugin->on_start_func = ruby_on_start_hook;
plugin->on_connect_func = ruby_on_connect_hook;
plugin->on_message_received_func = ruby_on_message_received_hook;
return plugin;
}
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;
VALUE v_version = rb_str_new2(version);
VALUE v_status = rb_str_new2(status);
PyObject *p_module = plugin->module;
if (PyObject_HasAttrString(p_module, "prof_init")) {
p_function = PyObject_GetAttrString(p_module, "prof_init");
ruby_check_error();
if (p_function && PyCallable_Check(p_function)) {
PyObject_CallObject(p_function, p_args);
ruby_check_error();
Py_XDECREF(p_function);
}
}
*/
VALUE module = rb_const_get(rb_cObject, rb_intern(plugin->name));
rb_funcall(module, rb_intern("prof_init"), 2, v_version, v_status);
}
void