Skip to content

Commit 9867d21

Browse files
committed
coding style for locals
1 parent 57a64e7 commit 9867d21

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

lmod/bit/numberlua.lua

+20-27
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ LICENSE
136136
137137
--]]
138138

139-
local M = {_TYPE='module', _NAME='bit.numberlua', _VERSION='000.003.2011-11-28'}
139+
local M = {_TYPE='module', _NAME='bit.numberlua', _VERSION='000.003.2011-11-29'}
140140

141141
local floor = math.floor
142142

@@ -177,39 +177,37 @@ local function make_bitop(t)
177177
end
178178

179179
-- ok? probably not if running on a 32-bit int Lua number type platform
180-
local function tobit(x)
180+
function M.tobit(x)
181181
return x % 2^32
182182
end
183-
M.tobit = tobit
184183

185-
local bxor = make_bitop {[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0}, n=4}
186-
M.bxor = bxor
184+
M.bxor = make_bitop {[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0}, n=4}
185+
local bxor = M.bxor
187186

188187
local F8 = 2^32 - 1
189-
local function bnot(a) return F8 - a end
190-
M.bnot = bnot
188+
function M.bnot(a) return F8 - a end
189+
local bnot = M.bnot
191190

192-
local function band(a,b) return ((a+b) - bxor(a,b))/2 end
193-
M.band = band
191+
function M.band(a,b) return ((a+b) - bxor(a,b))/2 end
192+
local band = M.band
194193

195-
local function bor(a,b) return F8 - band(F8 - a, F8 - b) end
196-
M.bor = bor
194+
function M.bor(a,b) return F8 - band(F8 - a, F8 - b) end
197195

198196
local lshift, rshift -- forward declare
199197

200-
function rshift(a,disp) -- Lua5.2 style
198+
function M.rshift(a,disp) -- Lua5.2 style
201199
if disp < 0 then return lshift(a,-disp) end
202200
return floor(a % 2^32 / 2^disp)
203201
end
204-
M.rshift = rshift
202+
rshift = M.rshift
205203

206-
function lshift(a,disp) -- Lua5.2 style
204+
function M.lshift(a,disp) -- Lua5.2 style
207205
if disp < 0 then return rshift(a,-disp) end
208206
return (a * 2^disp) % 2^32
209207
end
210-
M.lshift = lshift
208+
lshift = M.lshift
211209

212-
local function tohex(x, n) -- BitOp style
210+
function M.tohex(x, n) -- BitOp style
213211
n = n or 8
214212
local up
215213
if n < 0 then
@@ -219,43 +217,38 @@ local function tohex(x, n) -- BitOp style
219217
x = band(x, 16^n-1)
220218
return ('%0'..n..(up and 'X' or 'x')):format(x)
221219
end
222-
M.tohex = tohex
223220

224-
local function extract(n, field, width) -- Lua5.2 style
221+
function M.extract(n, field, width) -- Lua5.2 style
225222
width = width or 1
226223
return band(rshift(n, field), 2^width-1)
227224
end
228-
M.extract = extract
229225

230-
local function replace(n, v, field, width) -- Lua5.2 style
226+
function M.replace(n, v, field, width) -- Lua5.2 style
231227
width = width or 1
232228
local mask1 = 2^width-1
233229
v = band(v, mask1) -- required by spec?
234230
local mask = bnot(lshift(mask1, field))
235231
return band(n, mask) + lshift(v, field)
236232
end
237-
M.replace = replace
238233

239-
local function bswap(x) -- BitOp style
234+
function M.bswap(x) -- BitOp style
240235
local a = band(x, 0xff); x = rshift(x, 8)
241236
local b = band(x, 0xff); x = rshift(x, 8)
242237
local c = band(x, 0xff); x = rshift(x, 8)
243238
local d = band(x, 0xff)
244239
return lshift(lshift(lshift(a, 8) + b, 8) + c, 8) + d
245240
end
246-
M.bswap = bswap
247241

248-
local function rrotate(x, disp) -- Lua5.2 style
242+
function M.rrotate(x, disp) -- Lua5.2 style
249243
disp = disp % 32
250244
local low = band(x, 2^disp-1)
251245
return rshift(x, disp) + lshift(low, 32-disp)
252246
end
253-
M.rrotate = rrotate
247+
local rrotate = M.rrotate
254248

255-
local function lrotate(x, disp) -- Lua5.2 style
249+
function M.lrotate(x, disp) -- Lua5.2 style
256250
return rrotate(x, -disp)
257251
end
258-
M.lrotate = lrotate
259252

260253
M.rol = M.lrotate -- LuaOp style
261254
M.ror = M.rrotate -- LuaOp style

0 commit comments

Comments
 (0)