GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing gilzoide.github.io — Reference Module
|
| new (callable_or_file[, options[, ...]]) | Create a new stringstream from callable object or file-like object. |
| open (filename[, ...]) | Creates a new stream from file. |
| sub (i[, j]) | Returns a substring or a new view into stream. |
| find (pattern[, init[, plain]]) | Try finding pattern on loaded contents. |
| match (pattern[, init]) | Try matching pattern on loaded contents. |
| gmatch (pattern[, init]) | Returns an iterator function that, each time it is called, returns the next match from loaded contents. |
| __tostring () | Returns the current loaded content string. |
| __len () | Returns the current loaded content length. |
| len () | Alias for stringstream:__len |
| readsize | Default read size of streams created with file objects. |
| max_find_lookahead | Default maximum number of bytes that stringstream:find may load. |
| _VERSION | Module version. |
Both functions and tables or userdata with a __call metamethod are
accepted as callables. Just like load, each call must return a string that
concatenates with previous results and a return of an empty string or a falsey
value signals the end of the stream.
File-like objects are tables or userdata with a read method.
Chunks will be read calling the read method as in object:read(...).
callable_or_file is a file and no extra arguments are passed, stringstream.readsize will be used
(optional)
-- stream that reads chunks of 1024 bytes from opened file -- and retries find as many times as necessary stream = stringstream.new(io.open('file')) -- stream that reads lines from stdin and fails a search after -- having more than 4096 bytes loaded stream = stringstream.new(io.stdin, { max_find_lookahead = 4096 }, '*l') -- stream that generates digits from 1 to 10 local gen_numbers = coroutine.wrap(function() for i = 1, 10 do coroutine.yield(tostring(i)) end end) stream = stringstream.new(gen_numbers)
Opens the file with io.open in read mode and forward parameters to stringstream.new.
-- stream that reads chunks of 1024 bytes from 'file.txt' -- and loads the entire contents on a call to find, if necessary stream = stringstream.open('file.txt') -- stream that reads lines from 'file.txt' -- and loads the entire contents on a call to find, if necessary stream = stringstream.open('file.txt', nil, '*l')
If both i and j are passed, returns the substring that starts at i
and continues until j or until the end of stream.
Otherwise, returns a new stringstream object with starting index i.
j is not passed and i is not past the end of the stream
j is not passed in and i is past the end of the stream
j is passed in
i or j are non-positive, as reading from the end of
stream is not supported.
pattern on loaded contents.
Upon failure or if match spans the entire loaded content, loads new chunks,
bailing out after having more than max_find_lookahead bytes loaded
counting from init, returning nil afterwards.
Notice that the default value for max_find_lookahead makes the whole stream be loaded in case of failures or big matches. This is to have consistent output between stringstream and the string API by default.
init is a negative number.
pattern on loaded contents.
Uses stringstream:find for searching, so the same caveats apply.
init is a negative number.
Uses stringstream:find for searching, so the same caveats apply.
init is a negative number.
Be careful that it almost never reflects the entire content string.
Be careful that it almost never reflects the entire content length.
Change this to configure defaults module-wise. Default value is 1024.
Change this to configure defaults module-wise. Default value is math.huge, that is, load until stream is completely consumed, if necessary.