1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
10
#include <gjs/gjs-module.h>
13
* shell_js_add_extension_importer:
14
* @target_object_script: JavaScript code evaluating to a target object
15
* @target_property: Name of property to use for importer
16
* @directory: Source directory:
19
* This function sets a property named @target_property on the object
20
* resulting from the evaluation of @target_object_script code, which
21
* acts as a GJS importer for directory @directory.
23
* Returns: %TRUE on success
26
shell_js_add_extension_importer (const char *target_object_script,
27
const char *target_property,
28
const char *directory,
34
char *search_path[2] = { 0, 0 };
37
/* Take the first GjsContext from all of them --
38
* we should only ever have one context, so this
39
* should be alright. */
40
contexts = gjs_context_get_all ();
41
context = gjs_context_get_native_context (contexts->data);
42
g_list_free_full (contexts, g_object_unref);
44
JS_BeginRequest (context);
46
/* This is a bit of a hack; ideally we'd be able to pass our target
47
* object directly into this function, but introspection doesn't
48
* support that at the moment. Instead evaluate a string to get it. */
49
if (!JS_EvaluateScript(context,
50
JS_GetGlobalObject(context),
52
strlen (target_object_script),
53
"<target_object_script>",
58
gjs_log_exception(context,
63
"%s", message ? message : "(unknown)");
68
if (!JSVAL_IS_OBJECT (target_object))
70
g_error ("shell_js_add_extension_importer: invalid target object");
74
search_path[0] = (char*)directory;
75
gjs_define_importer (context, JSVAL_TO_OBJECT (target_object), target_property, (const char **)search_path, FALSE);
79
JS_EndRequest (context);
84
* shell_js_format_int_alternative_output:
87
* Returns: (transfer full):
90
shell_js_format_int_alternative_output (gint intval)
92
return g_strdup_printf ("%Id", intval);