added luacheck

This commit is contained in:
theFox6 2019-05-18 07:37:46 +02:00
parent 98cf73e57a
commit 2455b73e53
12 changed files with 93 additions and 36 deletions

26
.luacheck_health Normal file

@ -0,0 +1,26 @@
allow_defined_top = true
read_globals = {
"default",
"dump",
"ItemStack",
"PseudoRandom",
"stairsplus",
"intllib",
"Settings",
math = { fields = {"sign"} },
"minetest",
"vector",
"VoxelArea",
"VoxelManip",
}
ignore = {
"211",
"212",
"213",
"611",
"612",
"621",
"631"
}

11
.luacheckrc Normal file

@ -0,0 +1,11 @@
allow_defined_top = true
read_globals = {
"minetest", "default",
"dump", "vector",
"VoxelManip", "VoxelArea",
"ItemStack", "PseudoRandom",
"stairsplus", "intllib",
"Settings",
math = { fields = {"sign"} }
}

23
.travis.yml Normal file

@ -0,0 +1,23 @@
language: generic
sudo: false
addons:
apt:
packages:
- luarocks
before_install:
- luarocks install --local luacheck
env:
- CONFIG=.luacheck_health
- CONFIG=.luacheckrc
matrix:
allow_failures:
- name: "beauty check"
env: CONFIG=.luacheckrc
exclude:
- name: "health check"
env: CONFIG=.luacheck_health
script:
- $HOME/.luarocks/bin/luacheck --config $CONFIG .
notifications:
email:
on_failure: change

@ -156,7 +156,7 @@ function microexpansion.get_node(pos)
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)
if node then return node end if node then return node end
local vm = VoxelManip() local vm = VoxelManip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos) vm:read_from_map(pos, pos)
return minetest.get_node(pos) return minetest.get_node(pos)
end end

2
development/luacheck.sh Normal file

@ -0,0 +1,2 @@
#! /bin/bash
~/src/luarocks-3.0.3/lua_modules/bin/luacheck .. --exclude-files=.

@ -5,7 +5,6 @@ microexpansion.modpath = minetest.get_modpath("microexpansion") -- Get modpath
microexpansion.worldpath = minetest.get_worldpath() -- Get worldpath microexpansion.worldpath = minetest.get_worldpath() -- Get worldpath
local modpath = microexpansion.modpath -- Modpath pointer local modpath = microexpansion.modpath -- Modpath pointer
local worldpath = microexpansion.worldpath -- Worldpath pointer
-- Formspec GUI related stuff -- Formspec GUI related stuff
microexpansion.gui_bg = "bgcolor[#080808BB;true]background[5,5;1,1;gui_formbg.png;true]" microexpansion.gui_bg = "bgcolor[#080808BB;true]background[5,5;1,1;gui_formbg.png;true]"

@ -3,13 +3,13 @@
local me = microexpansion local me = microexpansion
local network = me.network local network = me.network
local function update_ctrl(pos,node) local function update_ctrl(pos)
local network = me.get_network(pos) local cnetwork = me.get_network(pos)
if network == nil then if cnetwork == nil then
minetest.log("error","no network for ctrl at pos "..minetest.pos_to_string(pos)) minetest.log("error","no network for ctrl at pos "..minetest.pos_to_string(pos))
return return
end end
local size = network:get_item_capacity() local size = cnetwork:get_item_capacity()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", me.int_to_stacks(size)) inv:set_size("main", me.int_to_stacks(size))
@ -97,8 +97,7 @@ me.register_node("ctrl", {
meta:set_string("infotext", "Network Controller (owned by "..name..")") meta:set_string("infotext", "Network Controller (owned by "..name..")")
meta:set_string("owner", name) meta:set_string("owner", name)
end, end,
on_destruct = function(pos, player) on_destruct = function(pos)
local meta = minetest.get_meta(pos)
local net,idx = me.get_network(pos) local net,idx = me.get_network(pos)
if net then if net then
net.controller_pos = nil net.controller_pos = nil
@ -110,7 +109,7 @@ me.register_node("ctrl", {
after_dig_node = function(pos) after_dig_node = function(pos)
me.update_connected_machines(pos) me.update_connected_machines(pos)
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(pos, listname, index, stack)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
local inside_stack = inv:get_stack(listname, index) local inside_stack = inv:get_stack(listname, index)
local stack_name = stack:get_name() local stack_name = stack:get_name()
@ -126,22 +125,22 @@ me.register_node("ctrl", {
local slots, items = 0, 0 local slots, items = 0, 0
-- Get amount of items in drive -- Get amount of items in drive
for i = 1, max_slots do for i = 1, max_slots do
local stack = inv:get_stack("main", i) local dstack = inv:get_stack("main", i)
if stack:get_name() ~= "" then if dstack:get_name() ~= "" then
slots = slots + 1 slots = slots + 1
local num = stack:get_count() local num = dstack:get_count()
if num == 0 then num = 1 end if num == 0 then num = 1 end
items = items + num items = items + num
end end
end end
return math.max(math.min(stack:get_count(),max_items-items),0) return math.max(math.min(stack:get_count(),max_items-items),0)
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, listname, _, stack)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
inv:remove_item(listname, stack) inv:remove_item(listname, stack)
me.insert_item(stack, inv, listname) me.insert_item(stack, inv, listname)
end, end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(_, _, _, stack)
return math.min(stack:get_count(),stack:get_stack_max()) return math.min(stack:get_count(),stack:get_stack_max())
end, end,
machine = { machine = {

@ -43,14 +43,14 @@ function network.adjacent_connected_nodes(pos, include_ctrl)
local nodes = {} local nodes = {}
for _,pos in pairs(adjacent) do for _,apos in pairs(adjacent) do
if network.can_connect(pos) then if network.can_connect(apos) then
if include_ctrl == false then if include_ctrl == false then
if not microexpansion.get_node(pos).name == "microexpansion:ctrl" then if not microexpansion.get_node(apos).name == "microexpansion:ctrl" then
table.insert(nodes, pos) table.insert(nodes, apos)
end end
else else
table.insert(nodes, pos) table.insert(nodes, apos)
end end
end end
end end

@ -2,11 +2,9 @@
local me = microexpansion local me = microexpansion
local networks = me.networks
local path = microexpansion.get_module_path("power") local path = microexpansion.get_module_path("power")
me.power = {} me.power = {}
local power = me.power
-- Load Resources -- Load Resources

@ -56,7 +56,7 @@ function microexpansion.move_inv(inv1, inv2)
local fname, tname = inv1.name, inv2.name local fname, tname = inv1.name, inv2.name
--FIXME only as many as allowed in a drive --FIXME only as many as allowed in a drive
for i,v in ipairs(finv:get_list(fname) or {}) do for _,v in ipairs(finv:get_list(fname) or {}) do
if tinv and tinv:room_for_item(tname, v) then if tinv and tinv:room_for_item(tname, v) then
local leftover = tinv:add_item( tname, v ) local leftover = tinv:add_item( tname, v )
finv:remove_item(fname, v) finv:remove_item(fname, v)

@ -54,19 +54,19 @@ microexpansion.register_node("drive", {
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("main", 10) inv:set_size("main", 10)
end, end,
can_dig = function(pos, player) can_dig = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
return inv:is_empty("main") return inv:is_empty("main")
end, end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player) allow_metadata_inventory_put = function(_, _, _, stack)
if minetest.get_item_group(stack:get_name(), "microexpansion_cell") ~= 0 then if minetest.get_item_group(stack:get_name(), "microexpansion_cell") ~= 0 then
return 1 return 1
else else
return 0 return 0
end end
end, end,
on_metadata_inventory_put = function(pos, listname, index, stack, player) on_metadata_inventory_put = function(pos, _, _, stack)
me.update_connected_machines(pos) me.update_connected_machines(pos)
local network,cp = me.get_connected_network(pos) local network,cp = me.get_connected_network(pos)
if network == nil then if network == nil then
@ -94,7 +94,7 @@ microexpansion.register_node("drive", {
return stack:get_count() return stack:get_count()
end end
local ctrl_meta = minetest.get_meta(cp) local ctrl_meta = minetest.get_meta(cp)
local ctrl_inv = ctrl_meta:get_inventory() local ctrl_inv = ctrl_meta:get_inventory()
local cells = {} local cells = {}
for i = 1, own_inv:get_size("main") do for i = 1, own_inv:get_size("main") do
local cell = own_inv:get_stack("main", i) local cell = own_inv:get_stack("main", i)
@ -151,7 +151,7 @@ microexpansion.register_node("drive", {
return stack:get_count() return stack:get_count()
end, end,
on_metadata_inventory_take = function(pos, listname, index, stack, player) on_metadata_inventory_take = function(pos, _, _, stack)
local network,cp = me.get_connected_network(pos) local network,cp = me.get_connected_network(pos)
if network == nil then if network == nil then
return return
@ -163,9 +163,9 @@ microexpansion.register_node("drive", {
me.update_connected_machines(pos) me.update_connected_machines(pos)
return return
end end
for _,stack in pairs(items) do for _,ostack in pairs(items) do
--this returns 99 (max count) even if it removes more --this returns 99 (max count) even if it removes more
ctrl_inv:remove_item("main", stack) ctrl_inv:remove_item("main", ostack)
end end
print(stack:to_string()) print(stack:to_string())

@ -3,11 +3,11 @@
local me = microexpansion local me = microexpansion
-- [me chest] Get formspec -- [me chest] Get formspec
local function chest_formspec(pos, start_id, listname, page_max, query) local function chest_formspec(pos, start_id, listname, page_max, q)
local list local list
local page_number = "" local page_number = ""
local buttons = "" local buttons = ""
local query = query or "" local query = q or ""
local net,cp = me.get_connected_network(pos) local net,cp = me.get_connected_network(pos)
if cp then if cp then
@ -64,7 +64,6 @@ end
local function update_chest(pos) local function update_chest(pos)
local network = me.get_connected_network(pos) local network = me.get_connected_network(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if network == nil then if network == nil then
meta:set_int("page", 1) meta:set_int("page", 1)
meta:set_string("formspec", chest_formspec(pos, 1)) meta:set_string("formspec", chest_formspec(pos, 1))
@ -72,7 +71,7 @@ local function update_chest(pos)
end end
local size = network:get_item_capacity() local size = network:get_item_capacity()
local page_max = me.int_to_pagenum(size) + 1 local page_max = me.int_to_pagenum(size) + 1
meta:set_string("inv_name", "main") meta:set_string("inv_name", "main")
meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max)) meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max))
end end
@ -104,15 +103,15 @@ microexpansion.register_node("term", {
update_chest(pos) update_chest(pos)
end end
end, end,
on_metadata_inventory_take = function(pos, listname, index, stack, player) on_metadata_inventory_take = function(pos, listname, _, stack)
if listname == "search" then if listname == "search" then
local _,cp = me.get_connected_network(pos) local _,cp = me.get_connected_network(pos)
local inv = minetest.get_meta(cp):get_inventory() local inv = minetest.get_meta(cp):get_inventory()
inv:remove_item("main", stack) inv:remove_item("main", stack)
end end
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, sender)
local network,cp = me.get_connected_network(pos) local _,cp = me.get_connected_network(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local page = meta:get_int("page") local page = meta:get_int("page")
local inv_name = meta:get_string("inv_name") local inv_name = meta:get_string("inv_name")