lua-users home
lua-l archive

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


On Mon, Mar 28, 2016 at 5:55 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> Hi all,
>
> I'm writing a document on Luakit, and in my section on making fonts
> bigger, I need to give instructions to edit the domain_props table,
> which looks something like this:
>
> =====================================================
> 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?
>
> Thanks,
>
> SteveT
>
> Steve Litt
> March 2016 featured book: Quit Joblessness: Start Your Own Business
> http://www.troubleshooters.com/startbiz
>

The [] is the syntax for using an expression for a table key. Some
people use it even for simple strings just so they don't have to have
something different if they have a key that happens to be a Lua
reserved word. (This is particularly relevant for configuration files
that might be modified by non-Lua-programmers.)

/s/ Adam