mirror of
https://github.com/minetest-mods/i3.git
synced 2024-12-25 02:10:39 +01:00
Add script for Luacheck
This commit is contained in:
parent
0b4250b54b
commit
ab690398b7
@ -1,6 +1,7 @@
|
||||
allow_defined_top = true
|
||||
|
||||
ignore = {
|
||||
"631", -- Line is too long.
|
||||
"get_debug_grid",
|
||||
}
|
||||
|
||||
|
129
luacheck.lua
Executable file
129
luacheck.lua
Executable file
@ -0,0 +1,129 @@
|
||||
local exec = os.execute
|
||||
local fmt, find, sub = string.format, string.find, string.sub
|
||||
local var = "[%w%.%[%]\"\'_]"
|
||||
|
||||
exec("reset")
|
||||
|
||||
local function split(str, delim, include_empty, max_splits, sep_is_pattern)
|
||||
delim = delim or ","
|
||||
max_splits = max_splits or -2
|
||||
local items = {}
|
||||
local pos, len = 1, #str
|
||||
local plain = not sep_is_pattern
|
||||
max_splits = max_splits + 1
|
||||
repeat
|
||||
local np, npe = find(str, delim, pos, plain)
|
||||
np, npe = (np or (len+1)), (npe or (len+1))
|
||||
if (not np) or (max_splits == 1) then
|
||||
np = len + 1
|
||||
npe = np
|
||||
end
|
||||
local s = sub(str, pos, np - 1)
|
||||
if include_empty or (s ~= "") then
|
||||
max_splits = max_splits - 1
|
||||
items[#items + 1] = s
|
||||
end
|
||||
pos = npe + 1
|
||||
until (max_splits == 0) or (pos > (len + 1))
|
||||
return items
|
||||
end
|
||||
|
||||
local files = {
|
||||
"api",
|
||||
"bags",
|
||||
"caches",
|
||||
"callbacks",
|
||||
"common",
|
||||
"compress",
|
||||
"detached_inv",
|
||||
"groups",
|
||||
"gui",
|
||||
"hud",
|
||||
"model_aliases",
|
||||
"progressive",
|
||||
"styles",
|
||||
}
|
||||
|
||||
local operators = {
|
||||
["([%+%-%*%^/&|])="] = function(a, b, c)
|
||||
return fmt("%s = %s %s %s", a, a, b, c)
|
||||
end,
|
||||
|
||||
["+%+"] = function(a, b)
|
||||
return fmt("%s = %s + 1\n%s", a, a, b)
|
||||
end,
|
||||
|
||||
["&"] = function(a, b)
|
||||
return fmt("bit.band(%s, %s)", a, b)
|
||||
end,
|
||||
|
||||
["|"] = function(a, b)
|
||||
return fmt("bit.bor(%s, %s)", a, b)
|
||||
end,
|
||||
|
||||
["<<"] = function(a, b)
|
||||
return fmt("bit.lshift(%s, %s)", a, b)
|
||||
end,
|
||||
|
||||
[">>"] = function(a, b)
|
||||
return fmt("bit.rshift(%s, %s)", a, b)
|
||||
end,
|
||||
|
||||
["<<="] = function(a, b)
|
||||
return fmt("%s = bit.lshift(%s, %s)", a, a, b)
|
||||
end,
|
||||
|
||||
[">>="] = function(a, b)
|
||||
return fmt("%s = bit.rshift(%s, %s)", a, a, b)
|
||||
end,
|
||||
}
|
||||
|
||||
local function compile(data)
|
||||
data = data:gsub("IMPORT%((.-)%)", function(a)
|
||||
return "local " .. a:gsub("\"", "") .. " = i3.get(" .. a .. ")"
|
||||
end)
|
||||
|
||||
for op, func in pairs(operators) do
|
||||
data = data:gsub("(" .. var .. "+)%s?" .. op .. "%s?(" .. var .. "*)", func)
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
for _, p in ipairs(files) do
|
||||
local function _load(path, line, data, t)
|
||||
if line then
|
||||
if not t then
|
||||
t = split(data, "\n")
|
||||
end
|
||||
t[line] = t[line]:gsub("(" .. var .. "+)%s?=%s?(" .. var .. "*)", "%2")
|
||||
data = table.concat(t, "\n")
|
||||
else
|
||||
local file = assert(io.open(path, "r"))
|
||||
data = file:read"*a"
|
||||
file:close()
|
||||
data = compile(data)
|
||||
end
|
||||
|
||||
local l, err = loadstring(data)
|
||||
|
||||
if not l then
|
||||
local err_line = tonumber(err:match(":(%d+):"))
|
||||
|
||||
if line ~= err_line then
|
||||
return _load(path, err_line, data, t)
|
||||
end
|
||||
end
|
||||
|
||||
local _file = io.open(path:match("(.*)%.") .. ".l", "w")
|
||||
_file:write(data)
|
||||
_file:close()
|
||||
end
|
||||
|
||||
_load("./src/" .. p .. ".lua")
|
||||
end
|
||||
|
||||
exec("luacheck init.lua")
|
||||
exec("luacheck ./src/operators.lua")
|
||||
exec("luacheck ./src/*.l")
|
||||
exec("rm ./src/*.l")
|
@ -1,6 +1,5 @@
|
||||
local ItemStack = ItemStack
|
||||
local loadstring = loadstring
|
||||
local ESC = core.formspec_escape
|
||||
local translate = core.get_translated_string
|
||||
local vec_new, vec_add, vec_mul = vector.new, vector.add, vector.multiply
|
||||
local sort, concat, insert = table.sort, table.concat, table.insert
|
||||
|
@ -241,9 +241,9 @@ local function get_isometric_view(fs, pos, X, Y)
|
||||
local p = area:position(idx)
|
||||
p = vec_sub(p, pos)
|
||||
|
||||
local size = 0.25
|
||||
local x = 2 + (size / 2 * (p.z - p.x))
|
||||
local y = 1.15 + (size / 4 * (p.x + p.z - 2 * p.y))
|
||||
local size = 0.25
|
||||
|
||||
if plant then
|
||||
size -= 0.05
|
||||
|
@ -1,7 +1,7 @@
|
||||
--[[ All source files have to be preprocessed before loading.
|
||||
This allows implementing custom operators like bitwise ones. ]]
|
||||
|
||||
local fmt = string.format
|
||||
local fmt, split = string.format, string.split
|
||||
local var = "[%w%.%[%]\"\'_]"
|
||||
|
||||
local operators = {
|
||||
@ -53,7 +53,7 @@ end
|
||||
local function _load(path, line, data, t)
|
||||
if line then
|
||||
if not t then
|
||||
t = data:split"\n"
|
||||
t = split(data, "\n")
|
||||
end
|
||||
t[line] = t[line]:gsub("(" .. var .. "+)%s?=%s?(" .. var .. "*)", "%2")
|
||||
data = table.concat(t, "\n")
|
||||
|
Loading…
Reference in New Issue
Block a user