Advertisement
Guest User

Per Bull Holmen

a guest
Feb 14th, 2010
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. local function makeProxyWrapper( proxy, key )
  2.     local func = proxy._file[ key ]       -- find the value
  3.     if( type( func ) == "function" ) then -- if it really is a function
  4.         return function( proxy, ... )     -- then we return a wrapper instead
  5.                     return func( proxy._file, ... )
  6.                end
  7.     end
  8.     return func                           -- else we return the value unchanged
  9. end
  10.  
  11. function newFileProxy( name, mode )       -- this will be the constructor
  12.     local proxy = { _file = io.open ( name , mode ) } -- This is the file proxy table
  13.     local meta = { __index = makeProxyWrapper }
  14.     setmetatable( proxy, meta )
  15.     return proxy
  16. end
  17.  
  18. fproxy = newFileProxy( "/path/to/lua_test_file", "r" )
  19.  
  20. number, line, fifteen_chars, rest = fproxy:read( "*n", "*l", 15, "*a" )
  21.  
  22. print( "Number: " .. number )
  23. print( "Line: " .. line )
  24. print( "15: " .. fifteen_chars )
  25. print( "Rest: " .. rest )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement