require editor margins to be ints

Not directly relevant here, but forks of this project that permit
zooming can run into weird glitches if margins are not a whole number of
pixels.

I'd always assumed a type system that divided ints into floats was
strictly superior, but now I have experienced a situation where
requiring ints isn't just a compromise for the underlying CPU
implementation. Particularly since Lua's print() silently hides really
tiny fractions.
This commit is contained in:
Kartik K. Agaram 2022-12-23 16:57:04 -08:00
parent df0aec10d0
commit e2e3aea2b1
2 changed files with 5 additions and 2 deletions

View File

@ -46,6 +46,9 @@ Lua is dynamically typed. Tests can't patch over lack of type-checking.
* Like any high-level language, it's easy to accidentally alias two non-scalar
variables. I wish there was a way to require copy when assigning.
* I wish I could require pixel coordinates to integers. The editor defensively
converts input margins to integers.
* My test harness automatically runs `test_*` methods -- but only at the
top-level. I wish there was a way to raise warnings if someone defines such
a function inside a dict somewhere.

View File

@ -90,8 +90,8 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
em = App.newText(love.graphics.getFont(), 'm'), -- widest possible character width
top = top,
left = left,
right = right,
left = math.floor(left),
right = math.floor(right),
width = right-left,
filename = love.filesystem.getUserDirectory()..'/lines.txt', -- '/' should work even on Windows