Merge remote-tracking branch 'upstream/master' into feat/mod-bundles
* upstream/master: Add parameter defaults and better error messages for dump and dump_to_file (#37)
This commit is contained in:
commit
78000cde56
2 changed files with 23 additions and 24 deletions
2
dtmt.cfg
2
dtmt.cfg
|
@ -1,7 +1,7 @@
|
||||||
id = "DMF"
|
id = "DMF"
|
||||||
name = "Darktide Mod Framework"
|
name = "Darktide Mod Framework"
|
||||||
summary = "An open-source, community-run framework that provides enhanced Darktide modding support."
|
summary = "An open-source, community-run framework that provides enhanced Darktide modding support."
|
||||||
version = "2023-02-18"
|
version = "2023-05-10"
|
||||||
author = "Aussiemon"
|
author = "Aussiemon"
|
||||||
image = "assets/dmf_logo_black.png"
|
image = "assets/dmf_logo_black.png"
|
||||||
|
|
||||||
|
|
|
@ -60,18 +60,22 @@ local function table_dump(key, value, depth, max_depth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
|
DMFMod.dump = function (self, dumped_object, object_name, max_depth)
|
||||||
|
if dmf.check_wrong_argument_type(self, "dump", "dumped_object_name", object_name, "string", "nil") or
|
||||||
if dmf.check_wrong_argument_type(self, "dump", "dumped_object_name", dumped_object_name, "string", "nil") or
|
dmf.check_wrong_argument_type(self, "dump", "max_depth", max_depth, "number", "nil")
|
||||||
dmf.check_wrong_argument_type(self, "dump", "max_depth", max_depth, "number")
|
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local object_type = type(dumped_object)
|
local object_type = type(dumped_object)
|
||||||
|
max_depth = max_depth or 1
|
||||||
|
|
||||||
if object_type ~= "table" then
|
if object_type ~= "table" then
|
||||||
local error_message = "(dump): \"object_name\" is not a table. It's " .. object_type
|
local error_message = string.format(
|
||||||
|
'(dump): "%s" is not a table but of type "%s"',
|
||||||
|
object_name or "Dump object",
|
||||||
|
object_type
|
||||||
|
)
|
||||||
|
|
||||||
if object_type ~= "nil" then
|
if object_type ~= "nil" then
|
||||||
error_message = error_message .. " (" .. tostring(dumped_object) .. ")"
|
error_message = error_message .. " (" .. tostring(dumped_object) .. ")"
|
||||||
|
@ -81,13 +85,8 @@ DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if dumped_object_name then
|
if object_name then
|
||||||
log_and_console_print(string.format("<%s>", dumped_object_name))
|
log_and_console_print(string.format("<%s>", object_name))
|
||||||
end
|
|
||||||
|
|
||||||
if not max_depth then
|
|
||||||
self:error("(dump): maximum depth is not specified")
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local success, error_message = pcall(function()
|
local success, error_message = pcall(function()
|
||||||
|
@ -100,17 +99,12 @@ DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
|
||||||
self:error("(dump): %s", tostring(error_message))
|
self:error("(dump): %s", tostring(error_message))
|
||||||
end
|
end
|
||||||
|
|
||||||
if dumped_object_name then
|
if object_name then
|
||||||
log_and_console_print(string.format("</%s>", dumped_object_name))
|
log_and_console_print(string.format("</%s>", object_name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function table_dump_to_file(dumped_table, dumped_table_name, max_depth)
|
local function table_dump_to_file(dumped_table, dumped_table_name, max_depth)
|
||||||
|
|
||||||
-- #####################
|
-- #####################
|
||||||
|
@ -348,17 +342,22 @@ end
|
||||||
|
|
||||||
|
|
||||||
DMFMod.dump_to_file = function (self, dumped_object, object_name, max_depth)
|
DMFMod.dump_to_file = function (self, dumped_object, object_name, max_depth)
|
||||||
|
if dmf.check_wrong_argument_type(self, "dump_to_file", "object_name", object_name, "string", "nil") or
|
||||||
if dmf.check_wrong_argument_type(self, "dump_to_file", "object_name", object_name, "string") or
|
dmf.check_wrong_argument_type(self, "dump_to_file", "max_depth", max_depth, "number", "nil")
|
||||||
dmf.check_wrong_argument_type(self, "dump_to_file", "max_depth", max_depth, "number")
|
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local object_type = type(dumped_object)
|
local object_type = type(dumped_object)
|
||||||
|
object_name = object_name or "mod_dump_to_file"
|
||||||
|
max_depth = max_depth or 1
|
||||||
|
|
||||||
if object_type ~= "table" then
|
if object_type ~= "table" then
|
||||||
local error_message = "(dump_to_file): \"object_name\" is not a table. It's " .. object_type
|
local error_message = string.format(
|
||||||
|
'(dump_to_file): "%s" is not a table but of type "%s"',
|
||||||
|
object_name or "Dump object",
|
||||||
|
object_type
|
||||||
|
)
|
||||||
|
|
||||||
if object_type ~= "nil" then
|
if object_type ~= "nil" then
|
||||||
error_message = error_message .. " (" .. tostring(dumped_object) .. ")"
|
error_message = error_message .. " (" .. tostring(dumped_object) .. ")"
|
||||||
|
|
Loading…
Add table
Reference in a new issue