lua-users home
lua-l archive

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


Am 14.02.2016 um 13:41 schröbte Geoff Smith:

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 ?

    local PRIVATE, meta, unpack = {}, {}, table.unpack or unpack

    local function tcopy( t )
      local newt = {}
      for k,v in pairs( t ) do newt[ k ] = v end
      return newt, #newt
    end

    function meta:__index( k )
      local u, l = tcopy( self[ PRIVATE ] )
      u[ l+1 ] = k
      return setmetatable( { [ PRIVATE ] = u }, meta )
    end

    function meta:__newindex( k, v )
      local u, l = tcopy( self[ PRIVATE ] )
      u[ l+1 ] = k
      u[ l+2 ] = v
      u.f( unpack( u, 1, l+2 ) )
    end

    local function newf( f, ... )
      return setmetatable( { [ PRIVATE ] = { f = f, ... } }, meta )
    end

    -- test it:
    local o = {
      -- you can pass any function and it receives all keys and the
      -- final value as arguments (print is just for show):
      Rows = newf( print, "Rows" )
    }

    o.Rows[1].Cells[4].Style.BackColor = "Yellow"



Thanks Geoff


HTH,
Philipp