Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
/* (find-es "lua5" "lbitlib")
 * Written by Reuben Thomas for Lua4.0
 * patched by Edrx for Lua5.0
 */

#include "lauxlib.h"
#include "lua.h"

typedef long long Integer;
typedef unsigned long long UInteger;

#define luaL_checkbit(L,n) ((Integer)luaL_checknumber(L, n))
#define luaL_checkubit(L,n) ((UInteger)luaL_checkbit(L, n))

#define TDYADIC(name, op, t1, t2) \
  static int name(lua_State* L) { \
    lua_pushnumber(L, \
      luaL_check ## t1 ## bit(L, 1) op luaL_check ## t2 ## bit(L, 2)); \
    return 1; \
  }

#define DYADIC(name, op)  TDYADIC(name, op, , )

#define MONADIC(name, op) \
  static int name(lua_State* L) { \
    lua_pushnumber(L, op luaL_checkbit(L, 1)); \
    return 1; \
  }

MONADIC(int_not,      ~)
DYADIC(int_mod,       %)
DYADIC(int_and,       &)
DYADIC(int_or,        |)
DYADIC(int_xor,       ^)
TDYADIC(int_lshift,  <<, , u)
TDYADIC(int_rshift,  >>, u, u)
TDYADIC(int_arshift, >>, , u)

static const struct luaL_reg bitlib[] = {
{"bnot",    int_not},
{"imod",    int_mod},  /* "mod" already in Lua math library */
{"band",    int_and},
{"bor",     int_or},
{"bxor",    int_xor},
{"lshift",  int_lshift},
{"rshift",  int_rshift},
{"arshift", int_arshift},
{NULL,      NULL}
};

LUALIB_API int lua_bitlibopen (lua_State *L) {
    lua_pushvalue(L, LUA_GLOBALSINDEX);
    luaL_openlib(L, NULL, bitlib, 0);
    return 0;
}