[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is string always same as number? (the consistency of lua)
- From: Axel Kittenberger <axkibe@...>
- Date: Thu, 10 Feb 2011 13:04:51 +0100
> A 'small hamming distance' is a nice way to say 'typo'.
Yup, but it sounds smarter in the first way.
> Lua programs are still very sensitive to spelling mistakes. In
> theory, Lua could be patched so that _no global_ accesses are allowed,
> except for some way to get 'imports' in. Then spelling mistakes will
> be genuine compile errors.
Not only in theory, I'm doing exactly that in my project after
initialization phase. It isnt yet a compile error but a runtime error,
but its better compared to some things becoming global by accident, or
something being nil just because of a typo. Dont ask me why it tests
for _ and __ I don't know, it was from the wiki.
----
-- Locks globals,
-- no more globals can be created
--
local function lockGlobals()
local t = _G
local mt = getmetatable(t) or {}
mt.__index = function(t, k)
if (k~="_" and string.sub(k, 1, 2) ~= "__") then
error("Access of non-existing global '"..k.."'", 2)
else
rawget(t, k)
end
end
mt.__newindex = function(t, k, v)
if (k~="_" and string.sub(k, 1, 2) ~= "__") then
error("Lsyncd does not allow GLOBALS to be created on the fly. " ..
"Declare '" ..k.."' local or declare global on load.", 2)
else
rawset(t, k, v)
end
end
setmetatable(t, mt)
end
Kind regards,
- References:
- Is string always same as number? (the consistency of lua), Xavier Wang
- Re: Is string always same as number? (the consistency of lua), Miles Bader
- Re: Is string always same as number? (the consistency of lua), Dirk Laurie
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), steve donovan
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), steve donovan
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), steve donovan
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), Paul Hudson
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), steve donovan
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), steve donovan