diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2023-11-18 11:30:57 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2023-11-18 11:32:01 -0800 |
commit | 007b965b11b681550ee2e2244a2f53e64e88697d (patch) | |
tree | e3bff0e0d71e896ea1d954ae7715f672b247bf0e /source_edit.lua | |
parent | 5cce5115507800eeca7ba9c271e07c23473228f4 (diff) | |
download | text.love-007b965b11b681550ee2e2244a2f53e64e88697d.tar.gz |
audit all asserts
Each one should provide a message that will show up within LÖVE. Stop relying on nearby prints to the terminal. I also found some unnecessary ones. There is some potential here for performance regressions: the format() calls will trigger whether or not the assertion fails, and cause allocations. So far Lua's GC seems good enough to manage the load even with Moby Dick, even in some situations that caused issues in the past like undo.
Diffstat (limited to 'source_edit.lua')
-rw-r--r-- | source_edit.lua | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/source_edit.lua b/source_edit.lua index 12c2bae..6259ebe 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -158,14 +158,8 @@ end function edit.draw(State, hide_cursor, show_line_numbers) State.button_handlers = {} App.color(Text_color) - if #State.lines ~= #State.line_cache then - print(('line_cache is out of date; %d when it should be %d'):format(#State.line_cache, #State.lines)) - assert(false) - end - if not Text.le1(State.screen_top1, State.cursor1) then - print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos) - assert(false) - end + assert(#State.lines == #State.line_cache, ('line_cache is out of date; %d elements when it should be %d'):format(#State.line_cache, #State.lines)) + assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)) State.cursor_x = nil State.cursor_y = nil local y = State.top @@ -209,8 +203,7 @@ function edit.draw(State, hide_cursor, show_line_numbers) Drawing.draw(State, line_index, y) y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottom else - print(line.mode) - assert(false) + assert(false, ('unknown line mode %s'):format(line.mode)) end end State.screen_bottom1 = screen_bottom1 |