Replaced prints by minetest.log and code styling

This commit is contained in:
Pierre-Yves Rollo 2019-03-14 09:46:04 +01:00
parent 0ca85ac5c1
commit 6162f49bc1
2 changed files with 24 additions and 13 deletions

View File

@ -22,7 +22,8 @@
function deprecated_group(deprecated_group, replacement_group)
for name, ndef in pairs(minetest.registered_nodes) do
if ndef.groups and ndef.groups[deprecated_group] then
minetest.log("warning", string.format('Node %s belongs to deprecated "%s" group which should be replaced with new "%s" group.',
minetest.log("warning", string.format(
'Node %s belongs to deprecated "%s" group which should be replaced with new "%s" group.',
name, deprecated_group, replacement_group))
end
end
@ -33,9 +34,10 @@ function deprecated_global_table(deprecated_global_name, replacement_global_name
assert(type(replacement_global_name) == 'string', "replacement_global_name should be a string.")
assert(deprecated_global_name ~= '', "deprecated_global_name should not be empty.")
assert(replacement_global_name ~= '', "replacement_global_name should not be empty.")
assert(rawget(_G, deprecated_global_name) == nil, "replacement global already exists.")
assert(rawget(_G, deprecated_global_name) == nil, "deprecated global does not exist.")
if _G[replacement_global_name] == nil then
print('warn_deprecated_functions: Warning, replacement global "'..replacement_global_name..'" does not exists.')
minetest.log('warning', string.format(
'Replacement global "%s" does not exists.', replacement_global_name))
return
end
local meta = {
@ -44,15 +46,19 @@ function deprecated_global_table(deprecated_global_name, replacement_global_name
__index = function(table, key)
local meta = getmetatable(table)
local dbg = debug.getinfo(2, "lS")
minetest.log("warning", string.format('Warning: Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'), (dbg.currentline or 0)))
minetest.log("warning", string.format(
'Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'),
(dbg.currentline or 0)))
return _G[meta.replacement][key]
end,
__newindex = function(table, key, value)
local meta = getmetatable(table)
local dbg = debug.getinfo(2, "lS")
minetest.log("warning", string.format('Warning: Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'), (dbg.currentline or 0)))
minetest.log("warning", string.format(
'Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'),
(dbg.currentline or 0)))
_G[meta.replacement][key]=value
end,
}

View File

@ -23,9 +23,10 @@ function deprecated_global_table(deprecated_global_name, replacement_global_name
assert(type(replacement_global_name) == 'string', "replacement_global_name should be a string.")
assert(deprecated_global_name ~= '', "deprecated_global_name should not be empty.")
assert(replacement_global_name ~= '', "replacement_global_name should not be empty.")
assert(rawget(_G, deprecated_global_name) == nil, "replacement global already exists.")
assert(rawget(_G, deprecated_global_name) == nil, "deprecated global does not exist.")
if _G[replacement_global_name] == nil then
print('warn_deprecated_functions: Warning, replacement global "'..replacement_global_name..'" does not exists.')
minetest.log('warning', string.format(
'Replacement global "%s" does not exists.', replacement_global_name))
return
end
local meta = {
@ -34,15 +35,19 @@ function deprecated_global_table(deprecated_global_name, replacement_global_name
__index = function(table, key)
local meta = getmetatable(table)
local dbg = debug.getinfo(2, "lS")
minetest.log("warning", string.format('Warning: Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'), (dbg.currentline or 0)))
minetest.log("warning", string.format(
'Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'),
(dbg.currentline or 0)))
return _G[meta.replacement][key]
end,
__newindex = function(table, key, value)
local meta = getmetatable(table)
local dbg = debug.getinfo(2, "lS")
minetest.log("warning", string.format('Warning: Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'), (dbg.currentline or 0)))
minetest.log("warning", string.format(
'Accessing deprecated "%s" table, "%s" should be used instead (%s:%d).',
meta.deprecated, meta.replacement, (dbg.short_src or 'unknown'),
(dbg.currentline or 0)))
_G[meta.replacement][key]=value
end,
}