summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-06-23 19:39:37 +0200
committerJo-Philipp Wich <jo@mein.io>2021-07-11 15:49:14 +0200
commit01795764e95983e416f5db14dd5599206b9ea41b (patch)
tree48d0bb9d4d13ea86d0fc387275b73cc4a8565a8f
parent98b9c84a369b9f9fa2ee0c87724fcc2066aa0d65 (diff)
lib: rename uc_add_proto_functions() to uc_add_functions()
The naming is an artifact from before the introduction of the new type system. In the current code, there is nothing special about prototypes, they're simple object values. Also introduce a new singular uc_add_function() convenience macro while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c2
-rw-r--r--lib.h20
-rw-r--r--lib/fs.c2
-rw-r--r--lib/math.c2
-rw-r--r--lib/ubus.c2
-rw-r--r--lib/uci.c2
6 files changed, 18 insertions, 12 deletions
diff --git a/lib.c b/lib.c
index c8bed8a..e960681 100644
--- a/lib.c
+++ b/lib.c
@@ -2945,7 +2945,7 @@ const uc_cfunction_list uc_stdlib_functions[] = {
void
uc_load_stdlib(uc_value_t *scope)
{
- uc_add_proto_functions(scope, uc_stdlib_functions);
+ uc_add_functions(scope, uc_stdlib_functions);
}
uc_value_t *
diff --git a/lib.h b/lib.h
index e6bae8b..23992b9 100644
--- a/lib.h
+++ b/lib.h
@@ -111,17 +111,23 @@ _uc_declare_type(uc_vm *vm, const char *name, const uc_cfunction_list *list, siz
_uc_declare_type(vm, name, functions, ARRAY_SIZE(functions), freefn)
-/* prototype helper */
+/* function helper */
-static inline void
-_uc_add_proto_functions(uc_value_t *proto, const uc_cfunction_list *list, size_t len)
+#define uc_add_function(object, name, function) \
+ ucv_object_add(object, name, ucv_cfunction_new(name, function))
+
+static inline bool
+_uc_add_functions(uc_value_t *object, const uc_cfunction_list *list, size_t len)
{
+ bool rv = true;
+
while (len-- > 0)
- ucv_object_add(proto, list[len].name,
- ucv_cfunction_new(list[len].name, list[len].func));
+ rv &= uc_add_function(object, list[len].name, list[len].func);
+
+ return rv;
}
-#define uc_add_proto_functions(proto, functions) \
- _uc_add_proto_functions(proto, functions, ARRAY_SIZE(functions))
+#define uc_add_functions(object, functions) \
+ _uc_add_functions(object, functions, ARRAY_SIZE(functions))
#endif /* __LIB_H_ */
diff --git a/lib/fs.c b/lib/fs.c
index 0c37aab..6f6c7cb 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -906,7 +906,7 @@ static void close_dir(void *ud)
void uc_module_init(uc_vm *vm, uc_value_t *scope)
{
- uc_add_proto_functions(scope, global_fns);
+ uc_add_functions(scope, global_fns);
proc_type = uc_declare_type(vm, "fs.proc", proc_fns, close_proc);
file_type = uc_declare_type(vm, "fs.file", file_fns, close_file);
diff --git a/lib/math.c b/lib/math.c
index 0adfaf8..bc8efb6 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -160,5 +160,5 @@ static const uc_cfunction_list math_fns[] = {
void uc_module_init(uc_vm *vm, uc_value_t *scope)
{
- uc_add_proto_functions(scope, math_fns);
+ uc_add_functions(scope, math_fns);
}
diff --git a/lib/ubus.c b/lib/ubus.c
index fb7600a..933ef3a 100644
--- a/lib/ubus.c
+++ b/lib/ubus.c
@@ -322,7 +322,7 @@ static void close_connection(void *ud) {
void uc_module_init(uc_vm *vm, uc_value_t *scope)
{
- uc_add_proto_functions(scope, global_fns);
+ uc_add_functions(scope, global_fns);
conn_type = uc_declare_type(vm, "ubus.connection", conn_fns, close_connection);
}
diff --git a/lib/uci.c b/lib/uci.c
index d9a9ea6..71a9c2d 100644
--- a/lib/uci.c
+++ b/lib/uci.c
@@ -1007,7 +1007,7 @@ static void close_uci(void *ud) {
void uc_module_init(uc_vm *vm, uc_value_t *scope)
{
- uc_add_proto_functions(scope, global_fns);
+ uc_add_functions(scope, global_fns);
cursor_type = uc_declare_type(vm, "uci.cursor", cursor_fns, close_uci);
}