lua-users home
lua-l archive

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




On 17/12/15 09:25 PM, Thijs Schreijer wrote:
I ran into the following;

local v = {type = "timestamp"}                          -- added to run it
if v.type == "number" or v .type == "timestamp" then    -- actual code
end



Notice above, the second `v.type` has a typo with an extra space; `v .type`. I'd expected an error, but it runs fine.

Why?

Thijs


What if you replace .name with ["name"]? It becomes `v ["type"]`.

You can add spaces around . in many languages, including C, C++ and Java. You can even add line breaks! E.g.

local dog = DogBuilder() -- Also works when using :
            . setName "Doggy"
            . setType "Poodle"
            . build()

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.