mirror of
https://github.com/minetest-mods/MoreMesecons.git
synced 2024-11-16 07:20:18 +01:00
Various code fixes detected by luacheck
* Luablock: Fix the missing position argument when executing the lua code fails * Wireless: Fix the missing id argument * Localize several variables * Some other small changes, e.g. dead code removal
This commit is contained in:
parent
28292dc2a5
commit
c41d0371c0
|
@ -62,7 +62,7 @@ local function resolve_commands(commands, pos)
|
||||||
nearest = player:get_player_name()
|
nearest = player:get_player_name()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
new_commands = commands:gsub("@nearest", nearest)
|
local new_commands = commands:gsub("@nearest", nearest)
|
||||||
return new_commands, min_distance, new_commands ~= commands
|
return new_commands, min_distance, new_commands ~= commands
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,19 +17,19 @@ end
|
||||||
local dual_delayer_activate = function(pos, node)
|
local dual_delayer_activate = function(pos, node)
|
||||||
mesecon.receptor_on(pos, {dual_delayer_get_output_rules(node)[1]}) -- Turn on the port 1
|
mesecon.receptor_on(pos, {dual_delayer_get_output_rules(node)[1]}) -- Turn on the port 1
|
||||||
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_10", param2 = node.param2})
|
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_10", param2 = node.param2})
|
||||||
minetest.after(0.4, function(pos, node)
|
minetest.after(0.4, function()
|
||||||
mesecon.receptor_on(pos, {dual_delayer_get_output_rules(node)[2]}) -- Turn on the port 2
|
mesecon.receptor_on(pos, {dual_delayer_get_output_rules(node)[2]}) -- Turn on the port 2
|
||||||
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_11", param2 = node.param2})
|
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_11", param2 = node.param2})
|
||||||
end, pos, node)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local dual_delayer_deactivate = function(pos, node, link)
|
local dual_delayer_deactivate = function(pos, node, link)
|
||||||
mesecon.receptor_off(pos, {dual_delayer_get_output_rules(node)[2]}) -- Turn off the port 2
|
mesecon.receptor_off(pos, {dual_delayer_get_output_rules(node)[2]}) -- Turn off the port 2
|
||||||
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_10", param2 = node.param2})
|
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_10", param2 = node.param2})
|
||||||
minetest.after(0.4, function(pos, node)
|
minetest.after(0.4, function()
|
||||||
mesecon.receptor_off(pos, {dual_delayer_get_output_rules(node)[1]}) -- Turn off the port 1
|
mesecon.receptor_off(pos, {dual_delayer_get_output_rules(node)[1]}) -- Turn off the port 1
|
||||||
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_00", param2 = node.param2})
|
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_00", param2 = node.param2})
|
||||||
end, pos, node)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,6 @@ local function induction_transmitter_get_output_rules(node)
|
||||||
return {vector.multiply(minetest.facedir_to_dir(node.param2), 2)}
|
return {vector.multiply(minetest.facedir_to_dir(node.param2), 2)}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function induction_transmitter_get_virtual_output_rules(node)
|
|
||||||
return {minetest.facedir_to_dir(node.param2)}
|
|
||||||
end
|
|
||||||
|
|
||||||
local function act(pos, node, state)
|
local function act(pos, node, state)
|
||||||
minetest.swap_node(pos, {name = "moremesecons_induction_transmitter:induction_transmitter_"..state, param2 = node.param2})
|
minetest.swap_node(pos, {name = "moremesecons_induction_transmitter:induction_transmitter_"..state, param2 = node.param2})
|
||||||
|
|
||||||
|
|
|
@ -128,33 +128,33 @@ minetest.register_node("moremesecons_luablock:luablock", {
|
||||||
env.pos = table.copy(npos)
|
env.pos = table.copy(npos)
|
||||||
env.mem = minetest.deserialize(meta:get_string("mem")) or {}
|
env.mem = minetest.deserialize(meta:get_string("mem")) or {}
|
||||||
|
|
||||||
local func, err
|
local func, err_syntax
|
||||||
if _VERSION == "Lua 5.1" then
|
if _VERSION == "Lua 5.1" then
|
||||||
func, err = loadstring(code)
|
func, err_syntax = loadstring(code)
|
||||||
if func then
|
if func then
|
||||||
setfenv(func, env)
|
setfenv(func, env)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
func, err = load(code, nil, "t", env)
|
func, err_syntax = load(code, nil, "t", env)
|
||||||
end
|
end
|
||||||
if not func then
|
if not func then
|
||||||
meta:set_string("errmsg", err)
|
meta:set_string("errmsg", err_syntax)
|
||||||
make_formspec(meta, pos)
|
make_formspec(meta, npos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local good, err = pcall(func)
|
local good, err_runtime = pcall(func)
|
||||||
|
|
||||||
if not good then -- Runtime error
|
if not good then
|
||||||
meta:set_string("errmsg", err)
|
meta:set_string("errmsg", err_runtime)
|
||||||
make_formspec(meta, pos)
|
make_formspec(meta, npos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_string("mem", minetest.serialize(env.mem))
|
meta:set_string("mem", minetest.serialize(env.mem))
|
||||||
|
|
||||||
meta:set_string("errmsg", "")
|
meta:set_string("errmsg", "")
|
||||||
make_formspec(meta, pos)
|
make_formspec(meta, npos)
|
||||||
end
|
end
|
||||||
}}
|
}}
|
||||||
})
|
})
|
||||||
|
|
|
@ -76,14 +76,17 @@ end]]
|
||||||
local file_path = minetest.get_worldpath().."/MoreMesecons_lctt"
|
local file_path = minetest.get_worldpath().."/MoreMesecons_lctt"
|
||||||
|
|
||||||
-- load templates from a compressed file
|
-- load templates from a compressed file
|
||||||
local templates_file = io.open(file_path, "rb")
|
do
|
||||||
if templates_file then
|
local templates_file = io.open(file_path, "rb")
|
||||||
local templates_raw = templates_file:read("*all")
|
if templates_file then
|
||||||
io.close(templates_file)
|
local templates_raw = templates_file:read("*all")
|
||||||
if templates_raw
|
io.close(templates_file)
|
||||||
and templates_raw ~= "" then
|
if templates_raw
|
||||||
for name,t in pairs(minetest.deserialize(minetest.decompress(templates_raw))) do
|
and templates_raw ~= "" then
|
||||||
templates[name] = t
|
local data = minetest.deserialize(minetest.decompress(templates_raw))
|
||||||
|
for name,t in pairs(data) do
|
||||||
|
templates[name] = t
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -80,7 +80,7 @@ minetest.register_node("moremesecons_switchtorch:switchtorch_on", {
|
||||||
selection_box = torch_selectionbox,
|
selection_box = torch_selectionbox,
|
||||||
groups = {dig_immediate=3, not_in_creative_inventory = 1},
|
groups = {dig_immediate=3, not_in_creative_inventory = 1},
|
||||||
drop = "moremesecons_switchtorch:switchtorch_off",
|
drop = "moremesecons_switchtorch:switchtorch_off",
|
||||||
light_source = LIGHT_MAX-5,
|
light_source = 9,
|
||||||
mesecons = {receptor = {
|
mesecons = {receptor = {
|
||||||
state = mesecon.state.on,
|
state = mesecon.state.on,
|
||||||
rules = torch_get_output_rules
|
rules = torch_get_output_rules
|
||||||
|
|
|
@ -24,12 +24,12 @@ local function teleport_nearest(pos)
|
||||||
|
|
||||||
-- Search for the nearest player
|
-- Search for the nearest player
|
||||||
local nearest = nil
|
local nearest = nil
|
||||||
local min_distance = MAX_PLAYER_DISTANCE
|
local min_distance_player = MAX_PLAYER_DISTANCE
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for _, player in pairs(players) do
|
for _, player in pairs(players) do
|
||||||
local distance = vector.distance(pos, player:getpos())
|
local distance = vector.distance(pos, player:getpos())
|
||||||
if distance <= min_distance then
|
if distance <= min_distance_player then
|
||||||
min_distance = distance
|
min_distance_player = distance
|
||||||
nearest = player
|
nearest = player
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,7 +35,7 @@ local function timegate_activate(pos, node)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
|
local boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
|
||||||
|
|
||||||
{ -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator
|
{ -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator
|
||||||
{ -3/16, -7/16, -3/16, 3/16, -26/64, -2/16 },
|
{ -3/16, -7/16, -3/16, 3/16, -26/64, -2/16 },
|
||||||
|
|
|
@ -243,12 +243,11 @@ MapDataStorage.__index = {
|
||||||
indices[i] = ("%.17g"):format(vi)
|
indices[i] = ("%.17g"):format(vi)
|
||||||
values[i] = v
|
values[i] = v
|
||||||
end
|
end
|
||||||
result = {
|
return minetest.serialize({
|
||||||
version = "MapDataStorage_v1",
|
version = "MapDataStorage_v1",
|
||||||
indices = "return {" .. table.concat(indices, ",") .. "}",
|
indices = "return {" .. table.concat(indices, ",") .. "}",
|
||||||
values = minetest.serialize(values),
|
values = minetest.serialize(values),
|
||||||
}
|
})
|
||||||
return minetest.serialize(result)
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
MapDataStorage.deserialize = function(txtdata)
|
MapDataStorage.deserialize = function(txtdata)
|
||||||
|
@ -317,6 +316,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
-- This testing code shows an example usage of the MapDataStorage code
|
-- This testing code shows an example usage of the MapDataStorage code
|
||||||
local function do_test()
|
local function do_test()
|
||||||
print("Test if iter returns correct positions when a lot is set")
|
print("Test if iter returns correct positions when a lot is set")
|
||||||
|
@ -377,5 +377,5 @@ local function do_test()
|
||||||
|
|
||||||
--~ data:iterAll()
|
--~ data:iterAll()
|
||||||
end
|
end
|
||||||
--~ do_test()
|
do_test()
|
||||||
|
--]]
|
||||||
|
|
|
@ -186,10 +186,10 @@ function wireless_receptor_off(pos, id, network, check)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function activate_network(owner, channel)
|
local function activate_network(owner, channel)
|
||||||
local network = wireless[owner][channel]
|
local network = wireless[owner][channel]
|
||||||
for _, wl_pos in pairs(network.members) do
|
for i, wl_pos in pairs(network.members) do
|
||||||
wireless_receptor_on(wl_pos, id, network)
|
wireless_receptor_on(wl_pos, i, network)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -300,7 +300,6 @@ mesecon.register_node("moremesecons_wireless:wireless", {
|
||||||
mesecon.receptor_off(pos)
|
mesecon.receptor_off(pos)
|
||||||
end,
|
end,
|
||||||
after_place_node = function(pos, placer)
|
after_place_node = function(pos, placer)
|
||||||
local placername = placer:get_player_name()
|
|
||||||
set_owner(pos, placer:get_player_name())
|
set_owner(pos, placer:get_player_name())
|
||||||
end,
|
end,
|
||||||
on_receive_fields = function(pos, _, fields, player)
|
on_receive_fields = function(pos, _, fields, player)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user