diff options
| author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-05-31 14:24:19 +0200 |
|---|---|---|
| committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-05-31 14:24:19 +0200 |
| commit | fae336d1a2d613fd00640ed6ccbb9eb386086c82 (patch) | |
| tree | 48f0fe2cf3a3d86d2d0e192f1b38da55bc18d2f7 /builtin | |
| parent | 76071affa0f33bef03e323aa0552c750c56a2cab (diff) | |
| download | hydra-dragonfire-fae336d1a2d613fd00640ed6ccbb9eb386086c82.tar.xz | |
Add map component
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/base64.lua | 43 | ||||
| -rw-r--r-- | builtin/escapes.lua | 2 | ||||
| -rw-r--r-- | builtin/vector.lua | 10 |
3 files changed, 52 insertions, 3 deletions
diff --git a/builtin/base64.lua b/builtin/base64.lua new file mode 100644 index 0000000..5afa64a --- /dev/null +++ b/builtin/base64.lua @@ -0,0 +1,43 @@ +--[[ builtin/base64.lua ]]-- + +-- Taken from: http://lua-users.org/wiki/BaseSixtyFour with minor modifications + +-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de> +-- licensed under the terms of the LGPL2 + +local base64 = {} +package.loaded.base64 = base64 + +-- character table string +local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' + +-- encoding +function base64.encode(data) + return ((data:gsub('.', function(x) + local r,b='',x:byte() + for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end + return r; + end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x) + if (#x < 6) then return '' end + local c=0 + for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end + return b:sub(c+1,c+1) + end)..({ '', '==', '=' })[#data%3+1]) +end + +-- decoding +function base64.decode(data) + data = string.gsub(data, '[^'..b..'=]', '') + return (data:gsub('.', function(x) + if (x == '=') then return '' end + local r,f='',(b:find(x)-1) + for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end + return r; + end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) + if (#x ~= 8) then return '' end + local c=0 + for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end + return string.char(c) + end)) +end + diff --git a/builtin/escapes.lua b/builtin/escapes.lua index 12ba174..e3ff161 100644 --- a/builtin/escapes.lua +++ b/builtin/escapes.lua @@ -2,7 +2,7 @@ -- code taken from minetest/builtin/common/misc_helpers.lua with modifications local escapes = {} -package.loaded["escapes"] = escapes +package.loaded.escapes = escapes escapes.ESCAPE_CHAR = string.char(0x1b) diff --git a/builtin/vector.lua b/builtin/vector.lua index eed368f..654a839 100644 --- a/builtin/vector.lua +++ b/builtin/vector.lua @@ -43,7 +43,10 @@ mt_vec2.__index = { assert(type(self.x) == "number") assert(type(self.y) == "number") return self - end + end, + round = function(self) + return vec2(math.round(self.x), math.round(self.y)) + end, } function vec2(a, b) @@ -91,7 +94,10 @@ mt_vec3.__index = { assert(type(self.y) == "number") assert(type(self.z) == "number") return self - end + end, + round = function(self) + return vec3(math.floor(self.x), math.floor(self.y), math.floor(self.z)) + end, } function vec3(a, b, c) |
