[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to check for key existence in a table (for the lazy programmer) ?
- From: "Soni L." <fakedme@...>
- Date: Sat, 31 Jan 2015 16:29:30 -0200
On 31/01/15 08:45 AM, Bertrand Mansion wrote:
In Lua programs, I often see code like the following:
if host.devices and host.devices.bridge and host.devices.bridge.friendlyName then
If Lua could use assignments as expressions, we could have things like this:
local temp;
if (temp = host.devices) and (temp = temp.bridge) and (temp =
temp.friendlyName) then
Which's _WAY_ faster.
(Does anyone know if moonscript or something supports this?)
In Php, I have seen this:
if (isset($host['devices']['bridge']['friendlyName']))
In Python, I have seen this:
try:
if host['devices']['bridge']['friendlyName']:
...
except KeyError:
pass
Are there other ways in Lua to check for a key existence ?
--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.