Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function makeProxyWrapper( proxy, key )
- local func = proxy._file[ key ] -- find the value
- if( type( func ) == "function" ) then -- if it really is a function
- return function( proxy, ... ) -- then we return a wrapper instead
- return func( proxy._file, ... )
- end
- end
- return func -- else we return the value unchanged
- end
- function newFileProxy( name, mode ) -- this will be the constructor
- local proxy = { _file = io.open ( name , mode ) } -- This is the file proxy table
- local meta = { __index = makeProxyWrapper }
- setmetatable( proxy, meta )
- return proxy
- end
- fproxy = newFileProxy( "/path/to/lua_test_file", "r" )
- number, line, fifteen_chars, rest = fproxy:read( "*n", "*l", 15, "*a" )
- print( "Number: " .. number )
- print( "Line: " .. line )
- print( "15: " .. fifteen_chars )
- print( "Rest: " .. rest )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement