--- a/gjs/gplugin-gjs-loader.cc Sat Feb 15 01:33:13 2020 -0600
+++ b/gjs/gplugin-gjs-loader.cc Mon Feb 17 00:51:58 2020 -0600
@@ -24,9 +24,11 @@
-G_DEFINE_DYNAMIC_TYPE(GPluginGjsLoader, gplugin_gjs_loader, GPLUGIN_TYPE_LOADER);
+struct _GPluginGjsLoader { -static GjsContext *global_ctx = NULL;
+ GjsContext *global_ctx; /******************************************************************************
@@ -49,7 +51,7 @@
* GPluginLoaderInterface API
*****************************************************************************/
-gplugin_gjs_loader_class_supported_extensions(G_GNUC_UNUSED const GPluginLoaderClass *klass) {
+gplugin_gjs_loader_class_supported_extensions(G_GNUC_UNUSED GPluginLoaderClass *klass) { return g_slist_append(NULL, (gpointer)"js");
@@ -60,21 +62,21 @@
GPluginPluginInfo *info = NULL;
- GjsContext *context = NULL;
+ GjsContext *ctx = NULL; + JSContext *jsctx = NULL; - context = gjs_context_new();
+ ctx = gjs_context_new(); - g_message("context: %p", context);
+ g_message("ctx: %p", ctx); - if(!_gplugin_gjs_loader_eval_file(context, filename, error)) {
- g_object_unref(G_OBJECT(context));
+ if(!_gplugin_gjs_loader_eval_file(ctx, filename, error)) { + g_object_unref(G_OBJECT(ctx)); - cx = (JSContext*)gjs_context_get_native_context(context);
+ jsctx = (JSContext*)gjs_context_get_native_context(ctx); /* now call the query function */
@@ -156,30 +158,50 @@
/******************************************************************************
+ * GObject Implementation *****************************************************************************/
+G_DEFINE_DYNAMIC_TYPE(GPluginGjsLoader, gplugin_gjs_loader, GPLUGIN_TYPE_LOADER); -gplugin_gjs_loader_init(G_GNUC_UNUSED GPluginGjsLoader *loader) {
+gplugin_gjs_loader_init(GPluginGjsLoader *loader) { + const gchar *appname = g_get_prgname(); + loader->global_ctx = (GjsContext *)g_object_new(GJS_TYPE_CONTEXT, + "program-name", appname, + gjs_context_make_current(loader->global_ctx); +gplugin_gjs_loader_finalize(GObject *obj) { + GPluginGjsLoader *loader = GPLUGIN_GJS_LOADER(obj); + g_clear_object(&loader->global_ctx); + G_OBJECT_CLASS(gplugin_gjs_loader_parent_class)->finalize(obj); gplugin_gjs_loader_class_init(G_GNUC_UNUSED GPluginGjsLoaderClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass); GPluginLoaderClass *loader_class = GPLUGIN_LOADER_CLASS(klass);
+ obj_class->finalize = gplugin_gjs_loader_finalize; loader_class->supported_extensions =
gplugin_gjs_loader_class_supported_extensions;
loader_class->query = gplugin_gjs_loader_query;
loader_class->load = gplugin_gjs_loader_load;
loader_class->unload = gplugin_gjs_loader_unload;
- g_warning("current-context: %p", gjs_context_get_current());
- global_ctx = (GjsContext *)g_object_new(GJS_TYPE_CONTEXT, "program-name", "gplugin", NULL);
gplugin_gjs_loader_class_finalize(G_GNUC_UNUSED GPluginGjsLoaderClass *klass) {
- g_clear_object(&global_ctx);
/******************************************************************************
--- a/gjs/gplugin-gjs-loader.h Sat Feb 15 01:33:13 2020 -0600
+++ b/gjs/gplugin-gjs-loader.h Mon Feb 17 00:51:58 2020 -0600
@@ -18,41 +18,15 @@
#ifndef GPLUGIN_GJS_LOADER_H
#define GPLUGIN_GJS_LOADER_H
-#define GPLUGIN_TYPE_GJS_LOADER (gplugin_gjs_loader_get_type())
-#define GPLUGIN_GJS_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLUGIN_TYPE_GJS_LOADER, GPluginGjsLoader))
-#define GPLUGIN_GJS_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((obj), GPLUGIN_TYPE_GJS_LOADER, GPluginGjsLoaderClass))
-#define GPLUGIN_IS_GJS_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GPLUGIN_TYPE_GJS_LOADER))
-#define GPLUGIN_IS_GJS_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), GPLUGIN_TYPE_GJS_LOADER))
-#define GPLUGIN_GJS_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GPLUGIN_TYPE_GJS_LOADER, GPluginGjsLoaderClass))
-typedef struct _GPluginGjsLoader GPluginGjsLoader;
-typedef struct _GPluginGjsLoaderClass GPluginGjsLoaderClass;
#include <gplugin-native.h>
-struct _GPluginGjsLoader {
- void (*_gplugin_reserved_1)(void);
- void (*_gplugin_reserved_2)(void);
- void (*_gplugin_reserved_3)(void);
- void (*_gplugin_reserved_4)(void);
-struct _GPluginGjsLoaderClass {
- GPluginLoaderClass parent;
- void (*_gplugin_reserved_1)(void);
- void (*_gplugin_reserved_2)(void);
- void (*_gplugin_reserved_3)(void);
- void (*_gplugin_reserved_4)(void);
+#define GPLUGIN_TYPE_GJS_LOADER (gplugin_gjs_loader_get_type()) +G_DECLARE_FINAL_TYPE(GPluginGjsLoader, gplugin_gjs_loader, GPLUGIN_GJS, LOADER, GPluginLoader) void gplugin_gjs_loader_register(GPluginNativePlugin *plugin);
-GType gplugin_gjs_loader_get_type(void);