lua-users home
lua-l archive

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


> My solution, in code, is to agree to use the "ugly" syntax and go on with my life.

I generally do the same, but if keeping "good looking" names is highly
desirable, then Rena's suggestion to convert attribute names before
writing out has two benefits: (1) you can convert various formats into
whatever you need (stroke_width and strokeWidth into stroke-width) and
(2) you can check the attribute name against "correct" list to avoid
generating invalid output (for example, misspelling "fill" as "fil").

Paul.

On Wed, Sep 3, 2014 at 5:19 AM, Pierre Chapuis <catwell@archlinux.us> wrote:
>>> I can make a function call as
>>> svg.rectangle{ width=100, height=42, fill="black" }
>>> But attributes with a dash require the ugly syntax
>>> svg.rectangle{ fill="black", ["stroke-width"]=1.337 }
>
>> My solution has usually been to write it as stroke_width and then
>> gsub('_', '-') before writing.
>
> For what it's worth this also happens with things like
> HTTP headers. My solution, in code, is to agree to use the
> "ugly" syntax and go on with my life.
>
> If you never have underscores in key names, the above
> solution can also work pretty well.
>
>