diff --git a/src/instead/instead.c b/src/instead/instead.c index 57356f68..38980e4b 100644 --- a/src/instead/instead.c +++ b/src/instead/instead.c @@ -735,12 +735,23 @@ static int luaB_print (lua_State *L) { for (i = 1; i <= n; i++) { /* for each argument */ size_t l; const char *s = luaL_tolstring(L, i, &l); /* convert it to string */ +#if LUA_VERSION_NUM >= 505 + if (i > 1) + fputs("\t", stdout); + fwrite(s, sizeof(char), l, stdout); +#else if (i > 1) /* not the first element? */ lua_writestring("\t", 1); /* add a tab before it */ lua_writestring(s, l); /* print it */ +#endif lua_pop(L, 1); /* pop result */ } +#if LUA_VERSION_NUM >= 505 + fputs("\n", stdout); + fflush(stdout); +#else lua_writeline(); +#endif return 0; } #endif diff --git a/stead/stead3/stead.lua b/stead/stead3/stead.lua index 843c6e85..ccac9a27 100644 --- a/stead/stead3/stead.lua +++ b/stead/stead3/stead.lua @@ -1533,9 +1533,9 @@ std.obj = std.class { for i = 1, #s.obj do local v = s.obj[i] - o, l, i = v:srch(w) + o, l, idx = v:srch(w) if o then - return o, l, i + return o, l, idx end end end; @@ -1547,9 +1547,9 @@ std.obj = std.class { end for i = 1, #s.obj do local v = s.obj[i] - o, l, i = v:lookup(w) + o, l, idx = v:lookup(w) if o then - return o, l, i + return o, l, idx end end end; diff --git a/tests/games/integration/main3.lua b/tests/games/integration/main3.lua index e55a70d0..58b94ddc 100644 --- a/tests/games/integration/main3.lua +++ b/tests/games/integration/main3.lua @@ -26,6 +26,24 @@ local function check_eq(name, got, want) end end +-- Recursive searches return the index in the containing list, not the parent. +local search_leaf = obj { nam = 'search_leaf' } +local search_inner = obj { + nam = 'search_inner', + obj = { obj { nam = 'search_filler' }, search_leaf }, +} +local search_root = obj { + nam = 'search_root', + obj = { search_inner }, +} +for _, method in ipairs { 'srch', 'lookup' } do + local o, l, idx = search_root[method](search_root, search_leaf) + check_eq(method .. " nested object", o, search_leaf) + check_eq(method .. " containing list", l, search_inner.obj) + check_eq(method .. " nested index", idx, 2) + check_eq(method .. " missing object", search_root[method](search_root, 'missing'), nil) +end + -- src/instead_paths.c check("instead_gamespath is a function", type(instead_gamespath) == "function") local gamespath = instead_gamespath()