lua-users home
lua-l archive

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


2016-02-14 12:41 GMT+00:00 Geoff Smith <spammealot1@live.co.uk>:
> I am wondering if  __index & __newindex metamethods can be used to solve
> this slightly complex specific problem
>
> [...]
>
> My preferred lua syntax mimics the C# line, so I would like to trigger a
> call to that function with something like
>
>
>   dgv1.Rows[1].Cells[4].Style.BackColor = "Yellow";
>
>
> I suspect this probably isnt possible, can anyone prove me wrong ?

Just in case the other answers to your post are as confusing to you as
they are to me, the simple answer is: yes, it is possible. The above
is equivalent to this:

dgv1["Rows"][1]["Cells"][4]["Style"]["BackColor"] = "Yellow"

So you need dgv1 to have an __index that accepts a string "Rows" as
argument and returns another object. Repeat that for keys 1, "Cells",
4 and "Style". That last Style object should have a __newindex that
accepts the string "BackColor" as key and the string "Yellow" as
value.

> Or
> alternatively suggest another variation on how to solve it ?

You can keep the original syntax for easier porting:

dgv1.Rows[1].Cells[4].Style.BackColor = Color.Yellow

The advantage is you can keep a minimal namespace for the name
"Yellow", instead of having a global association of that name to a
color object.

Intuitively I would expect your C#/.NET binding to let you have such a
syntax already. So before you dismiss it and roll your own, I'd
suggess looking really hard for it.