lua_newtable(L);
if (package) {
uci_lua_changes_pkg(L, ctx, package);
- } else {
- if (uci_list_configs(ctx, &config) != 0)
- goto done;
+ return 1;
+ }
- for(i = 0; config[i] != NULL; i++) {
- uci_lua_changes_pkg(L, ctx, config[i]);
- }
+ if ((uci_list_configs(ctx, &config) != UCI_OK) || !config)
+ return 1;
+
+ for (i = 0; config[i] != NULL; i++) {
+ uci_lua_changes_pkg(L, ctx, config[i]);
}
-done:
+ free(config);
return 1;
}
--- /dev/null
+local A = assert
+local c = uci.cursor(os.getenv("CONFIG_DIR"))
+
+A(c:set("network", "lan", "dns", {
+ "ns1.king.banik.cz",
+ "ns2.openwrt.org",
+}))
+
+local changes = c:changes()
+A(changes.network.lan.dns[1] == "ns1.king.banik.cz")
+A(changes.network.lan.dns[2] == "ns2.openwrt.org")
--- /dev/null
+set LUA_CPATH and ucilua for convenience:
+
+ $ [ -n "$UCI_LUA" ] && export LUA_CPATH="$(dirname "$UCI_LUA")/?.so"
+ $ alias ucilua="valgrind --quiet --leak-check=full lua -luci"
+
+check that changes method doesnt leak memory:
+
+ $ cp -R "$TESTDIR/config" .
+ $ export CONFIG_DIR=$(pwd)/config
+ $ ucilua $TESTDIR/lua/test_cases/changes_doesnt_leak.lua