support builds without bit module
This commit is contained in:
parent
af91334ec7
commit
7704f5280d
@ -58,8 +58,11 @@ local Base64 = {}
|
||||
-- Imports
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
bit = ie.require("bit")
|
||||
|
||||
local bit
|
||||
local status,err = pcall(function() bit = ie.require 'bit' end)
|
||||
if not status then
|
||||
bit = ie.dofile(minetest.get_modpath(minetest.get_current_modname()) .. '/slowbit32.lua')
|
||||
end
|
||||
local band, bor, lshift, rshift = bit.band, bit.bor, bit.lshift, bit.rshift
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
|
@ -87,13 +87,16 @@ else
|
||||
remote_address = "*"
|
||||
end
|
||||
|
||||
local server = socket.bind(remote_address, 4711)
|
||||
local server,err = socket.bind(remote_address, 4711)
|
||||
assert(server, err)
|
||||
|
||||
server:setoption('tcp-nodelay',true)
|
||||
server:settimeout(0)
|
||||
|
||||
local ws_server = nil
|
||||
|
||||
if ws then
|
||||
if not bit or not bit.bxor then bit = ie.require("slowbit32") end
|
||||
tools = ie.require("tools")
|
||||
base64 = ie.require("base64")
|
||||
ws_server = socket.bind(remote_address, 14711)
|
||||
@ -285,6 +288,10 @@ function python(name, args, kill_script)
|
||||
return true
|
||||
end
|
||||
|
||||
local function sanitize_pipe(s)
|
||||
return s:gsub("%&", "&"):gsub("%|", "|")
|
||||
end
|
||||
|
||||
minetest.register_on_chat_message(function(name, message)
|
||||
local id = get_player_id_by_name(name)
|
||||
table.insert(chat_record, id .. "," .. sanitize_pipe(message))
|
||||
@ -318,10 +325,6 @@ function get_entity_id(entity)
|
||||
end
|
||||
end
|
||||
|
||||
local function sanitize_pipe(s)
|
||||
return s:gsub("%&", "&"):gsub("%|", "|")
|
||||
end
|
||||
|
||||
function handle_entity(cmd, id, args)
|
||||
local entity
|
||||
if id == nil then
|
||||
@ -665,8 +668,8 @@ function handle_command(line)
|
||||
end
|
||||
|
||||
local args = {}
|
||||
for arg in argtext:gmatch("([^,]+)") do
|
||||
table.insert(args, arg)
|
||||
for argument in argtext:gmatch("([^,]+)") do
|
||||
table.insert(args, argument)
|
||||
end
|
||||
if cmd:sub(1,6) == "world." then
|
||||
return handle_world(cmd:sub(7),args)
|
||||
|
139
raspberryjammod/slowbit32.lua
Normal file
139
raspberryjammod/slowbit32.lua
Normal file
@ -0,0 +1,139 @@
|
||||
-- These are super slow 32-bit operations --
|
||||
|
||||
local two31 = 2^31
|
||||
local two32 = 2^32
|
||||
|
||||
local to_binary = function(x)
|
||||
local pos = two31
|
||||
local a = ""
|
||||
if x < 0 then
|
||||
x = x + two32
|
||||
end
|
||||
x = x % two32
|
||||
for i=1,32 do
|
||||
if x >= pos then
|
||||
a = a .. "1"
|
||||
x = x - pos
|
||||
else
|
||||
a = a .. "0"
|
||||
end
|
||||
pos = pos / 2
|
||||
end
|
||||
return a
|
||||
end
|
||||
|
||||
local from_binary = function(x)
|
||||
local z = tonumber(x)
|
||||
if z >= two31 then
|
||||
return z - two32
|
||||
else
|
||||
return z
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local band = function(...)
|
||||
local a = {}
|
||||
local arg = {...}
|
||||
for i = 1,#arg do
|
||||
a[i] = to_binary(arg[i])
|
||||
end
|
||||
local c = ""
|
||||
for i = 1,32 do
|
||||
local value = true
|
||||
for j = 1,#arg do
|
||||
if a[j]:sub(i,i) == "0" then
|
||||
value = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if value then
|
||||
c = c .. "1"
|
||||
else
|
||||
c = c .. "0"
|
||||
end
|
||||
end
|
||||
return from_binary(c)
|
||||
end
|
||||
|
||||
local bor = function(...)
|
||||
local a = {}
|
||||
local arg = {...}
|
||||
for i = 1,#arg do
|
||||
a[i] = to_binary(arg[i])
|
||||
end
|
||||
local c = ""
|
||||
for i = 1,32 do
|
||||
local value = false
|
||||
for j = 1,#arg do
|
||||
if a[j]:sub(i,i) == "1" then
|
||||
value = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if value then
|
||||
c = c .. "1"
|
||||
else
|
||||
c = c .. "0"
|
||||
end
|
||||
end
|
||||
return from_binary(c)
|
||||
end
|
||||
|
||||
local bxor = function(...)
|
||||
local a = {}
|
||||
local arg = {...}
|
||||
for i = 1,#arg do
|
||||
a[i] = to_binary(arg[i])
|
||||
end
|
||||
local c = ""
|
||||
for i = 1,32 do
|
||||
local value = false
|
||||
for j = 1,#arg do
|
||||
if a[j]:sub(i,i) == "1" then
|
||||
value = not value
|
||||
end
|
||||
end
|
||||
|
||||
if value then
|
||||
c = c .. "1"
|
||||
else
|
||||
c = c .. "0"
|
||||
end
|
||||
end
|
||||
return from_binary(c)
|
||||
end
|
||||
|
||||
|
||||
local bnot = function(x)
|
||||
local a = to_binary(x)
|
||||
local c = ""
|
||||
for i = 1,32 do
|
||||
if a:sub(i,i) == "0" then
|
||||
c = c .. "1"
|
||||
else
|
||||
c = c .. "0"
|
||||
end
|
||||
end
|
||||
return from_binary(c)
|
||||
end
|
||||
|
||||
local lshift = function(x,n)
|
||||
return (x * 2^n) % two32
|
||||
end
|
||||
|
||||
local rshift = function(x,n)
|
||||
return math.floor(x / 2^n)
|
||||
end
|
||||
|
||||
local rol = function(x,n)
|
||||
local a = to_binary(x)
|
||||
for i = 1,n do
|
||||
a = a:sub(2,32) .. a:sub(1,1)
|
||||
end
|
||||
return from_binary(a)
|
||||
end
|
||||
|
||||
return {rol=rol, bxor=bxor, bor=bor, band=band, bnot=bnot, lshift=lshift, rshift=rshift}
|
@ -21,8 +21,6 @@ if not status then
|
||||
socket = ie.require("socket.cx64")
|
||||
end
|
||||
|
||||
ie.module("socket")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Exported auxiliar functions
|
||||
-----------------------------------------------------------------------------
|
||||
@ -49,7 +47,7 @@ function bind(host, port, backlog)
|
||||
return sock
|
||||
end
|
||||
|
||||
try = newtry()
|
||||
-- try = newtry()
|
||||
|
||||
function choose(table)
|
||||
return function(name, opt1, opt2)
|
||||
@ -141,3 +139,4 @@ sourcet["default"] = sourcet["until-closed"]
|
||||
|
||||
source = choose(sourcet)
|
||||
|
||||
return { connect=connect, bind=bind, choose=choose, source=source }
|
||||
|
@ -4,7 +4,12 @@ else
|
||||
ie = _G
|
||||
end
|
||||
|
||||
local bit = ie.require 'bit'
|
||||
local bit
|
||||
local status,err = pcall(function() bit = ie.require 'bit' end)
|
||||
if not status then
|
||||
bit = ie.dofile(minetest.get_modpath(minetest.get_current_modname()) .. '/slowbit32.lua')
|
||||
end
|
||||
|
||||
local rol = bit.rol
|
||||
local bxor = bit.bxor
|
||||
local bor = bit.bor
|
||||
|
Loading…
x
Reference in New Issue
Block a user