[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ["all"] as an Lvalue?
- From: Jonathan Goble <jcgoble3@...>
- Date: Mon, 28 Mar 2016 21:00:04 -0400
On Mon, Mar 28, 2016 at 8:55 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> =====================================================
> domain_props = {
> ["all"] = {
> enable_scripts = false,
> enable_plugins = false,
> enable_private_browsing = false,
> user_stylesheet_uri = "",
> },
> ["youtube.com"] = {
> enable_scripts = true,
> enable_plugins = true,
> },
> }
> =====================================================
>
> It looks like domain_props is a table whose two elements are each
> tables, named ["all"] and ["youtube.com"] respectively. I've never seen
> something like ["all"] being the name of a table element or a variable
> name before. What's going on, is ["all"] an anonymous table containing
> element "all"? I just don't understand this syntax, and why somebody
> would do this. What am I missing?
No, the keys are ordinary string values. So the first one could also
be accessed as `domain_props.all`. The `[]` syntax here is just a way
to use an arbitrary expression as a table key; it's not needed for
"all", since that is a valid identifier, but it is necessary to use
the string "youtube.com" as a table key, since that string is not a
valid identifier.
Thus, this piece of code could also be written as:
domain_props = {
all = {
["enable_scripts"] = false,
["enable_plugins"] = false,
enable_private_browsing = false,
user_stylesheet_uri = "",
},
["youtube.com"] = {
enable_scripts = true,
["enable_plugins"] = true,
},
}
Both domain_props tables, in your example and mine, are exactly identical.