[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: string.len(str) vs str:len()
- From: Elias Barrionovo <elias.tandel@...>
- Date: Thu, 7 Aug 2014 14:42:49 -0300
On Thu, Aug 7, 2014 at 2:35 PM, Mason Mackaman <masondeanm@aol.com> wrote:
> So does some equivalent of "local getmetatable('').__index=_ENV.string” execute before the program starts?
Yes! More like `setmetatable("", {__index = string})`, actually:
http://www.lua.org/source/5.2/lstrlib.c.html#createmetatable
Just one more example of how Lua doesn't care about string when using __index:
Lua 5.2.3 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> str = "hello"
> print(str:len())
5
> string = nil
> print(string.len(str)) -- no more string, so blows up
stdin:1: attempt to index global 'string' (a nil value)
stack traceback:
stdin:1: in main chunk
[C]: in ?
> print(str:len()) -- __index remains untouched
5
--
NI!
() - www.asciiribbon.org
/\ - ascii ribbon campaign against html e-mail and proprietary attachments
- References:
- string.len(str) vs str:len(), Mason Mackaman
- Re: string.len(str) vs str:len(), Thiago L.
- Re: string.len(str) vs str:len(), Mason Mackaman
- Re: string.len(str) vs str:len(), Thiago L.
- Re: string.len(str) vs str:len(), Mason Mackaman
- Re: string.len(str) vs str:len(), Coda Highland
- Re: string.len(str) vs str:len(), Thiago L.
- Re: string.len(str) vs str:len(), Mason Mackaman
- Re: string.len(str) vs str:len(), Coda Highland
- Re: string.len(str) vs str:len(), Mason Mackaman
- Re: string.len(str) vs str:len(), Mason Mackaman
- Re: string.len(str) vs str:len(), Mason Mackaman