Localize a few variables

This commit is contained in:
Novatux 2015-01-25 10:31:23 +01:00
parent 9d43c1c90e
commit 13a946a868
3 changed files with 42 additions and 42 deletions

View File

@ -3,12 +3,12 @@ bit32 = {}
local N = 32
local P = 2^N
bit32.bnot = function(x)
function bit32.bnot(x)
x = x % P
return P - 1 - x
end
bit32.band = function(x, y)
function bit32.band(x, y)
-- Common usecases, they deserve to be optimized
if y == 0xff then return x % 0x100 end
if y == 0xffff then return x % 0x10000 end
@ -18,7 +18,7 @@ bit32.band = function(x, y)
local r = 0
local p = 1
for i = 1, N do
a, b = x%2, y%2
local a, b = x % 2, y % 2
x, y = math.floor(x / 2), math.floor(y / 2)
if a + b == 2 then
r = r + p
@ -28,7 +28,7 @@ bit32.band = function(x, y)
return r
end
bit32.bor = function(x, y)
function bit32.bor(x, y)
-- Common usecases, they deserve to be optimized
if y == 0xff then return x - (x%0x100) + 0xff end
if y == 0xffff then return x - (x%0x10000) + 0xffff end
@ -38,7 +38,7 @@ bit32.bor = function(x, y)
local r = 0
local p = 1
for i = 1, N do
a, b = x%2, y%2
local a, b = x % 2, y % 2
x, y = math.floor(x / 2), math.floor(y / 2)
if a + b >= 1 then
r = r + p
@ -48,12 +48,12 @@ bit32.bor = function(x, y)
return r
end
bit32.bxor = function(x, y)
function bit32.bxor(x, y)
x, y = x % P, y % P
local r = 0
local p = 1
for i = 1, N do
a, b = x%2, y%2
local a, b = x%2, y%2
x, y = math.floor(x/2), math.floor(y/2)
if a + b == 1 then
r = r + p
@ -63,7 +63,7 @@ bit32.bxor = function(x, y)
return r
end
bit32.lshift = function(x, s_amount)
function bit32.lshift(x, s_amount)
if math.abs(s_amount) >= N then return 0 end
x = x % P
if s_amount < 0 then
@ -73,7 +73,7 @@ bit32.lshift = function(x, s_amount)
end
end
bit32.rshift = function(x, s_amount)
function bit32.rshift(x, s_amount)
if math.abs(s_amount) >= N then return 0 end
x = x % P
if s_amount > 0 then
@ -83,7 +83,7 @@ bit32.rshift = function(x, s_amount)
end
end
bit32.arshift = function(x, s_amount)
function bit32.arshift(x, s_amount)
if math.abs(s_amount) >= N then return 0 end
x = x % P
if s_amount > 0 then

View File

@ -159,7 +159,7 @@ function run_computer(turtle, cptr)
if cptr.stopped then return end
cptr.cycles = math.max(MAX_CYCLES, cptr.cycles + CYCLES_PER_STEP)
while true do
instr = cptr[cptr.PC]
local instr = cptr[cptr.PC]
local f = ITABLE[instr]
if f == nil then return end
cptr.PC = u16(cptr.PC + 1)

View File

@ -28,7 +28,7 @@ end
local function escape(text)
-- Remove all \0's in the string, that cannot be done using string.gsub as there can't be \0's in a pattern
text2 = ""
local text2 = ""
for i = 1, string.len(text) do
if string.byte(text, i) ~= 0 then text2 = text2 .. string.sub(text, i, i) end
end
@ -48,8 +48,8 @@ end
function screen.create_text_formspec(text, basex, basey)
local f = lines(text)
s = ""
i = basey - 0.25
local s = ""
local i = basey - 0.25
for _, x in ipairs(f) do
s = s .. "]label[" .. basex .. "," .. tostring(i) .. ";" .. escape(x)
i = i + 0.3