From: Jo-Philipp Wich Date: Thu, 5 Nov 2015 17:47:34 +0000 (+0100) Subject: lua: fix invocation of foreach() with nil type and implicit self X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=commitdiff_plain;h=aaf9dff96d391f1d3fdc73dc5eb14b0d6b51085d;ds=sidebyside lua: fix invocation of foreach() with nil type and implicit self The check for nil on the 2nd argument misses the offset in order to skip over implicit self which results in `bad argument #2 to 'foreach' (string expected, got nil)` when invoking `uci.cursor():foreach("test", nil, function(s) end)`. The same call works fine when using dot instead of colon notation. Signed-off-by: Jo-Philipp Wich --- diff --git a/lua/uci.c b/lua/uci.c index 6ba7da0..1cb31a5 100644 --- a/lua/uci.c +++ b/lua/uci.c @@ -303,7 +303,7 @@ uci_lua_foreach(lua_State *L) ctx = find_context(L, &offset); package = luaL_checkstring(L, 1 + offset); - if (lua_isnil(L, 2)) + if (lua_isnil(L, 2 + offset)) type = NULL; else type = luaL_checkstring(L, 2 + offset);