lua-users home
lua-l archive

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




On 14/02/16 10:41 AM, Geoff Smith wrote:


Hi


I am wondering if __index & __newindex metamethods can be used to solve this slightly complex specific problem


I am trying to wire up Lua to a Windows Gui function. Lets take an example in C#


my C# line inside my binding function is


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


The binding function is called from Lua as below


gridSetStyle(1, 4, luaStyleTable)


Where arg 1 is rowIndex,  arg 2 is CellIndex and


arg 3 luaStyleTable  is { BackColor = Yellow}


this works but the syntax in Lua isnt nice to require the line gridSetStyle(1, 4, luaStyleTable)


What I am trying to do is get Lua to have a metamethod that triggers and calls that function in the background


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 ? Or alternatively suggest another variation on how to solve it ?


Thanks Geoff





Why not dgv1[1][4].Style.BackColor = "Yellow"?

dgv1 would have an __index function that checks if the argument is a number. if it is, it attempts to index Rows with it, otherwise it does something else.

dgv1[1] would have an __index function that checks if the argument is a number. if it is, it attempts to index Cells with it, otherwise it does something else.

dgv1[1][4] would have an __index function.

dgv1[1][4].Style would have a __newindex function.

Using functions and userdata instead of tables means you can have it dynamically update and thus reflect the internal state better.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.