Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add handling in logging functions for tables with defined len key #409

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions msu/utils/log.nut
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
local fixCounter = 0;
local locals = ::MSU.Table.filter(line.locals, @(_key, _val) _key != "this" && _key != "_release_hook_DO_NOT_delete_it_");

if (locals.len() != 0)
local localsString = "";
foreach (key, value in locals)
{
string += "<div class=\"function-container\"><div style=\"color:green;\" class=\"label\">Variables:</div><div class=\"valueVar\">";
foreach (key, value in locals)
{
string += format("%s = %s, ", key, this.getLocalString(value, _maxLen, _maxDepth, _advanced, false));
}
localsString += format("%s = %s, ", key, this.getLocalString(value, _maxLen, _maxDepth, _advanced, false));
}
if (localsString != "")
{
string += "<div class=\"function-container\"><div style=\"color:green;\" class=\"label\">Variables:</div><div class=\"valueVar\">" + localsString;
string = string.slice(0, string.len() - 2) + "</div></div>";
}
}
Expand All @@ -42,17 +43,26 @@

function formatData( _data, _maxDepth = 1, _advanced = false, _maxLenMin = 1, _printClasses = true )
{
if (["array", "table"].find(typeof _data) != null && _data.len() > _maxLenMin)
local len = 0;
local obj = _data;;
switch (typeof _data)
{
_maxLenMin = _data.len();
}
else if (["class", "instance"].find(typeof _data) != null)
{
local len = 0;
local classed = typeof _data == "instance" ? _data.getclass() : _data;
foreach (key, value in classed) ++len;
if (len > _maxLenMin) _maxLenMin = len;
case "table":
len = this.__safeLen(_data);
break;

case "instance":
obj = _data.getclass();
case "class":
foreach (k, v in obj) ++len;
break;

case "array":
len = _data.len();
break;
}

if (len > _maxLenMin) _maxLenMin = len;
return this.getLocalString(_data, _maxLenMin, _maxDepth, _advanced, _printClasses);
}

Expand All @@ -70,14 +80,16 @@
if (_value.len() != 0) ret = ret.slice(0, -2);
ret += "]";
}
else if (typeof _value == "table" && _value.len() <= _maxLen && _depth > 0) // full table
else if (typeof _value == "table" && _depth > 0 && this.__safeLen(_table) <= _maxLen) // full table
{
ret += "{";
local len = 0;
foreach (key, value in _value)
{
ret += format("%s = %s, ", key.tostring(), this.getLocalString(value, _maxLen, _depth - 1, _advanced, _printClasses));
len++;
}
if (_value.len() != 0) ret = ret.slice(0, -2);
if (len != 0) ret = ret.slice(0, -2);
ret += "}";
}
else if (["instance", "class"].find(typeof _value) != null && _depth > 0 && _printClasses) // full instance or class
Expand Down Expand Up @@ -111,4 +123,17 @@
}
return ret;
}

function __safeLen( _table )
{
if (_table.len == {}.len)
return _table.len();

local ret = 0;
foreach (k, v in _table)
{
ret++;
}
return ret;
}
}