summaryrefslogtreecommitdiffhomepage
path: root/lib/uci.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/uci.c')
-rw-r--r--lib/uci.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/lib/uci.c b/lib/uci.c
index 00a451c..f582ddb 100644
--- a/lib/uci.c
+++ b/lib/uci.c
@@ -17,7 +17,7 @@
#include <string.h>
#include <uci.h>
-#include "../module.h"
+#include "ucode/module.h"
#define err_return(err) do { last_error = err; return NULL; } while(0)
@@ -31,7 +31,7 @@ enum pkg_cmd {
};
static uc_value_t *
-uc_uci_error(uc_vm *vm, size_t nargs)
+uc_uci_error(uc_vm_t *vm, size_t nargs)
{
char buf[sizeof("Unknown error: -9223372036854775808")];
uc_value_t *errmsg;
@@ -64,10 +64,10 @@ uc_uci_error(uc_vm *vm, size_t nargs)
static uc_value_t *
-uc_uci_cursor(uc_vm *vm, size_t nargs)
+uc_uci_cursor(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *cdir = uc_get_arg(0);
- uc_value_t *sdir = uc_get_arg(1);
+ uc_value_t *cdir = uc_fn_arg(0);
+ uc_value_t *sdir = uc_fn_arg(1);
struct uci_context *c;
int rv;
@@ -94,15 +94,15 @@ uc_uci_cursor(uc_vm *vm, size_t nargs)
err_return(rv);
}
- return uc_alloc_ressource(cursor_type, c);
+ return uc_ressource_new(cursor_type, c);
}
static uc_value_t *
-uc_uci_load(uc_vm *vm, size_t nargs)
+uc_uci_load(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
struct uci_element *e;
char *s;
@@ -128,10 +128,10 @@ uc_uci_load(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_unload(uc_vm *vm, size_t nargs)
+uc_uci_unload(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
struct uci_element *e;
if (!c || !*c)
@@ -181,7 +181,7 @@ lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, bool extended)
}
static uc_value_t *
-option_to_uval(uc_vm *vm, struct uci_option *o)
+option_to_uval(uc_vm_t *vm, struct uci_option *o)
{
struct uci_element *e;
uc_value_t *arr;
@@ -205,7 +205,7 @@ option_to_uval(uc_vm *vm, struct uci_option *o)
}
static uc_value_t *
-section_to_uval(uc_vm *vm, struct uci_section *s, int index)
+section_to_uval(uc_vm_t *vm, struct uci_section *s, int index)
{
uc_value_t *so = ucv_object_new(vm);
struct uci_element *e;
@@ -230,7 +230,7 @@ section_to_uval(uc_vm *vm, struct uci_section *s, int index)
}
static uc_value_t *
-package_to_uval(uc_vm *vm, struct uci_package *p)
+package_to_uval(uc_vm_t *vm, struct uci_package *p)
{
uc_value_t *po = ucv_object_new(vm);
uc_value_t *so;
@@ -249,12 +249,12 @@ package_to_uval(uc_vm *vm, struct uci_package *p)
}
static uc_value_t *
-uc_uci_get_any(uc_vm *vm, size_t nargs, bool all)
+uc_uci_get_any(uc_vm_t *vm, size_t nargs, bool all)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *sect = uc_get_arg(1);
- uc_value_t *opt = uc_get_arg(2);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *sect = uc_fn_arg(1);
+ uc_value_t *opt = uc_fn_arg(2);
struct uci_ptr ptr = { 0 };
int rv;
@@ -309,24 +309,24 @@ uc_uci_get_any(uc_vm *vm, size_t nargs, bool all)
}
static uc_value_t *
-uc_uci_get(uc_vm *vm, size_t nargs)
+uc_uci_get(uc_vm_t *vm, size_t nargs)
{
return uc_uci_get_any(vm, nargs, false);
}
static uc_value_t *
-uc_uci_get_all(uc_vm *vm, size_t nargs)
+uc_uci_get_all(uc_vm_t *vm, size_t nargs)
{
return uc_uci_get_any(vm, nargs, true);
}
static uc_value_t *
-uc_uci_get_first(uc_vm *vm, size_t nargs)
+uc_uci_get_first(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *type = uc_get_arg(1);
- uc_value_t *opt = uc_get_arg(2);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *type = uc_fn_arg(1);
+ uc_value_t *opt = uc_fn_arg(2);
struct uci_package *p = NULL;
struct uci_section *sc;
struct uci_element *e;
@@ -379,11 +379,11 @@ uc_uci_get_first(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_add(uc_vm *vm, size_t nargs)
+uc_uci_add(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *type = uc_get_arg(1);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *type = uc_fn_arg(1);
struct uci_element *e = NULL;
struct uci_package *p = NULL;
struct uci_section *sc = NULL;
@@ -414,7 +414,7 @@ uc_uci_add(uc_vm *vm, size_t nargs)
}
static bool
-uval_to_uci(uc_vm *vm, uc_value_t *val, const char **p, bool *is_list)
+uval_to_uci(uc_vm_t *vm, uc_value_t *val, const char **p, bool *is_list)
{
uc_value_t *item;
@@ -459,11 +459,11 @@ uval_to_uci(uc_vm *vm, uc_value_t *val, const char **p, bool *is_list)
}
static uc_value_t *
-uc_uci_set(uc_vm *vm, size_t nargs)
+uc_uci_set(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *sect = uc_get_arg(1);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *sect = uc_fn_arg(1);
uc_value_t *opt = NULL, *val = NULL;
struct uci_ptr ptr = { 0 };
bool is_list = false;
@@ -477,8 +477,8 @@ uc_uci_set(uc_vm *vm, size_t nargs)
switch (nargs) {
/* conf, sect, opt, val */
case 4:
- opt = uc_get_arg(2);
- val = uc_get_arg(3);
+ opt = uc_fn_arg(2);
+ val = uc_fn_arg(3);
if (ucv_type(opt) != UC_STRING)
err_return(UCI_ERR_INVAL);
@@ -487,7 +487,7 @@ uc_uci_set(uc_vm *vm, size_t nargs)
/* conf, sect, type */
case 3:
- val = uc_get_arg(2);
+ val = uc_fn_arg(2);
if (ucv_type(val) != UC_STRING)
err_return(UCI_ERR_INVAL);
@@ -564,12 +564,12 @@ uc_uci_set(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_delete(uc_vm *vm, size_t nargs)
+uc_uci_delete(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *sect = uc_get_arg(1);
- uc_value_t *opt = uc_get_arg(2);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *sect = uc_fn_arg(1);
+ uc_value_t *opt = uc_fn_arg(2);
struct uci_ptr ptr = { 0 };
int rv;
@@ -599,11 +599,11 @@ uc_uci_delete(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_rename(uc_vm *vm, size_t nargs)
+uc_uci_rename(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *sect = uc_get_arg(1);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *sect = uc_fn_arg(1);
uc_value_t *opt = NULL, *val = NULL;
struct uci_ptr ptr = { 0 };
int rv;
@@ -615,8 +615,8 @@ uc_uci_rename(uc_vm *vm, size_t nargs)
switch (nargs) {
/* conf, sect, opt, val */
case 4:
- opt = uc_get_arg(2);
- val = uc_get_arg(3);
+ opt = uc_fn_arg(2);
+ val = uc_fn_arg(3);
if (ucv_type(opt) != UC_STRING ||
ucv_type(val) != UC_STRING)
@@ -626,7 +626,7 @@ uc_uci_rename(uc_vm *vm, size_t nargs)
/* conf, sect, type */
case 3:
- val = uc_get_arg(2);
+ val = uc_fn_arg(2);
if (ucv_type(val) != UC_STRING)
err_return(UCI_ERR_INVAL);
@@ -659,12 +659,12 @@ uc_uci_rename(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_reorder(uc_vm *vm, size_t nargs)
+uc_uci_reorder(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *sect = uc_get_arg(1);
- uc_value_t *val = uc_get_arg(2);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *sect = uc_fn_arg(1);
+ uc_value_t *val = uc_fn_arg(2);
struct uci_ptr ptr = { 0 };
int64_t n;
int rv;
@@ -699,10 +699,10 @@ uc_uci_reorder(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_pkg_command(uc_vm *vm, size_t nargs, enum pkg_cmd cmd)
+uc_uci_pkg_command(uc_vm_t *vm, size_t nargs, enum pkg_cmd cmd)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
struct uci_element *e, *tmp;
struct uci_package *p;
struct uci_ptr ptr = { 0 };
@@ -749,25 +749,25 @@ uc_uci_pkg_command(uc_vm *vm, size_t nargs, enum pkg_cmd cmd)
}
static uc_value_t *
-uc_uci_save(uc_vm *vm, size_t nargs)
+uc_uci_save(uc_vm_t *vm, size_t nargs)
{
return uc_uci_pkg_command(vm, nargs, CMD_SAVE);
}
static uc_value_t *
-uc_uci_commit(uc_vm *vm, size_t nargs)
+uc_uci_commit(uc_vm_t *vm, size_t nargs)
{
return uc_uci_pkg_command(vm, nargs, CMD_COMMIT);
}
static uc_value_t *
-uc_uci_revert(uc_vm *vm, size_t nargs)
+uc_uci_revert(uc_vm_t *vm, size_t nargs)
{
return uc_uci_pkg_command(vm, nargs, CMD_REVERT);
}
static uc_value_t *
-change_to_uval(uc_vm *vm, struct uci_delta *d)
+change_to_uval(uc_vm_t *vm, struct uci_delta *d)
{
const char *types[] = {
[UCI_CMD_REORDER] = "order",
@@ -806,7 +806,7 @@ change_to_uval(uc_vm *vm, struct uci_delta *d)
}
static uc_value_t *
-changes_to_uval(uc_vm *vm, struct uci_context *ctx, const char *package)
+changes_to_uval(uc_vm_t *vm, struct uci_context *ctx, const char *package)
{
uc_value_t *a = NULL, *c;
struct uci_package *p = NULL;
@@ -856,10 +856,10 @@ changes_to_uval(uc_vm *vm, struct uci_context *ctx, const char *package)
}
static uc_value_t *
-uc_uci_changes(uc_vm *vm, size_t nargs)
+uc_uci_changes(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
uc_value_t *res, *chg;
char **configs;
int rv, i;
@@ -890,12 +890,12 @@ uc_uci_changes(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_foreach(uc_vm *vm, size_t nargs)
+uc_uci_foreach(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
- uc_value_t *conf = uc_get_arg(0);
- uc_value_t *type = uc_get_arg(1);
- uc_value_t *func = uc_get_arg(2);
+ struct uci_context **c = uc_fn_this("uci.cursor");
+ uc_value_t *conf = uc_fn_arg(0);
+ uc_value_t *type = uc_fn_arg(1);
+ uc_value_t *func = uc_fn_arg(2);
uc_value_t *rv = NULL;
struct uci_package *p = NULL;
struct uci_element *e, *tmp;
@@ -927,8 +927,8 @@ uc_uci_foreach(uc_vm *vm, size_t nargs)
if (type && strcmp(sc->type, ucv_string_get(type)))
continue;
- uc_push_val(ucv_get(func));
- uc_push_val(section_to_uval(vm, sc, i - 1));
+ uc_value_push(ucv_get(func));
+ uc_value_push(section_to_uval(vm, sc, i - 1));
ex = uc_call(1);
@@ -937,7 +937,7 @@ uc_uci_foreach(uc_vm *vm, size_t nargs)
break;
ret = true;
- rv = uc_pop_val();
+ rv = uc_value_pop();
stop = (ucv_type(rv) == UC_BOOLEAN && !ucv_boolean_get(rv));
ucv_put(rv);
@@ -952,9 +952,9 @@ uc_uci_foreach(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_uci_configs(uc_vm *vm, size_t nargs)
+uc_uci_configs(uc_vm_t *vm, size_t nargs)
{
- struct uci_context **c = uc_get_self("uci.cursor");
+ struct uci_context **c = uc_fn_this("uci.cursor");
uc_value_t *a;
char **configs;
int i, rv;
@@ -975,7 +975,7 @@ uc_uci_configs(uc_vm *vm, size_t nargs)
}
-static const uc_cfunction_list cursor_fns[] = {
+static const uc_function_list_t cursor_fns[] = {
{ "load", uc_uci_load },
{ "unload", uc_uci_unload },
{ "get", uc_uci_get },
@@ -995,7 +995,7 @@ static const uc_cfunction_list cursor_fns[] = {
{ "error", uc_uci_error },
};
-static const uc_cfunction_list global_fns[] = {
+static const uc_function_list_t global_fns[] = {
{ "error", uc_uci_error },
{ "cursor", uc_uci_cursor },
};
@@ -1005,9 +1005,9 @@ static void close_uci(void *ud) {
uci_free_context((struct uci_context *)ud);
}
-void uc_module_init(uc_value_t *scope)
+void uc_module_init(uc_vm_t *vm, uc_value_t *scope)
{
- uc_add_proto_functions(scope, global_fns);
+ uc_function_list_register(scope, global_fns);
- cursor_type = uc_declare_type("uci.cursor", cursor_fns, close_uci);
+ cursor_type = uc_type_declare(vm, "uci.cursor", cursor_fns, close_uci);
}