lua-users home
lua-l archive

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


On Wed, Feb 17, 2010 at 1:48 AM, Alex Davies <alex.mania@iinet.net.au> wrote:
> Peter Cawley wrote:
>> function how(s, x) return debug.getinfo(1).namewhat == "method" and
>> ":" or "." end
>> t = {how = how}
>> print(t.how()) --> .
>> print(t:how()) --> :
>
> Except that then breaks legitimate uses, ie when caching the function lookup
> for a tight inner loop.
>
> local setAngle = bot.setAngle
> for angle = 0,math.pi,0.0001 do
>  setAngle(bot, angle)
> end

In your particular example, namewhat would be "local", rather than
"field" or "method". Whilst you could use my suggestion to force every
call to be via : notation, I intended it to be used *after* you've
realised that your parameters are wrong, to try and tell the user why,
in which case it cannot break any legitimate uses.