root/lu/LUProxy.lua

Revision 814 (checked in by rsz, 3 years ago)

cleanup

Line 
1 --------------------------------------------------------------------------------
2 -- Title:               LUProxy.lua
3 -- Description:         Like a square peg in a round hole
4 -- Author:              Raphaël Szwarc http://alt.textdrive.com/lua/
5 -- Creation Date:       February 1, 2005
6 -- Legal:               Copyright (C) 2005 Raphaël Szwarc
7 --------------------------------------------------------------------------------
8
9 -- import dependencies
10 local LUObject = require( "LUObject" )
11 local LULog = require( "LULog" )
12
13 -- define the class
14 local super = LUObject
15 local self = super()
16
17 -- class variable(s)
18 local _forward = {}
19
20 -- method for class initialization
21 function self:initialize()
22         super.initialize( self )
23
24         setmetatable( _forward, { __index = _G } )
25
26         self.__index =
27         function( anObject, aKey )
28                 local aValue = self[ aKey ]
29        
30                 if aValue == nil and aKey:byte( 1 ) ~= 95 then
31                         aValue = function( anObject, ... )
32                                 return anObject:forward( aKey, ... )
33                         end
34                        
35                         setfenv( aValue, _forward )
36                 end
37                
38                 return aValue
39         end
40                        
41         return self
42 end
43
44 -- method to forward invocations
45 function self:forward( aMethod, ... )
46         error( ( "'%s' does not implement method '%s'" ):format( self:className(), aMethod ) )
47 end
48
49  -- method to check if this object implements the given method name
50 function self:respondsTo( aMethod )
51         aMethod = self[ aMethod ]
52        
53         if type( aMethod ) == "function" and getfenv( aMethod ) ~= _forward  then
54                 return true
55         end
56        
57         return false
58 end
59
60 return self
Note: See TracBrowser for help on using the browser.