lua-users home
lua-l archive

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


David Manura wrote:
> I was thinking of writing an alternative implementation of bitlib
> having the exact same interface but in pure Lua so that one could
> transparently choose either the C or Lua implementation.  However, the
> prerequisite is that the interface of bitlib be more formally defined
> in regards to sign, endianness, portability limits, etc. (which I
> haven't examined in detail myself).

I've done the latter, since I needed it for LuaJIT 2.x anyway.
Here's an excerpt of the docs:
  http://lua-users.org/lists/lua-l/2008-09/msg00441.html

In fact, I've got a backport of the bit operations library for
standard Lua that has the same functionality and semantics.
I haven't released it yet, lacking the time to package, document
and support it. But if there's sufficient demand ...

Anyway, here are the specs:
- Supported functions: bit.tobit, bit.bnot, bit.band, bit.bor,
  bit.bxor, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror.
- Only 100 lines of C.
- Needs C99 <stdint.h>, but has MSVC workaround.
- Zero configuration in the standard case. One define is needed for
  the rare case of mixed-endian doubles.
- A simple Makefile for POSIX platforms. A BAT file for MSVC.
- Compiles out-of-the-box with GCC, MSVC and probably anything else.
- Works on 16, 32 and 64 bit platforms (with 2's-complement arithmetic,
  please :-) ).
- Works with lua_Number set to IEEE 754 doubles or to any signed
  integer type of 32 bits or more.
- Does not work with lua_Number = float (doesn't make much sense).
- Consistent semantics across all platforms. All operations work
  on 32 bits, independent of the size and type of lua_Number.
- Internal self-test on startup to detect miscompiles (wrong luaconf.h)
  and DirectX used with the wrong flags (bad FPU precision setting).
- Includes comprehensive tests and benchmarks.
- It's as fast as you can get with the standard Lua/C API.
- Author is reading the Lua mailing list. :-)

Open issues:
- Lacks an appropriate project name that is not taken yet.

--Mike