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 /file.lua | |
parent | 5cce5115507800eeca7ba9c271e07c23473228f4 (diff) | |
download | lines.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 'file.lua')
-rw-r--r-- | file.lua | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/file.lua b/file.lua index 228f1f3..34be015 100644 --- a/file.lua +++ b/file.lua @@ -55,7 +55,7 @@ function load_drawing(infile_next_line) local drawing = {mode='drawing', h=256/2, points={}, shapes={}, pending={}} while true do local line = infile_next_line() - assert(line) + assert(line, 'drawing in file is incomplete') if line == '```' then break end local shape = json.decode(line) if shape.mode == 'freehand' then @@ -80,8 +80,7 @@ function load_drawing(infile_next_line) elseif shape.mode == 'deleted' then -- ignore else - print(shape.mode) - assert(false) + assert(false, ('unknown drawing mode %s'):format(shape.mode)) end table.insert(drawing.shapes, shape) end @@ -115,8 +114,7 @@ function store_drawing(outfile, drawing) elseif shape.mode == 'deleted' then -- ignore else - print(shape.mode) - assert(false) + assert(false, ('unknown drawing mode %s'):format(shape.mode)) end end outfile:write('```\n') @@ -152,7 +150,7 @@ function load_drawing_from_array(iter, a, i) local line while true do i, line = iter(a, i) - assert(i) + assert(i, 'drawing in array is incomplete') --? print(i) if line == '```' then break end local shape = json.decode(line) @@ -178,8 +176,7 @@ function load_drawing_from_array(iter, a, i) elseif shape.mode == 'deleted' then -- ignore else - print(shape.mode) - assert(false) + assert(false, ('unknown drawing mode %s'):format(shape.mode)) end table.insert(drawing.shapes, shape) end |