Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ABC
- -- DEF
- local f = io.open ( require('shell').resolve ('test'),'r')
- -- Works fine
- f:seek('set',7)
- print ( f:read('*line') )
- f:seek('set',0)
- print ( f:read('*line') )
- f:close ()
- local b = {
- ['resource']=nil,
- ['seek'] = {[1]=0},
- ['open'] = function ( self )
- self ['resource'] = io.open ( 'test', 'r' )
- end,
- }
- setmetatable ( b, {
- ['__index'] = function ( self, index )
- if self ['seek'][index] == nil then
- local tmpIndex = 1
- for i = index, 1, -1 do
- if self ['seek'][i] ~= nil then
- tmpIndex = i i = 0
- end
- end
- for i = tmpIndex, index, 1 do
- self ['resource']:seek ( 'set', self ['seek'][i] )
- local line = self ['resource']:read ('*line')
- self ['seek'][(i+1)] = self ['seek'][i] + #line + 1
- end
- end
- print ( 'seek', self['seek'][index] )
- self['resource']:seek ('set', self['seek'][index])
- return self['resource']:read('*line')
- end,
- } )
- b:open()
- print ( b[2] )
- print ( b[1] )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement