lua-users home
lua-l archive

Re: [local] <namelist> = do <block> =<explist> end

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


On 18/08/15 03:11 PM, Dirk Laurie wrote:
2015年08月18日 19:14 GMT+02:00 Soni L. <fakedme@gmail.com>:
I'd like a way to do
local v
do v = 3 end
without assigning nil to v.
You can't have that in principle. No name can ever not be
associated to a value. If you don't do
local v=3
(why on earth don't you?) then Lua explicitly supplies the nil.
Otherwise that slot would contain whatever was in it before
(which may be a user's unencrypted password) and all sorts
of security holes open up.
The basic idea /is/ to do local v=3, but also run some code inbetween.
local v = (function() return 3 end)() lets you run code inbetween, but "v" doesn't get assigned nil: it gets assigned whatever the function returns.
--
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.

AltStyle によって変換されたページ (->オリジナル) /