lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've updated my bit and rex libraries for Lua 5 (formerly rexlib and
bitlib): respectively they provide bitwise and regular expression
operations. The new versions are fully Lua 5-ized: rex provides a more
OO-interface, and bit places its functions in a table, as is
now conventional.

The latest Lua 4 release (which as has had no bugs reported or found for
some months) is still available.

See http://www.mupsych.org/~rrt/Lua for the download.

I attach the (short) readme file for those unfamiliar with the libraries:



                       Lua C libraries release 9
                       -------------------------

                    by Reuben Thomas (rrt@sc3d.org)


This archive contains two additional libraries for Lua 5.0, documented
below. The Makefile provided builds them into a shared library called
libluaRRT.so, which can be used with loadlib.

The libraries are copyright Reuben Thomas 2000-2003, and are released
under the MIT license, like Lua (see http://www.lua.org/copyright.html
for the full license). There is no warranty.

Note for Lua 4 users: release 8 of the libraries, which works with Lua
4, is still available.


bit
---

Provides bitwise logical operations:

bit.bnot(a)       returns the one's complement of a
bit.band(w1,...)  returns the bitwise and of the w's
bit.bor(w1,...)   returns the bitwise or of the w's
bit.bxor(w1,...)  returns the bitwise exclusive or of the w's
bit.lshift(a,b)   returns a shifted left b places
bit.rshift(a,b)   returns a shifted logically right b places
bit.arshift(a,b)  returns a shifted arithmetically right b places
bit.mod(a,b)      returns the integer remainder of a divided by b

The arguments to all functions should be integral numbers. The number
of bits available for logical operations depends on the data type used
to represent Lua numbers; this is typically 8-byte IEEE floats, which
give 53 bits (the size of the mantissa).

The logical operations start with "b" for "bit" to avoid clashing with
reserved words; although "xor" isn't a reserved word, it seemed better
to use "bxor" for consistency.


rex
---

Provides POSIX regular expression matching:

rex.comp(r)  returns a compiled regular expression (calls regcomp)
r:match(s)   returns the start and end point of the first match of
             the compiled regexp r in the string s (calls regexec).
             Substring matches ("captures" in Lua terminology) are
             returned as a third result, in a table.
r:gmatch(s, f[, n]) tries to match the regex r against s up to n
             times (or as many as possible if n is not given); each
             time there is a match, f is called as f(m, c), where m is
             the matched string and c is a table of substring matches;
             gmatch returns the number of matches made.

It may be useful to define:

-- string.find replacement
function rex.find(s, r)
  return rex.comp(r):match(s)
end

-- partial string.gsub replacement
function rex.gsub(s, r, f, n)
  return rex.comp(r):gmatch(s, f, n)
end

If rexlib is compiled against Henry Spencer's regex library, then
regular expressions and the strings to match them against may contain
NULs.

If you're wondering why regfree isn't mentioned above, that's because
it's called automatically by the __gc metamethod of the userdata type
that holds regexs.

-- 
http://www.mupsych.org/~rrt/
motive, n.  a mental wolf in moral wool (Bierce)