If you are using luarocks, just run:
luarocks install wires
Copy the wires.lua file somewhere where your Lua interpreter will be able to find it and require it accordingly:
local wires = require("wires")
You can extend the Lua string namespace by doing:
for k, v in pairs(wires) do
string[k] = v
end
so you can use them as string methods:
(""):trim()
or
string.trim("")
wires.starts(s, prefix)
Find if string s
starts with prefix
wires.starts("foo bar baz", "foo") -> true
Arguments:
s
(string)
- String to matchprefix
(string)
- String to match ins
Returns:
(boolean)
-true
ifs
starts withprefix
,false
if not
wires.ends(s, suffix)
Find if string s
ends with suffix
wires.ends("foo bar baz", "baz") -> true
Arguments:
s
(string)
- String to matchsuffix
(string)
- String to match ins
Returns:
(boolean)
-true
ifs
ends withsuffix
,false
if not
wires.trim(s)
Remove whitespace (defined as Lua pattern "%s"
) from the beginning and end of a string
wires.trim(" foo ") -> "foo"
Arguments:
s
(string)
- String to trim
Returns:
(string)
- The trimmed string
wires.escape(s[, mode])
Escape magic characters of s
so that it can be used as a pattern. The optional argument mode may be "*i"
(for case insensitive)
wires.escape("%s", "*i") -> "%%[sS]"
Arguments:
s
(string)
- String to escapemode
(string)
- String for whether the escape should be case insensetive
Returns:
(string)
- The escaped string
wires.gsplit(s, sep[, start[, plain]]) -> iter() -> e[, captures...]
Split s
by a separator pattern (or plain string) and iterate over the elements
for c in wires.gsplit('foo bar baz', '%s') do
print(c)
end
Arguments:
s
(string)
- string to gsplitsep
(string)
- pattern to gsplits
start
(number)
- Capture to begin atplain
(boolean)
- Whether to match patterns or not
Returns:
c
(string)
- A capture froms
wires.lines(s[, opt]) -> iter() -> s
Iterate the lines of a string, The lines are split at \r\n
, \r
and \n
markers
for c in wires.lines("foo\nbar\nbaz") do
print(c)
end
Arguments:
s
(string)
- String with lines to iterate overopt
(string)
-*L
(include line endings; default) or*l
(exclude).
Returns:
c
(string)
- The captured line
wires.tohex(s, upper)
Convert a hex string to its binary representation
wires.tohex("foo") -> "666f6f"
Arguments:
s
(string)
- String to convert to it's hex representationupper
(boolean)
- Whether alphabetical characters should be capitalised
Returns:
(string)
- Hex representation ofs
wires.fromhex(s)
Convert a hex string to its binary representation
wires.fromhex("666f6f") -> "foo"
Arguments:
s
(string)
- Hex string to convert to it's binary represenation
Returns:
(string)
- Binary representation ofs
This library is free software; You may redistribute and/or modify it under the terms of the MIT license. See LICENSE for details.