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 = malloc(sizeof(ProfPlugin));
plugin->name = g_strdup(filename); plugin->name = g_strdup(filename);
plugin->lang = C; plugin->lang = LANG_C;
plugin->module = handle; plugin->module = handle;
plugin->init_func = c_init_hook; plugin->init_func = c_init_hook;
plugin->on_start_func = c_on_start_hook; plugin->on_start_func = c_on_start_hook;

View File

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

View File

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

View File

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

View File

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