Thread: Window Chaining
View Single Post
03/07/14, 01:45 PM   #9
inDef
Join Date: Mar 2014
Posts: 16
Originally Posted by Lodur View Post
Code:
  CFP.TLW = CFP.BallAndChain( 
      WINDOW_MANAGER:CreateTopLevelWindow("CFP_BuffDisplay") )
    -- Return T
    -- Returns T, where T has the __index function on it's meta table built

    :SetHidden(true)
    -- step 1) lookup SetHidden via __index:
    -- return function( self , ... )
    -- tmp = T.__index(T, SetHidden) -- 1st anon function runs and returns the 2nd anon function

    -- Step 2) invoke function call:
    -- return self
    -- :tmp(true)  -- calls 2nd anon function which calls SetHidden on object and returns self (i.e. T)


    :SetDimensions(w,h)
    -- step 1) lookup SetDimensions via __index:
    -- return function( self , ... )
    -- tmp = T.__index(T, SetDimensions) -- 1st anon function runs and returns the 2nd anon function

    -- Step 2) invoke function call:
    -- return self
    -- :tmp(w,h)  -- calls 2nd anon function which calls SetDimensions on object and returns self (i.e. T)

  .__BALL
  -- step 1) lookup __BALL via __index:
  -- if func == "__BALL" then	return object end
  -- 1st anon function string matches __BALL names and then returns object.
  -- There is not invoke function call step as there are no parens after __BALL.
That is my understanding, at least...
This explained what was going on perfectly.

The key step I was missing is that "return function (self, ...)" is returning that actual function to some temp variable in memory. So once that is returned we're still left with a function call to tmp().

So if my understanding is right, for the SetHidden call we'd end up with something that looked like:

T.tmp(T, true). Since the function "tmp" IS defined for T (since it is explicitly defined right there in the call), tmp is executed...which calls Object.SetHidden(Object, true). It then returns "self" which T so the chain can continue. "Object" is the original window Object passed to the BallAndChain function

Does this sound right? If so, I think we've got the analysis of this tricky block of code down!!
  Reply With Quote