diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2010-10-15 09:49:24 +0000 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2010-10-15 09:49:24 +0000 |
commit | 6cf12867f2d5e078d9a988607315a8257380d8ba (patch) | |
tree | edd43bbc04135d1c61a6b2a29970a6af5b775eeb | |
parent | 297174b1e89f882f7bfd1767484f14fa863ad3a9 (diff) | |
download | lua-augeas-6cf12867f2d5e078d9a988607315a8257380d8ba.tar.bz2 lua-augeas-6cf12867f2d5e078d9a988607315a8257380d8ba.tar.xz |
implement match() and matches()
-rw-r--r-- | laugeas.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -1,3 +1,5 @@ +#include <stdlib.h> + #include <lua.h> #include <lualib.h> #include <lauxlib.h> @@ -193,6 +195,35 @@ static int Paug_mv(lua_State *L) return pushresult(L, aug_mv(a, src, dst), a, NULL); } +static int Paug_matches(lua_State *L) +{ + augeas *a = Paug_checkarg(L, 1); + const char *path = luaL_checkstring(L, 2); + return pushresult(L, aug_match(a, path, NULL), a, path); +} + +static int Paug_match(lua_State *L) +{ + augeas *a = Paug_checkarg(L, 1); + const char *path = luaL_checkstring(L, 2); + char **match = NULL; + int i, n; + n = aug_match(a, path, &match); + if (n < 0) + return pusherror(L, a, path); + + lua_newtable(L); + for (i = 0; i < n; i++) { + lua_pushnumber(L, i+1); + lua_pushstring(L, match[i]); + lua_settable(L, -3); + free(match[i]); + } + free(match); + lua_pushinteger(L, n); + return 2; +} + static int Paug_save(lua_State *L) { augeas *a = Paug_checkarg(L, 1); @@ -228,6 +259,8 @@ static const luaL_reg Paug_methods[] = { {"insert", Paug_insert}, {"rm", Paug_rm}, {"mv", Paug_mv}, + {"matches", Paug_matches}, + {"match", Paug_match}, {"save", Paug_save}, {"load", Paug_load}, {"print", Paug_print}, |