[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Penlight 1.12.0 released
- From: Thijs Schreijer <thijs@...>
- Date: Wed, 12 Jan 2022 11:19:28 +0000
>> • feat: utils.enum added to create enums and prevent magic strings #408
>
> I'd like to see an example of the intended use for it (yes, we do
> overuse magic strings, which is efficient because of interning in Lua)
>
> steve d.
Hi Steve,
From the documentation:
-- accessing at runtime
local obj = {}
obj.MOVEMENT = utils.enum("FORWARD", "REVERSE", "LEFT", "RIGHT")
if current_movement == obj.MOVEMENT.FORWARD then
-- do something
elseif current_movement == obj.MOVEMENT.REVERES then
-- throws error due to typo 'REVERES', so a silent mistake becomes a hard error:
-- "'REVERES' is not a valid value (expected one of: 'FORWARD', 'REVERSE', 'LEFT', 'RIGHT')”
end
Hope that explains the use case.
Thijs