Improved error messages, and fixed issue with importing from other modules
This commit is contained in:
parent
ae73cc9b64
commit
ec3ba2cab9
|
@ -1,5 +1,10 @@
|
||||||
|
|
||||||
local TABLE_TYPE = require "table_type"
|
local TABLE_TYPE
|
||||||
|
do
|
||||||
|
local thispath = ... and select('1', ...):match('.+%.') or ''
|
||||||
|
was_loaded, TABLE_TYPE = pcall(require, thispath..'table_type')
|
||||||
|
assert(was_loaded, '[pretty]: Could not load vital library: table_type')
|
||||||
|
end
|
||||||
|
|
||||||
local RESERVED_LUA_WORDS = {
|
local RESERVED_LUA_WORDS = {
|
||||||
['and'] = true,
|
['and'] = true,
|
||||||
|
@ -147,7 +152,9 @@ function is_short_table (value)
|
||||||
-- Predicate: value is either an empty table, or one with a single simple
|
-- Predicate: value is either an empty table, or one with a single simple
|
||||||
-- non-function element.
|
-- non-function element.
|
||||||
|
|
||||||
assert( type(value) == 'table', '[analyze_structure]: Only tables allowed!' )
|
if type(value) ~= 'table' then
|
||||||
|
error(('[pretty/internal]: Only tables allowed in function analyze_structure.is_short_table, but was given %s (%s)'):format(value, type(value)), 2)
|
||||||
|
end
|
||||||
|
|
||||||
local first_key = next(value, nil)
|
local first_key = next(value, nil)
|
||||||
if not first_key then
|
if not first_key then
|
||||||
|
|
|
@ -102,7 +102,6 @@ end
|
||||||
local function format_function_with_closure (value, options, depth, l, format_value)
|
local function format_function_with_closure (value, options, depth, l, format_value)
|
||||||
local info = get_function_info(value)
|
local info = get_function_info(value)
|
||||||
|
|
||||||
--assert(info.nups > 0)
|
|
||||||
local function_str = nil
|
local function_str = nil
|
||||||
if (info.defined_how == 'string') then
|
if (info.defined_how == 'string') then
|
||||||
function_str = get_full_function_str(info.source, info.linedefined, info.lastlinedefined)
|
function_str = get_full_function_str(info.source, info.linedefined, info.lastlinedefined)
|
||||||
|
|
13
pretty.lua
13
pretty.lua
|
@ -13,9 +13,10 @@ do
|
||||||
-- Load other stuff
|
-- Load other stuff
|
||||||
local was_loaded
|
local was_loaded
|
||||||
was_loaded, analyze_structure = pcall(require, thispath..'analyze_structure')
|
was_loaded, analyze_structure = pcall(require, thispath..'analyze_structure')
|
||||||
assert(was_loaded)
|
print(was_loaded, analyze_structure)
|
||||||
|
assert(was_loaded, '[pretty]: Could not load vital library: analyze_structure')
|
||||||
was_loaded, TABLE_TYPE = pcall(require, thispath..'table_type')
|
was_loaded, TABLE_TYPE = pcall(require, thispath..'table_type')
|
||||||
assert(was_loaded)
|
assert(was_loaded, '[pretty]: Could not load vital library: table_type')
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
|
|
||||||
|
@ -238,7 +239,9 @@ local SIMPLE_VALUE_TYPES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local function is_empty_table (value)
|
local function is_empty_table (value)
|
||||||
assert( type(value) == 'table', '[is_empty_table]: Only tables allowed!' )
|
if type(value) ~= 'table' then
|
||||||
|
error(('[pretty/internal]: Only tables allowed in function pretty.is_empty_table, but was given %s (%s)'):format(value, type(value)), 2)
|
||||||
|
end
|
||||||
return next(value) == nil
|
return next(value) == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -246,7 +249,9 @@ local function is_short_table (value)
|
||||||
-- In this context, a short table is either an empty table, or one with a
|
-- In this context, a short table is either an empty table, or one with a
|
||||||
-- single element.
|
-- single element.
|
||||||
|
|
||||||
assert( type(value) == 'table', '[is_short_table]: Only tables allowed!' )
|
if type(value) ~= 'table' then
|
||||||
|
error(('[pretty/internal]: Only tables allowed in function pretty.is_short_table, but was given %s (%s)'):format(value, type(value)), 2)
|
||||||
|
end
|
||||||
|
|
||||||
local first_key = next(value)
|
local first_key = next(value)
|
||||||
return (not first_key or SIMPLE_VALUE_TYPES[type(value[first_key])])
|
return (not first_key or SIMPLE_VALUE_TYPES[type(value[first_key])])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user