summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-05-25 19:14:20 +0200
committerJo-Philipp Wich <jo@mein.io>2021-05-25 21:02:40 +0200
commitd81bad7683165df8b9e3a8f8edf253129ce6f4b2 (patch)
tree66e1df3c8a40f4bbaa1220b0cb5d26972fbb3bbd /lib.c
parentc4f4b38a84ac2f762f9a3acfb2f22d6b0d971899 (diff)
main, lib: move allocation of globals object into lib function
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index c3a1599..466d56a 100644
--- a/lib.c
+++ b/lib.c
@@ -2583,3 +2583,26 @@ uc_lib_init(uc_value_t *scope)
{
uc_add_proto_functions(scope, functions);
}
+
+uc_value_t *
+uc_alloc_global(uc_vm *vm)
+{
+ const char *path[] = { LIB_SEARCH_PATH };
+ uc_value_t *global, *arr;
+ size_t i;
+
+ global = ucv_object_new(vm);
+
+ /* build default require() search path */
+ arr = ucv_array_new(vm);
+
+ for (i = 0; i < ARRAY_SIZE(path); i++)
+ ucv_array_push(arr, ucv_string_new(path[i]));
+
+ ucv_object_add(global, "REQUIRE_SEARCH_PATH", arr);
+
+ /* register global property */
+ ucv_object_add(global, "global", ucv_get(global));
+
+ return global;
+}