Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/instead/instead.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions stead/stead3/stead.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/games/integration/main3.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down