Indent to stirng
This commit is contained in:
parent
736335b208
commit
e5e23422ef
43
function.lua
43
function.lua
|
@ -88,6 +88,15 @@ local function width_of_strings_in_l (l, start_i, end_i)
|
||||||
return width
|
return width
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function add_indent_to_string (str, indent)
|
||||||
|
local l = {}
|
||||||
|
for line in string.gmatch(str, '\n', true) do
|
||||||
|
l[#l+1] = indent
|
||||||
|
l[#l+1] = line
|
||||||
|
end
|
||||||
|
return table.concat(l, '\n')
|
||||||
|
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)
|
||||||
|
@ -155,10 +164,11 @@ return function (value, options, depth, l, format_value)
|
||||||
|
|
||||||
-- More info! --
|
-- More info! --
|
||||||
|
|
||||||
|
local indent = '\n' .. options.indent
|
||||||
|
|
||||||
-- Name
|
-- Name
|
||||||
if info.name then
|
if info.name then
|
||||||
l[#l+1] = '\n'
|
l[#l+1] = indent
|
||||||
l[#l+1] = options.indent
|
|
||||||
l[#l+1] = '-- '
|
l[#l+1] = '-- '
|
||||||
l[#l+1] = info.name
|
l[#l+1] = info.name
|
||||||
end
|
end
|
||||||
|
@ -166,8 +176,7 @@ return function (value, options, depth, l, format_value)
|
||||||
-- Doc
|
-- Doc
|
||||||
if info.doc then
|
if info.doc then
|
||||||
for doc_line in info.doc:gmatch('[^\n]+') do
|
for doc_line in info.doc:gmatch('[^\n]+') do
|
||||||
l[#l+1] = '\n'
|
l[#l+1] = indent
|
||||||
l[#l+1] = options.indent
|
|
||||||
l[#l+1] = '-- '
|
l[#l+1] = '-- '
|
||||||
|
|
||||||
l[#l+1] = doc_line
|
l[#l+1] = doc_line
|
||||||
|
@ -176,8 +185,7 @@ return function (value, options, depth, l, format_value)
|
||||||
|
|
||||||
-- source
|
-- source
|
||||||
if not info.builtin then
|
if not info.builtin then
|
||||||
l[#l+1] = '\n'
|
l[#l+1] = indent
|
||||||
l[#l+1] = options.indent
|
|
||||||
l[#l+1] = ('-- source_file: \'%s\' '):format(info.short_src)
|
l[#l+1] = ('-- source_file: \'%s\' '):format(info.short_src)
|
||||||
if info.linedefined == info.lastlinedefined then
|
if info.linedefined == info.lastlinedefined then
|
||||||
l[#l+1] = ('[Line: %i]'):format(info.linedefined)
|
l[#l+1] = ('[Line: %i]'):format(info.linedefined)
|
||||||
|
@ -188,8 +196,7 @@ return function (value, options, depth, l, format_value)
|
||||||
|
|
||||||
-- upvalues
|
-- upvalues
|
||||||
if info.nups > 0 and not info.builtin then
|
if info.nups > 0 and not info.builtin then
|
||||||
l[#l+1] = '\n'
|
l[#l+1] = indent
|
||||||
l[#l+1] = options.indent
|
|
||||||
l[#l+1] = '-- up_values: '
|
l[#l+1] = '-- up_values: '
|
||||||
format_value(info.ups, options, depth + 1, l)
|
format_value(info.ups, options, depth + 1, l)
|
||||||
end
|
end
|
||||||
|
@ -197,20 +204,22 @@ return function (value, options, depth, l, format_value)
|
||||||
if options._all_function_info then
|
if options._all_function_info then
|
||||||
-- NOTE: This is for testing/debugging/experimentation purposes.
|
-- NOTE: This is for testing/debugging/experimentation purposes.
|
||||||
|
|
||||||
local function_str = get_function_str_from_file(info.short_src, info.linedefined, info.lastlinedefined)
|
l[#l+1] = indent
|
||||||
|
l[#l+1] = '--[[ Function Body:\n\t'
|
||||||
|
l[#l+1] = add_indent_to_string(get_function_str_from_file(info.short_src, info.linedefined, info.lastlinedefined), options.indent)
|
||||||
|
l[#l+1] = indent
|
||||||
|
l[#l+1] = '--]]'
|
||||||
|
|
||||||
l[#l+1] = '\n\t--[[ Function Body\n\t'
|
l[#l+1] = indent
|
||||||
l[#l+1] = function_str
|
l[#l+1] = '--[[\n\tNative repr:'
|
||||||
l[#l+1] = '\n\t--]]'
|
|
||||||
|
|
||||||
l[#l+1] = '\n\t--[[\n\tNative repr:'
|
|
||||||
l[#l+1] = tostring(value)
|
l[#l+1] = tostring(value)
|
||||||
l[#l+1] = '\n\t'
|
l[#l+1] = indent
|
||||||
format_value(info, options, depth + 1, l)
|
format_value(info, options, depth + 1, l)
|
||||||
|
l[#l+1] = indent
|
||||||
l[#l+1] = '--]]'
|
l[#l+1] = '--]]'
|
||||||
end
|
end
|
||||||
|
|
||||||
l[#l+1] = '\n\n'
|
l[#l+1] = '\n'
|
||||||
l[#l+1] = options.indent
|
l[#l+1] = indent
|
||||||
l[#l+1] = '...\nend'
|
l[#l+1] = '...\nend'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user