projects
/
oweals
/
uci.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
7d69106
)
push out uci error messages to lua as well
author
Felix Fietkau
<nbd@openwrt.org>
Wed, 27 Aug 2008 20:05:54 +0000
(22:05 +0200)
committer
Felix Fietkau
<nbd@openwrt.org>
Wed, 27 Aug 2008 20:05:54 +0000
(22:05 +0200)
lua/uci.c
patch
|
blob
|
history
diff --git
a/lua/uci.c
b/lua/uci.c
index 567b44c8caf7f1937bf33ae955778391b0d68505..2d81a38b98c95375ac8302231d4d865e365a8a47 100644
(file)
--- a/
lua/uci.c
+++ b/
lua/uci.c
@@
-97,20
+97,6
@@
done:
return p;
}
return p;
}
-static void
-uci_lua_perror(lua_State *L, struct uci_context *ctx, char *name)
-{
- lua_getfield(L, LUA_GLOBALSINDEX, "uci");
- lua_getfield(L, -1, "warn");
- if (!lua_isboolean(L, -1))
- goto done;
- if (lua_toboolean(L, -1) != 1)
- goto done;
- uci_perror(ctx, name);
-done:
- lua_pop(L, 2);
-}
-
static int
lookup_args(lua_State *L, struct uci_context *ctx, int offset, struct uci_ptr *ptr, char **buf)
{
static int
lookup_args(lua_State *L, struct uci_context *ctx, int offset, struct uci_ptr *ptr, char **buf)
{
@@
-156,6
+142,24
@@
error:
return 1;
}
return 1;
}
+static int
+uci_push_status(lua_State *L, struct uci_context *ctx, bool hasarg)
+{
+ char *str = NULL;
+
+ if (!hasarg)
+ lua_pushboolean(L, (ctx->err == UCI_OK));
+ if (ctx->err) {
+ uci_get_errorstr(ctx, &str, MODNAME);
+ if (str) {
+ lua_pushstring(L, str);
+ free(str);
+ return 2;
+ }
+ }
+ return 1;
+}
+
static void
uci_push_option(lua_State *L, struct uci_option *o)
{
static void
uci_push_option(lua_State *L, struct uci_option *o)
{
@@
-228,7
+232,7
@@
uci_lua_unload(lua_State *L)
p = find_package(L, ctx, s, false);
if (p) {
uci_unload(ctx, p);
p = find_package(L, ctx, s, false);
if (p) {
uci_unload(ctx, p);
-
lua_pushboolean(L, 1
);
+
return uci_push_status(L, ctx, false
);
} else {
lua_pushboolean(L, 0);
}
} else {
lua_pushboolean(L, 0);
}
@@
-248,14
+252,8
@@
uci_lua_load(lua_State *L)
lua_pop(L, 1); /* bool ret value of unload */
s = lua_tostring(L, -1);
lua_pop(L, 1); /* bool ret value of unload */
s = lua_tostring(L, -1);
- if (uci_load(ctx, s, &p)) {
- uci_lua_perror(L, ctx, "uci.load");
- lua_pushboolean(L, 0);
- } else {
- lua_pushboolean(L, 1);
- }
-
- return 1;
+ uci_load(ctx, s, &p);
+ return uci_push_status(L, ctx, false);
}
}
@@
-349,17
+347,8
@@
error:
if (s)
free(s);
if (s)
free(s);
- switch(err) {
- default:
- ctx->err = err;
- uci_lua_perror(L, ctx, "uci.get");
- /* fall through */
- case UCI_ERR_NOTFOUND:
- lua_pushnil(L);
- /* fall through */
- case 0:
- return 1;
- }
+ lua_pushnil(L);
+ return uci_push_status(L, ctx, true);
}
static int
}
static int
@@
-401,7
+390,7
@@
uci_lua_add(lua_State *L)
fail:
lua_pushnil(L);
fail:
lua_pushnil(L);
- return
1
;
+ return
uci_push_status(L, ctx, true)
;
}
static int
}
static int
@@
-423,10
+412,7
@@
uci_lua_delete(lua_State *L)
error:
if (s)
free(s);
error:
if (s)
free(s);
- if (err)
- uci_lua_perror(L, ctx, "uci.delete");
- lua_pushboolean(L, (err == 0));
- return 1;
+ return uci_push_status(L, ctx, false);
}
static int
}
static int
@@
-496,10
+482,7
@@
uci_lua_set(lua_State *L)
}
error:
}
error:
- if (err)
- uci_lua_perror(L, ctx, "uci.set");
- lua_pushboolean(L, (err == 0));
- return 1;
+ return uci_push_status(L, ctx, false);
}
enum pkg_cmd {
}
enum pkg_cmd {
@@
-553,8
+536,7
@@
uci_lua_package_cmd(lua_State *L, enum pkg_cmd cmd)
}
err:
}
err:
- lua_pushboolean(L, !failed);
- return 1;
+ return uci_push_status(L, ctx, false);
}
static int
}
static int
@@
-687,8
+669,7
@@
uci_lua_set_confdir(lua_State *L)
ctx = find_context(L, &offset);
luaL_checkstring(L, 1 + offset);
ret = uci_set_confdir(ctx, lua_tostring(L, -1));
ctx = find_context(L, &offset);
luaL_checkstring(L, 1 + offset);
ret = uci_set_confdir(ctx, lua_tostring(L, -1));
- lua_pushboolean(L, (ret == 0));
- return 1;
+ return uci_push_status(L, ctx, false);
}
static int
}
static int
@@
-708,9
+689,7
@@
uci_lua_set_savedir(lua_State *L)
ctx = find_context(L, &offset);
luaL_checkstring(L, 1 + offset);
ret = uci_set_savedir(ctx, lua_tostring(L, -1));
ctx = find_context(L, &offset);
luaL_checkstring(L, 1 + offset);
ret = uci_set_savedir(ctx, lua_tostring(L, -1));
- lua_pushboolean(L, (ret == 0));
-
- return 1;
+ return uci_push_status(L, ctx, false);
}
static int
}
static int