| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
An object that loads chunks of strings on demand compatible with a subset of the Lua string API suitable for parsing. Compatible with Lua 5.1+
Useful for passing streams (e.g.: files) to parser functionality that expects strings and use method notation (text:match(...)).
It is available as a LuaRocks package and has online documentation:
$ luarocks install stringstream
Or just copy stringstream.lua into your Lua path and require it, the module has no dependencies.
local stringstream = require 'stringstream'
-- Streams may be created with callable objects (functions or tables/userdata
-- with __call metamethod) like the ones `load` expects, or file-like objects
-- that contain a `read` method, like open files.
local stream = assert(stringstream.new(io.stdin))
-- Alternatively, `stringstream.open(filename, ...)` may be used to open a file
-- by name in read mode and create a stringstream from it.
--
-- local stream = assert(stringstream.open("README.md"))
-- Now just call the supported string methods =D
while true do
local token, advance = stream:match("(%S+)()")
if not token then break end
-- ... do something with token
print('TOKEN', token)
stream = stream:sub(advance)
endTests are run using busted:
$ busted
The API is documented using LDoc and is available at github pages.
To generate:
$ ldoc .
| Back | FazBrowse Home | New Git URL |