[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Question about metamethods
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Sun, 14 Feb 2016 14:58:26 +0000
2016-02-14 12:41 GMT+00:00 Geoff Smith <firstname.lastname@example.org>:
> 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.Cells.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"]["Cells"]["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
> alternatively suggest another variation on how to solve it ?
You can keep the original syntax for easier porting:
dgv1.Rows.Cells.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
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.