gplugin/gplugin

closing this branch as there is no demand for this
feature/ruby-loader
16 months ago, Gary Kramlich
d44bad5e041e
closing this branch as there is no demand for this
/*
* Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <ruby.h>
#include "gplugin-ruby-loader.h"
#include "gplugin-ruby-plugin.h"
#define GPLUGIN_RUBY_LOADER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLUGIN_TYPE_RUBY_LOADER, GPluginRubyLoaderPrivate))
/******************************************************************************
* Typedefs
*****************************************************************************/
typedef struct {
gint dummy;
} GPluginRubyLoaderPrivate;
/******************************************************************************
* Globals
*****************************************************************************/
static GObjectClass *parent_class = NULL;
static GType type_real = 0;
/******************************************************************************
* GPluginLoaderInterface API
*****************************************************************************/
static GSList *
gplugin_ruby_loader_class_supported_extensions(GPLUGIN_UNUSED const GPluginLoaderClass *klass) {
return g_slist_append(NULL, "rb");
}
static GPluginPlugin *
gplugin_ruby_loader_query(GPLUGIN_UNUSED GPluginLoader *loader,
const gchar *filename,
GError **error)
{
GPluginPlugin *plugin = NULL;
gpointer other = NULL;
VALUE module = 0, script = 0;
gint state = 0;
g_message("filename: %s", filename);
/* this is garbage and should be normalized somehow */
module = rb_define_module("gplugin");
script = rb_new_cstr(filename);
rb_load_protect(script, 1, &state);
if(state) {
if(error) {
*error = g_error_new(GPLUGIN_DOMAIN, 0, "failed to load %s", filename);
}
return NULL;
}
g_message("type: 0x%x", TYPE(script));
// info = rb_funcall(
// rb_current_receiver(),
// rb_intern("gplugin_query"),
// 1,
// NULL
// );
g_message("info: %" G_GUINT64_FORMAT, info);
return plugin;
}
static gboolean
gplugin_ruby_loader_load(GPLUGIN_UNUSED GPluginLoader *loader,
GPluginPlugin *plugin,
GError **error)
{
gboolean ret = FALSE;
return ret;
}
static gboolean
gplugin_ruby_loader_unload(GPLUGIN_UNUSED GPluginLoader *loader,
GPluginPlugin *plugin,
GError **error)
{
gboolean ret = FALSE;
return ret;
}
/******************************************************************************
* Ruby Stuff
*****************************************************************************/
static gboolean
gplugin_ruby_loader_init_ruby(void) {
ruby_init();
ruby_init_loadpath();
return TRUE;
}
/******************************************************************************
* Object Stuff
*****************************************************************************/
static void
gplugin_ruby_loader_finalize(GObject *obj) {
G_OBJECT_CLASS(parent_class)->finalize(obj);
}
static void
gplugin_ruby_loader_class_init(GPluginRubyLoaderClass *klass) {
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
GPluginLoaderClass *loader_class =
GPLUGIN_LOADER_CLASS(klass);
parent_class = g_type_class_peek_parent(klass);
g_type_class_add_private(klass, sizeof(GPluginRubyLoaderPrivate));
obj_class->finalize = gplugin_ruby_loader_finalize;
loader_class->supported_extensions =
gplugin_ruby_loader_class_supported_extensions;
loader_class->query = gplugin_ruby_loader_query;
loader_class->load = gplugin_ruby_loader_load;
loader_class->unload = gplugin_ruby_loader_unload;
}
/******************************************************************************
* API
*****************************************************************************/
void
gplugin_ruby_loader_register(GPluginNativePlugin *plugin) {
if(g_once_init_enter(&type_real)) {
GType type = 0;
static const GTypeInfo info = {
.class_size = sizeof(GPluginRubyLoaderClass),
.class_init = (GClassInitFunc)gplugin_ruby_loader_class_init,
.instance_size = sizeof(GPluginRubyLoader),
};
type = gplugin_native_plugin_register_type(plugin,
GPLUGIN_TYPE_LOADER,
"GPluginRubyLoader",
&info,
0);
gplugin_ruby_loader_init_ruby();
g_once_init_leave(&type_real, type);
}
}
GType
gplugin_ruby_loader_get_type(void) {
if(G_UNLIKELY(type_real == 0)) {
g_warning("gplugin_ruby_loader_get_type was called before "
"the type was registered!\n");
}
return type_real;
}