diff --git a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua index 8ac9674dd..fb4820be8 100644 --- a/src/main/resources/assets/computercraft/lua/rom/apis/window.lua +++ b/src/main/resources/assets/computercraft/lua/rom/apis/window.lua @@ -388,14 +388,14 @@ function create( parent, nX, nY, nWidth, nHeight, bStartVisible ) return nBackgroundColor end - function window.getLine( nY ) - if type(nY) ~= "number" then expect(1, nY, "number") end + function window.getLine(y) + if type(y) ~= "number" then expect(1, y, "number") end - if nY < 1 or nY > nHeight then - error( "Line is out of range.", 2 ) + if y < 1 or y > nHeight then + error("Line is out of range.", 2) end - return tLines[nY].text, tLines[nY].textColor, tLines[nY].backgroundColor + return tLines[y].text, tLines[y].textColor, tLines[y].backgroundColor end -- Other functions diff --git a/src/test/resources/test-rom/spec/apis/window_spec.lua b/src/test/resources/test-rom/spec/apis/window_spec.lua index b6102e841..2fb6d119d 100644 --- a/src/test/resources/test-rom/spec/apis/window_spec.lua +++ b/src/test/resources/test-rom/spec/apis/window_spec.lua @@ -130,5 +130,11 @@ describe("The window library", function() expect.error(w.getLine, 0):eq("Line is out of range.") expect.error(w.getLine, y + 1):eq("Line is out of range.") end) + + it("provides a line's contents", function() + local w = mk() + w.blit("test", "aaaa", "4444") + expect({ w.getLine(1) }):same { "test ", "aaaa0", "4444f" } + end) end) end)