Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit ca45992

Browse files
committed
[luadist-git] add lua-bit-numberlua-0.1.0-Windows-x86
0 parents  commit ca45992

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

dist.info

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
type = "x86"
2+
arch = "Windows"
3+
author = "David Manura"
4+
depends = {
5+
[[lua ~> 5.1]],
6+
}
7+
8+
desc = "'bit.numberlua' Bitwise operators in pure Lua using Lua numbers"
9+
version = "0.1.0"
10+
homepage = "http://lua-users.org/wiki/ModuleBitNumberLua"
11+
files = {
12+
Unspecified = {
13+
[[lib\lua\bit\numberlua.lua]],
14+
[[share\lua-bit-numberlua\COPYRIGHT]],
15+
}
16+
,
17+
}
18+
19+
license = "MIT"
20+
name = "lua-bit-numberlua"
21+
maintainer = "Peter Kapec"

lib/lua/bit/numberlua.lua

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
-- dmlib.bit
2+
-- Bitwise operations implemented entirely in Lua.
3+
-- Represents bit arrays as non-negative Lua numbers.[1]
4+
-- Can represent 32-bit bit arrays, when Lua is compiled
5+
-- with lua_Number being double-precision IEEE 754 floating point.
6+
--
7+
-- Based partly on Roberto Ierusalimschy's post
8+
-- in http://lua-users.org/lists/lua-l/2002-09/msg00134.html .
9+
--
10+
-- References
11+
--
12+
-- [1] http://lua-users.org/wiki/FloatingPoint
13+
--
14+
-- (c) 2008 David Manura. Licensed under the same terms as Lua (MIT).
15+
16+
17+
local function memoize(f)
18+
local mt = {}
19+
local t = setmetatable({}, mt)
20+
function mt:__index(k)
21+
local v = f(k); t[k] = v
22+
return v
23+
end
24+
return t
25+
end
26+
27+
local function make_bitop_uncached(t, m)
28+
local function bitop(a, b)
29+
local res,p = 0,1
30+
while a ~= 0 and b ~= 0 do
31+
local am, bm = a%m, b%m
32+
res = res + t[am][bm]*p
33+
a = (a - am) / m
34+
b = (b - bm) / m
35+
p = p*m
36+
end
37+
res = res + (a+b)*p
38+
return res
39+
end
40+
return bitop
41+
end
42+
43+
local function make_bitop(t)
44+
local op1 = make_bitop_uncached(t,2^1)
45+
local op2 = memoize(function(a)
46+
return memoize(function(b)
47+
return op1(a, b)
48+
end)
49+
end)
50+
return make_bitop_uncached(op2, 2^(t.n or 1))
51+
end
52+
53+
local bxor = make_bitop {[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0}, n=4}
54+
local F8 = 2^32 - 1
55+
local function bnot(a) return F8 - a end
56+
local function band(a,b) return ((a+b) - bxor(a,b))/2 end
57+
local function bor(a,b) return F8 - band(F8 - a, F8 - b) end
58+
59+
local M = {}
60+
M.bxor = bxor
61+
M.bnot = bnot
62+
M.band = band
63+
M.bor = bor
64+
65+
return M
66+
67+
--[[
68+
LICENSE
69+
70+
Copyright (C) 2008, David Manura.
71+
72+
Permission is hereby granted, free of charge, to any person obtaining a copy
73+
of this software and associated documentation files (the "Software"), to deal
74+
in the Software without restriction, including without limitation the rights
75+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
76+
copies of the Software, and to permit persons to whom the Software is
77+
furnished to do so, subject to the following conditions:
78+
79+
The above copyright notice and this permission notice shall be included in
80+
all copies or substantial portions of the Software.
81+
82+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
83+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
84+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
85+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
86+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
87+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
88+
THE SOFTWARE.
89+
90+
(end license)
91+
--]]

share/lua-bit-numberlua/COPYRIGHT

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
lua-bit-numberlua License
2+
3+
===============================================================================
4+
5+
Copyright (C) 2008, David Manura.
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
===============================================================================

0 commit comments

Comments
 (0)