summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-07-11 18:03:42 +0200
committerGitHub <noreply@github.com>2021-07-11 18:03:42 +0200
commite4871c661f0bfb979f1b235d7b6e59b70ed1aca6 (patch)
tree40542b06a966366e2e8a3a0118e756874a838ce6 /lib
parentdad8f3aed4ca5f2f93e2be6f1243632439dec541 (diff)
parentd5b25f942147b09511d77d5470cd38a1e1643fb9 (diff)
Merge pull request #15 from jow-/c-api
C API wip
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.c170
-rw-r--r--lib/math.c52
-rw-r--r--lib/ubus.c48
-rw-r--r--lib/uci.c164
4 files changed, 217 insertions, 217 deletions
diff --git a/lib/fs.c b/lib/fs.c
index 4f96a6c..485dfb1 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -26,7 +26,7 @@
#include <pwd.h>
#include <glob.h>
-#include "../module.h"
+#include "ucode/module.h"
#define err_return(err) do { last_error = err; return NULL; } while(0)
@@ -36,7 +36,7 @@ static uc_ressource_type_t *file_type, *proc_type, *dir_type;
static int last_error = 0;
static uc_value_t *
-uc_fs_error(uc_vm *vm, size_t nargs)
+uc_fs_error(uc_vm_t *vm, size_t nargs)
{
uc_value_t *errmsg;
@@ -50,16 +50,16 @@ uc_fs_error(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_read_common(uc_vm *vm, size_t nargs, const char *type)
+uc_fs_read_common(uc_vm_t *vm, size_t nargs, const char *type)
{
- uc_value_t *limit = uc_get_arg(0);
+ uc_value_t *limit = uc_fn_arg(0);
uc_value_t *rv = NULL;
char buf[128], *p = NULL, *tmp;
size_t rlen, len = 0;
const char *lstr;
int64_t lsize;
- FILE **fp = uc_get_self(type);
+ FILE **fp = uc_fn_this(type);
if (!fp || !*fp)
err_return(EBADF);
@@ -142,13 +142,13 @@ uc_fs_read_common(uc_vm *vm, size_t nargs, const char *type)
}
static uc_value_t *
-uc_fs_write_common(uc_vm *vm, size_t nargs, const char *type)
+uc_fs_write_common(uc_vm_t *vm, size_t nargs, const char *type)
{
- uc_value_t *data = uc_get_arg(0);
+ uc_value_t *data = uc_fn_arg(0);
size_t len, wsize;
char *str;
- FILE **fp = uc_get_self(type);
+ FILE **fp = uc_fn_this(type);
if (!fp || !*fp)
err_return(EBADF);
@@ -172,9 +172,9 @@ uc_fs_write_common(uc_vm *vm, size_t nargs, const char *type)
static uc_value_t *
-uc_fs_pclose(uc_vm *vm, size_t nargs)
+uc_fs_pclose(uc_vm_t *vm, size_t nargs)
{
- FILE **fp = uc_get_self("fs.proc");
+ FILE **fp = uc_fn_this("fs.proc");
int rc;
if (!fp || !*fp)
@@ -196,22 +196,22 @@ uc_fs_pclose(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_pread(uc_vm *vm, size_t nargs)
+uc_fs_pread(uc_vm_t *vm, size_t nargs)
{
return uc_fs_read_common(vm, nargs, "fs.proc");
}
static uc_value_t *
-uc_fs_pwrite(uc_vm *vm, size_t nargs)
+uc_fs_pwrite(uc_vm_t *vm, size_t nargs)
{
return uc_fs_write_common(vm, nargs, "fs.proc");
}
static uc_value_t *
-uc_fs_popen(uc_vm *vm, size_t nargs)
+uc_fs_popen(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *comm = uc_get_arg(0);
- uc_value_t *mode = uc_get_arg(1);
+ uc_value_t *comm = uc_fn_arg(0);
+ uc_value_t *mode = uc_fn_arg(1);
FILE *fp;
if (ucv_type(comm) != UC_STRING)
@@ -223,14 +223,14 @@ uc_fs_popen(uc_vm *vm, size_t nargs)
if (!fp)
err_return(errno);
- return uc_alloc_ressource(proc_type, fp);
+ return uc_ressource_new(proc_type, fp);
}
static uc_value_t *
-uc_fs_close(uc_vm *vm, size_t nargs)
+uc_fs_close(uc_vm_t *vm, size_t nargs)
{
- FILE **fp = uc_get_self("fs.file");
+ FILE **fp = uc_fn_this("fs.file");
if (!fp || !*fp)
err_return(EBADF);
@@ -242,26 +242,26 @@ uc_fs_close(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_read(uc_vm *vm, size_t nargs)
+uc_fs_read(uc_vm_t *vm, size_t nargs)
{
return uc_fs_read_common(vm, nargs, "fs.file");
}
static uc_value_t *
-uc_fs_write(uc_vm *vm, size_t nargs)
+uc_fs_write(uc_vm_t *vm, size_t nargs)
{
return uc_fs_write_common(vm, nargs, "fs.file");
}
static uc_value_t *
-uc_fs_seek(uc_vm *vm, size_t nargs)
+uc_fs_seek(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *ofs = uc_get_arg(0);
- uc_value_t *how = uc_get_arg(1);
+ uc_value_t *ofs = uc_fn_arg(0);
+ uc_value_t *how = uc_fn_arg(1);
int whence, res;
long offset;
- FILE **fp = uc_get_self("fs.file");
+ FILE **fp = uc_fn_this("fs.file");
if (!fp || !*fp)
err_return(EBADF);
@@ -289,11 +289,11 @@ uc_fs_seek(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_tell(uc_vm *vm, size_t nargs)
+uc_fs_tell(uc_vm_t *vm, size_t nargs)
{
long offset;
- FILE **fp = uc_get_self("fs.file");
+ FILE **fp = uc_fn_this("fs.file");
if (!fp || !*fp)
err_return(EBADF);
@@ -307,10 +307,10 @@ uc_fs_tell(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_open(uc_vm *vm, size_t nargs)
+uc_fs_open(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
- uc_value_t *mode = uc_get_arg(1);
+ uc_value_t *path = uc_fn_arg(0);
+ uc_value_t *mode = uc_fn_arg(1);
FILE *fp;
if (ucv_type(path) != UC_STRING)
@@ -322,14 +322,14 @@ uc_fs_open(uc_vm *vm, size_t nargs)
if (!fp)
err_return(errno);
- return uc_alloc_ressource(file_type, fp);
+ return uc_ressource_new(file_type, fp);
}
static uc_value_t *
-uc_fs_readdir(uc_vm *vm, size_t nargs)
+uc_fs_readdir(uc_vm_t *vm, size_t nargs)
{
- DIR **dp = uc_get_self("fs.dir");
+ DIR **dp = uc_fn_this("fs.dir");
struct dirent *e;
if (!dp || !*dp)
@@ -345,9 +345,9 @@ uc_fs_readdir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_telldir(uc_vm *vm, size_t nargs)
+uc_fs_telldir(uc_vm_t *vm, size_t nargs)
{
- DIR **dp = uc_get_self("fs.dir");
+ DIR **dp = uc_fn_this("fs.dir");
long position;
if (!dp || !*dp)
@@ -362,10 +362,10 @@ uc_fs_telldir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_seekdir(uc_vm *vm, size_t nargs)
+uc_fs_seekdir(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *ofs = uc_get_arg(0);
- DIR **dp = uc_get_self("fs.dir");
+ uc_value_t *ofs = uc_fn_arg(0);
+ DIR **dp = uc_fn_this("fs.dir");
long position;
if (ucv_type(ofs) != UC_INTEGER)
@@ -382,9 +382,9 @@ uc_fs_seekdir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_closedir(uc_vm *vm, size_t nargs)
+uc_fs_closedir(uc_vm_t *vm, size_t nargs)
{
- DIR **dp = uc_get_self("fs.dir");
+ DIR **dp = uc_fn_this("fs.dir");
if (!dp || !*dp)
err_return(EBADF);
@@ -396,9 +396,9 @@ uc_fs_closedir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_opendir(uc_vm *vm, size_t nargs)
+uc_fs_opendir(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
+ uc_value_t *path = uc_fn_arg(0);
DIR *dp;
if (ucv_type(path) != UC_STRING)
@@ -409,13 +409,13 @@ uc_fs_opendir(uc_vm *vm, size_t nargs)
if (!dp)
err_return(errno);
- return uc_alloc_ressource(dir_type, dp);
+ return uc_ressource_new(dir_type, dp);
}
static uc_value_t *
-uc_fs_readlink(uc_vm *vm, size_t nargs)
+uc_fs_readlink(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
+ uc_value_t *path = uc_fn_arg(0);
uc_value_t *res;
ssize_t buflen = 0, rv;
char *buf = NULL, *tmp;
@@ -453,9 +453,9 @@ uc_fs_readlink(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_stat_common(uc_vm *vm, size_t nargs, bool use_lstat)
+uc_fs_stat_common(uc_vm_t *vm, size_t nargs, bool use_lstat)
{
- uc_value_t *path = uc_get_arg(0);
+ uc_value_t *path = uc_fn_arg(0);
uc_value_t *res, *o;
struct stat st;
int rv;
@@ -537,22 +537,22 @@ uc_fs_stat_common(uc_vm *vm, size_t nargs, bool use_lstat)
}
static uc_value_t *
-uc_fs_stat(uc_vm *vm, size_t nargs)
+uc_fs_stat(uc_vm_t *vm, size_t nargs)
{
return uc_fs_stat_common(vm, nargs, false);
}
static uc_value_t *
-uc_fs_lstat(uc_vm *vm, size_t nargs)
+uc_fs_lstat(uc_vm_t *vm, size_t nargs)
{
return uc_fs_stat_common(vm, nargs, true);
}
static uc_value_t *
-uc_fs_mkdir(uc_vm *vm, size_t nargs)
+uc_fs_mkdir(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
- uc_value_t *mode = uc_get_arg(1);
+ uc_value_t *path = uc_fn_arg(0);
+ uc_value_t *mode = uc_fn_arg(1);
if (ucv_type(path) != UC_STRING ||
(mode && ucv_type(mode) != UC_INTEGER))
@@ -565,9 +565,9 @@ uc_fs_mkdir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_rmdir(uc_vm *vm, size_t nargs)
+uc_fs_rmdir(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
+ uc_value_t *path = uc_fn_arg(0);
if (ucv_type(path) != UC_STRING)
err_return(EINVAL);
@@ -579,10 +579,10 @@ uc_fs_rmdir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_symlink(uc_vm *vm, size_t nargs)
+uc_fs_symlink(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *dest = uc_get_arg(0);
- uc_value_t *path = uc_get_arg(1);
+ uc_value_t *dest = uc_fn_arg(0);
+ uc_value_t *path = uc_fn_arg(1);
if (ucv_type(dest) != UC_STRING ||
ucv_type(path) != UC_STRING)
@@ -595,9 +595,9 @@ uc_fs_symlink(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_unlink(uc_vm *vm, size_t nargs)
+uc_fs_unlink(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
+ uc_value_t *path = uc_fn_arg(0);
if (ucv_type(path) != UC_STRING)
err_return(EINVAL);
@@ -609,7 +609,7 @@ uc_fs_unlink(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_getcwd(uc_vm *vm, size_t nargs)
+uc_fs_getcwd(uc_vm_t *vm, size_t nargs)
{
uc_value_t *res;
char *buf = NULL, *tmp;
@@ -645,9 +645,9 @@ uc_fs_getcwd(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_chdir(uc_vm *vm, size_t nargs)
+uc_fs_chdir(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
+ uc_value_t *path = uc_fn_arg(0);
if (ucv_type(path) != UC_STRING)
err_return(EINVAL);
@@ -659,10 +659,10 @@ uc_fs_chdir(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_chmod(uc_vm *vm, size_t nargs)
+uc_fs_chmod(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
- uc_value_t *mode = uc_get_arg(1);
+ uc_value_t *path = uc_fn_arg(0);
+ uc_value_t *mode = uc_fn_arg(1);
if (ucv_type(path) != UC_STRING ||
ucv_type(mode) != UC_INTEGER)
@@ -769,11 +769,11 @@ uc_fs_resolve_group(uc_value_t *v, gid_t *gid)
}
static uc_value_t *
-uc_fs_chown(uc_vm *vm, size_t nargs)
+uc_fs_chown(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *path = uc_get_arg(0);
- uc_value_t *user = uc_get_arg(1);
- uc_value_t *group = uc_get_arg(2);
+ uc_value_t *path = uc_fn_arg(0);
+ uc_value_t *user = uc_fn_arg(1);
+ uc_value_t *group = uc_fn_arg(2);
uid_t uid;
gid_t gid;
@@ -791,10 +791,10 @@ uc_fs_chown(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_rename(uc_vm *vm, size_t nargs)
+uc_fs_rename(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *oldpath = uc_get_arg(0);
- uc_value_t *newpath = uc_get_arg(1);
+ uc_value_t *oldpath = uc_fn_arg(0);
+ uc_value_t *newpath = uc_fn_arg(1);
if (ucv_type(oldpath) != UC_STRING ||
ucv_type(newpath) != UC_STRING)
@@ -807,14 +807,14 @@ uc_fs_rename(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_fs_glob(uc_vm *vm, size_t nargs)
+uc_fs_glob(uc_vm_t *vm, size_t nargs)
{
uc_value_t *pat, *arr;
glob_t gl = { 0 };
size_t i;
for (i = 0; i < nargs; i++) {
- pat = uc_get_arg(i);
+ pat = uc_fn_arg(i);
if (ucv_type(pat) != UC_STRING) {
globfree(&gl);
@@ -835,14 +835,14 @@ uc_fs_glob(uc_vm *vm, size_t nargs)
}
-static const uc_cfunction_list proc_fns[] = {
+static const uc_function_list_t proc_fns[] = {
{ "read", uc_fs_pread },
{ "write", uc_fs_pwrite },
{ "close", uc_fs_pclose },
{ "error", uc_fs_error },
};
-static const uc_cfunction_list file_fns[] = {
+static const uc_function_list_t file_fns[] = {
{ "read", uc_fs_read },
{ "write", uc_fs_write },
{ "seek", uc_fs_seek },
@@ -851,7 +851,7 @@ static const uc_cfunction_list file_fns[] = {
{ "error", uc_fs_error },
};
-static const uc_cfunction_list dir_fns[] = {
+static const uc_function_list_t dir_fns[] = {
{ "read", uc_fs_readdir },
{ "seek", uc_fs_seekdir },
{ "tell", uc_fs_telldir },
@@ -859,7 +859,7 @@ static const uc_cfunction_list dir_fns[] = {
{ "error", uc_fs_error },
};
-static const uc_cfunction_list global_fns[] = {
+static const uc_function_list_t global_fns[] = {
{ "error", uc_fs_error },
{ "open", uc_fs_open },
{ "opendir", uc_fs_opendir },
@@ -904,15 +904,15 @@ static void close_dir(void *ud)
closedir(dp);
}
-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);
- proc_type = uc_declare_type("fs.proc", proc_fns, close_proc);
- file_type = uc_declare_type("fs.file", file_fns, close_file);
- dir_type = uc_declare_type("fs.dir", dir_fns, close_dir);
+ proc_type = uc_type_declare(vm, "fs.proc", proc_fns, close_proc);
+ file_type = uc_type_declare(vm, "fs.file", file_fns, close_file);
+ dir_type = uc_type_declare(vm, "fs.dir", dir_fns, close_dir);
- ucv_object_add(scope, "stdin", uc_alloc_ressource(file_type, stdin));
- ucv_object_add(scope, "stdout", uc_alloc_ressource(file_type, stdout));
- ucv_object_add(scope, "stderr", uc_alloc_ressource(file_type, stderr));
+ ucv_object_add(scope, "stdin", uc_ressource_new(file_type, stdin));
+ ucv_object_add(scope, "stdout", uc_ressource_new(file_type, stdout));
+ ucv_object_add(scope, "stderr", uc_ressource_new(file_type, stderr));
}
diff --git a/lib/math.c b/lib/math.c
index 8f8466e..c4a08e3 100644
--- a/lib/math.c
+++ b/lib/math.c
@@ -17,14 +17,14 @@
#include <math.h>
#include <sys/time.h>
-#include "../module.h"
+#include "ucode/module.h"
static bool srand_called = false;
static uc_value_t *
-uc_abs(uc_vm *vm, size_t nargs)
+uc_abs(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *v = uc_get_arg(0);
+ uc_value_t *v = uc_fn_arg(0);
uc_type_t t;
int64_t n;
double d;
@@ -32,7 +32,7 @@ uc_abs(uc_vm *vm, size_t nargs)
if (ucv_type(v) == UC_NULL)
return ucv_double_new(NAN);
- t = uc_to_number(v, &n, &d);
+ t = ucv_cast_number(v, &n, &d);
if (t == UC_DOUBLE)
return (isnan(d) || d < 0) ? ucv_double_new(-d) : ucv_get(v);
@@ -41,10 +41,10 @@ uc_abs(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_atan2(uc_vm *vm, size_t nargs)
+uc_atan2(uc_vm_t *vm, size_t nargs)
{
- double d1 = uc_to_double(uc_get_arg(0));
- double d2 = uc_to_double(uc_get_arg(1));
+ double d1 = ucv_to_double(uc_fn_arg(0));
+ double d2 = ucv_to_double(uc_fn_arg(1));
if (isnan(d1) || isnan(d2))
return ucv_double_new(NAN);
@@ -53,9 +53,9 @@ uc_atan2(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_cos(uc_vm *vm, size_t nargs)
+uc_cos(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -64,9 +64,9 @@ uc_cos(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_exp(uc_vm *vm, size_t nargs)
+uc_exp(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -75,9 +75,9 @@ uc_exp(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_log(uc_vm *vm, size_t nargs)
+uc_log(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -86,9 +86,9 @@ uc_log(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_sin(uc_vm *vm, size_t nargs)
+uc_sin(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -97,9 +97,9 @@ uc_sin(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_sqrt(uc_vm *vm, size_t nargs)
+uc_sqrt(uc_vm_t *vm, size_t nargs)
{
- double d = uc_to_double(uc_get_arg(0));
+ double d = ucv_to_double(uc_fn_arg(0));
if (isnan(d))
return ucv_double_new(NAN);
@@ -108,10 +108,10 @@ uc_sqrt(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_pow(uc_vm *vm, size_t nargs)
+uc_pow(uc_vm_t *vm, size_t nargs)
{
- double x = uc_to_double(uc_get_arg(0));
- double y = uc_to_double(uc_get_arg(1));
+ double x = ucv_to_double(uc_fn_arg(0));
+ double y = ucv_to_double(uc_fn_arg(1));
if (isnan(x) || isnan(y))
return ucv_double_new(NAN);
@@ -120,7 +120,7 @@ uc_pow(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_rand(uc_vm *vm, size_t nargs)
+uc_rand(uc_vm_t *vm, size_t nargs)
{
struct timeval tv;
@@ -135,9 +135,9 @@ uc_rand(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_srand(uc_vm *vm, size_t nargs)
+uc_srand(uc_vm_t *vm, size_t nargs)
{
- int64_t n = uc_to_int64(uc_get_arg(0));
+ int64_t n = ucv_to_integer(uc_fn_arg(0));
srand((unsigned int)n);
srand_called = true;
@@ -145,7 +145,7 @@ uc_srand(uc_vm *vm, size_t nargs)
return NULL;
}
-static const uc_cfunction_list math_fns[] = {
+static const uc_function_list_t math_fns[] = {
{ "abs", uc_abs },
{ "atan2", uc_atan2 },
{ "cos", uc_cos },
@@ -158,7 +158,7 @@ static const uc_cfunction_list math_fns[] = {
{ "srand", uc_srand },
};
-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, math_fns);
+ uc_function_list_register(scope, math_fns);
}
diff --git a/lib/ubus.c b/lib/ubus.c
index 4d74710..14e62de 100644
--- a/lib/ubus.c
+++ b/lib/ubus.c
@@ -19,7 +19,7 @@
#include <libubox/blobmsg.h>
#include <libubox/blobmsg_json.h>
-#include "../module.h"
+#include "ucode/module.h"
#define err_return(err) do { last_error = err; return NULL; } while(0)
@@ -33,7 +33,7 @@ typedef struct {
} ubus_connection;
static uc_value_t *
-uc_ubus_error(uc_vm *vm, size_t nargs)
+uc_ubus_error(uc_vm_t *vm, size_t nargs)
{
uc_value_t *errmsg;
@@ -47,10 +47,10 @@ uc_ubus_error(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_blob_to_json(uc_vm *vm, struct blob_attr *attr, bool table, const char **name);
+uc_blob_to_json(uc_vm_t *vm, struct blob_attr *attr, bool table, const char **name);
static uc_value_t *
-uc_blob_array_to_json(uc_vm *vm, struct blob_attr *attr, size_t len, bool table)
+uc_blob_array_to_json(uc_vm_t *vm, struct blob_attr *attr, size_t len, bool table)
{
uc_value_t *o = table ? ucv_object_new(vm) : ucv_array_new(vm);
uc_value_t *v;
@@ -77,7 +77,7 @@ uc_blob_array_to_json(uc_vm *vm, struct blob_attr *attr, size_t len, bool table)
}
static uc_value_t *
-uc_blob_to_json(uc_vm *vm, struct blob_attr *attr, bool table, const char **name)
+uc_blob_to_json(uc_vm_t *vm, struct blob_attr *attr, bool table, const char **name)
{
void *data;
int len;
@@ -131,10 +131,10 @@ uc_blob_to_json(uc_vm *vm, struct blob_attr *attr, bool table, const char **name
static uc_value_t *
-uc_ubus_connect(uc_vm *vm, size_t nargs)
+uc_ubus_connect(uc_vm_t *vm, size_t nargs)
{
- uc_value_t *socket = uc_get_arg(0);
- uc_value_t *timeout = uc_get_arg(1);
+ uc_value_t *socket = uc_fn_arg(0);
+ uc_value_t *timeout = uc_fn_arg(1);
uc_value_t *co;
ubus_connection *c;
@@ -168,7 +168,7 @@ uc_ubus_connect(uc_vm *vm, size_t nargs)
ubus_add_uloop(c->ctx);
- return uc_alloc_ressource(conn_type, c);
+ return uc_ressource_new(conn_type, c);
}
static void
@@ -199,10 +199,10 @@ uc_ubus_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p)
}
static uc_value_t *
-uc_ubus_list(uc_vm *vm, size_t nargs)
+uc_ubus_list(uc_vm_t *vm, size_t nargs)
{
- ubus_connection **c = uc_get_self("ubus.connection");
- uc_value_t *objname = uc_get_arg(0);
+ ubus_connection **c = uc_fn_this("ubus.connection");
+ uc_value_t *objname = uc_fn_arg(0);
uc_value_t *res = NULL;
enum ubus_msg_status rv;
@@ -237,12 +237,12 @@ uc_ubus_call_cb(struct ubus_request *req, int type, struct blob_attr *msg)
}
static uc_value_t *
-uc_ubus_call(uc_vm *vm, size_t nargs)
+uc_ubus_call(uc_vm_t *vm, size_t nargs)
{
- ubus_connection **c = uc_get_self("ubus.connection");
- uc_value_t *objname = uc_get_arg(0);
- uc_value_t *funname = uc_get_arg(1);
- uc_value_t *funargs = uc_get_arg(2);
+ ubus_connection **c = uc_fn_this("ubus.connection");
+ uc_value_t *objname = uc_fn_arg(0);
+ uc_value_t *funname = uc_fn_arg(1);
+ uc_value_t *funargs = uc_fn_arg(2);
uc_value_t *res = NULL;
json_object *o;
enum ubus_msg_status rv;
@@ -282,9 +282,9 @@ uc_ubus_call(uc_vm *vm, size_t nargs)
}
static uc_value_t *
-uc_ubus_disconnect(uc_vm *vm, size_t nargs)
+uc_ubus_disconnect(uc_vm_t *vm, size_t nargs)
{
- ubus_connection **c = uc_get_self("ubus.connection");
+ ubus_connection **c = uc_fn_this("ubus.connection");
if (!c || !*c || !(*c)->ctx)
err_return(UBUS_STATUS_CONNECTION_FAILED);
@@ -296,12 +296,12 @@ uc_ubus_disconnect(uc_vm *vm, size_t nargs)
}
-static const uc_cfunction_list global_fns[] = {
+static const uc_function_list_t global_fns[] = {
{ "error", uc_ubus_error },
{ "connect", uc_ubus_connect },
};
-static const uc_cfunction_list conn_fns[] = {
+static const uc_function_list_t conn_fns[] = {
{ "list", uc_ubus_list },
{ "call", uc_ubus_call },
{ "error", uc_ubus_error },
@@ -320,9 +320,9 @@ static void close_connection(void *ud) {
free(conn);
}
-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);
- conn_type = uc_declare_type("ubus.connection", conn_fns, close_connection);
+ conn_type = uc_type_declare(vm, "ubus.connection", conn_fns, close_connection);
}
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);
}