Skip to content

Commit

Permalink
Works with lua 5.2 now (haven't tested 5.3 yet).
Browse files Browse the repository at this point in the history
Originally it was written with luajit (with 5.2 compatibility on). But
the bit library is named differently than 5.2's bit32 library and is
slightly different.

Changed to work with whichever library is available.
  • Loading branch information
differentprogramming committed Jun 7, 2015
1 parent b55d238 commit e5627a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions bench.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
local mojibake = require 'mojibake'

local bit = require "bit"
local tobit, tohex, bnot, band, bor, bxor, lshift, rshift, arshift, rol, ror, bswap=bit.tobit, bit.tohex, bit.bnot, bit.band, bit.bor, bit.bxor, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror, bit.bswap
--use "bit" library if available (luajit and external), "bit32" if not (lua 5.2)
local bit_library_loaded,bit = pcall(require, "bit")
if not bit_library_loaded then
bit = require "bit32"
end
local bnot, band, bor, bxor, lshift, rshift=bit.bnot, bit.band, bit.bor, bit.bxor, bit.lshift, bit.rshift


function readfile(filename)
local f = io.open(filename, "rb");
Expand Down
8 changes: 6 additions & 2 deletions mojibake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@
* Implementation of libutf8proc.
--]]

local bit = require "bit"
local tobit, tohex, bnot, band, bor, bxor, lshift, rshift, arshift, rol, ror, bswap=bit.tobit, bit.tohex, bit.bnot, bit.band, bit.bor, bit.bxor, bit.lshift, bit.rshift, bit.arshift, bit.rol, bit.ror, bit.bswap
--use "bit" library if available (luajit and external), "bit32" if not (lua 5.2)
local bit_library_loaded,bit = pcall(require, "bit")
if not bit_library_loaded then
bit = require "bit32"
end
local bnot, band, bor, bxor, lshift, rshift=bit.bnot, bit.band, bit.bor, bit.bxor, bit.lshift, bit.rshift
local floor=math.floor

local NULLTERM = 1
Expand Down

0 comments on commit e5627a3

Please sign in to comment.