+static int
+uci_lua_cursor(lua_State *L)
+{
+ struct uci_context **u;
+ int argc = lua_gettop(L);
+
+ u = lua_newuserdata(L, sizeof(struct uci_context *));
+ luaL_getmetatable(L, METANAME);
+ lua_setmetatable(L, -2);
+
+ *u = uci_alloc_context();
+ if (!*u)
+ luaL_error(L, "Cannot allocate UCI context");
+ switch (argc) {
+ case 2:
+ if (lua_isstring(L, 2) &&
+ (uci_set_savedir(*u, luaL_checkstring(L, 2)) != UCI_OK))
+ luaL_error(L, "Unable to set savedir");
+ /* fall through */
+ case 1:
+ if (lua_isstring(L, 1) &&
+ (uci_set_confdir(*u, luaL_checkstring(L, 1)) != UCI_OK))
+ luaL_error(L, "Unable to set savedir");
+ break;
+ default:
+ break;
+ }