summaryrefslogtreecommitdiffhomepage
path: root/lib.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-06 14:16:19 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-06 23:25:11 +0200
commitb6fd8a2f825ba3d38137bcfbf44ef7dd09161cd2 (patch)
tree1cd19fd65ad6892e900a42186c907593e6968943 /lib.c
parenta486adc4e377611f1bcd957afe8c3ff6643e75c4 (diff)
lib: internally expose new uc_require_library() helper
Break out the core logic of the uc_require() stl function into a new uc_require_library() helper function and make it available for usage outside of lib.c. Also add a new boolean parameter to the helper function which allows restricting runtime require operations of modules to dynamic libraries only. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/lib.c b/lib.c
index 779e3f5..7a04cdd 100644
--- a/lib.c
+++ b/lib.c
@@ -1674,7 +1674,7 @@ uc_require_ucode(uc_vm_t *vm, const char *path, uc_value_t *scope, uc_value_t **
}
static bool
-uc_require_path(uc_vm_t *vm, const char *path_template, const char *name, uc_value_t **res)
+uc_require_path(uc_vm_t *vm, const char *path_template, const char *name, uc_value_t **res, bool so_only)
{
uc_stringbuf_t *buf = xprintbuf_new();
const char *p, *q, *last;
@@ -1715,7 +1715,7 @@ uc_require_path(uc_vm_t *vm, const char *path_template, const char *name, uc_val
if (!strcmp(p + 1, ".so"))
rv = uc_require_so(vm, buf->buf, res);
- else if (!strcmp(p + 1, ".uc"))
+ else if (!strcmp(p + 1, ".uc") && !so_only)
rv = uc_require_ucode(vm, buf->buf, NULL, res, true);
if (rv)
@@ -1727,18 +1727,17 @@ out:
return rv;
}
-static uc_value_t *
-uc_require(uc_vm_t *vm, size_t nargs)
+uc_value_t *
+uc_require_library(uc_vm_t *vm, uc_value_t *nameval, bool so_only)
{
- uc_value_t *val = uc_fn_arg(0);
uc_value_t *search, *se, *res;
size_t arridx, arrlen;
const char *name;
- if (ucv_type(val) != UC_STRING)
+ if (ucv_type(nameval) != UC_STRING)
return NULL;
- name = ucv_string_get(val);
+ name = ucv_string_get(nameval);
search = ucv_property_get(uc_vm_scope_get(vm), "REQUIRE_SEARCH_PATH");
if (ucv_type(search) != UC_ARRAY) {
@@ -1754,7 +1753,7 @@ uc_require(uc_vm_t *vm, size_t nargs)
if (ucv_type(se) != UC_STRING)
continue;
- if (uc_require_path(vm, ucv_string_get(se), name, &res))
+ if (uc_require_path(vm, ucv_string_get(se), name, &res, so_only))
return res;
}
@@ -1765,6 +1764,12 @@ uc_require(uc_vm_t *vm, size_t nargs)
}
static uc_value_t *
+uc_require(uc_vm_t *vm, size_t nargs)
+{
+ return uc_require_library(vm, uc_fn_arg(0), false);
+}
+
+static uc_value_t *
uc_iptoarr(uc_vm_t *vm, size_t nargs)
{
uc_value_t *ip = uc_fn_arg(0);