lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sat, Nov 23, 2013 at 6:02 PM, Rena <hyperhacker@gmail.com> wrote:
> On Sat, Nov 23, 2013 at 9:00 PM, Craig Barnes <craigbarnes85@gmail.com>
> wrote:
>>
>> P.S. Why not use a table of functions?
>>
>>   local action = {
>>     Linux = function() print "Using Linux" end,
>>     Darwin = function() print "Using Darwin" end,
>
>        Unknown = function() print "No idea what you're using" end,
>>
>>     -- ...
>>   }
>>
>>   local fd = assert(io.popen("uname"))
>>   local os = assert(fd:read())
>>   fd:close()
>>
>>   (action[os] or action.Unknown)()
>>
>
> Always handle the edge cases.
>
> --
> Sent from my Game Boy.

Arguably one could say that the edge case was handled in that the
behavior was perfectly deterministic -- it would throw an error,
because it's an unsupported configuration. :P

/s/ Adam