lua-users home
lua-l archive

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


On Apr 28, 2011, at 6:45 PM, HyperHacker wrote:

> Another pattern you can use for private data is a local/hidden table indexed
> by your object. E.g.:

Yes, using an upvalue is handy.

FWIW, here is a more full fledge example [1]:

(1) Create an upvalue to hold various private data 
local context = setmetatable( {}, { __mode = 'k' } )

(2) Initialize a given data set 
 context[ aToken ] = aContext

(3) Access the private data 
    return ID( context[ self ] )

[1] http://dev.alt.textdrive.com/browser/HTTP/Token.lua