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
|
||||
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)
|
||||
|
@ -155,10 +164,11 @@ return function (value, options, depth, l, format_value)
|
|||
|
||||
-- More info! --
|
||||
|
||||
local indent = '\n' .. options.indent
|
||||
|
||||
-- Name
|
||||
if info.name then
|
||||
l[#l+1] = '\n'
|
||||
l[#l+1] = options.indent
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = '-- '
|
||||
l[#l+1] = info.name
|
||||
end
|
||||
|
@ -166,8 +176,7 @@ return function (value, options, depth, l, format_value)
|
|||
-- Doc
|
||||
if info.doc then
|
||||
for doc_line in info.doc:gmatch('[^\n]+') do
|
||||
l[#l+1] = '\n'
|
||||
l[#l+1] = options.indent
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = '-- '
|
||||
|
||||
l[#l+1] = doc_line
|
||||
|
@ -176,8 +185,7 @@ return function (value, options, depth, l, format_value)
|
|||
|
||||
-- source
|
||||
if not info.builtin then
|
||||
l[#l+1] = '\n'
|
||||
l[#l+1] = options.indent
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = ('-- source_file: \'%s\' '):format(info.short_src)
|
||||
if info.linedefined == info.lastlinedefined then
|
||||
l[#l+1] = ('[Line: %i]'):format(info.linedefined)
|
||||
|
@ -188,8 +196,7 @@ return function (value, options, depth, l, format_value)
|
|||
|
||||
-- upvalues
|
||||
if info.nups > 0 and not info.builtin then
|
||||
l[#l+1] = '\n'
|
||||
l[#l+1] = options.indent
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = '-- up_values: '
|
||||
format_value(info.ups, options, depth + 1, l)
|
||||
end
|
||||
|
@ -197,20 +204,22 @@ return function (value, options, depth, l, format_value)
|
|||
if options._all_function_info then
|
||||
-- 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] = function_str
|
||||
l[#l+1] = '\n\t--]]'
|
||||
|
||||
l[#l+1] = '\n\t--[[\n\tNative repr:'
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = '--[[\n\tNative repr:'
|
||||
l[#l+1] = tostring(value)
|
||||
l[#l+1] = '\n\t'
|
||||
l[#l+1] = indent
|
||||
format_value(info, options, depth + 1, l)
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = '--]]'
|
||||
end
|
||||
|
||||
l[#l+1] = '\n\n'
|
||||
l[#l+1] = options.indent
|
||||
l[#l+1] = '\n'
|
||||
l[#l+1] = indent
|
||||
l[#l+1] = '...\nend'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user