1
0

Added short_builtins

This commit is contained in:
Jon Michael Aanes 2017-04-03 13:56:06 +02:00
parent 588e5588ac
commit 9695a27394
2 changed files with 15 additions and 3 deletions

View File

@ -25,7 +25,7 @@ local function get_function_info (f)
info.params = {} info.params = {}
info.ups = {} info.ups = {}
info.env = debug.getfenv and debug.getfenv(f) info.env = debug.getfenv and debug.getfenv(f)
info.builtin = info.source == '=[C]' info.builtin = (info.source == '=[C]')
for i = 1, info.nparams or 0 do info.params[i] = debug.getlocal(f, i) end for i = 1, info.nparams or 0 do info.params[i] = debug.getlocal(f, i) end
if info.isvararg or not info.nparams then info.params[#info.params+1] = '...' end if info.isvararg or not info.nparams then info.params[#info.params+1] = '...' end
-- Get upvalues -- Get upvalues
@ -120,7 +120,7 @@ end
return function (value, options, depth, l, format_value) return function (value, options, depth, l, format_value)
local info = get_function_info(value) local info = get_function_info(value)
if options.include_closure then if options.include_closure and not info.builtin then
return format_function_with_closure(value, options, depth, l, format_value) return format_function_with_closure(value, options, depth, l, format_value)
end end
@ -130,6 +130,11 @@ return function (value, options, depth, l, format_value)
return; return;
end end
if info.builtin and options.short_builtins then
l[#l+1] = info.name
return;
end
-- Include function modifier, and alignment info. -- Include function modifier, and alignment info.
l[#l+1] = info.builtin and 'builtin ' or '' l[#l+1] = info.builtin and 'builtin ' or ''
l[#l+1] = { #l[#l], 'func_mod'} l[#l+1] = { #l[#l], 'func_mod'}

View File

@ -232,7 +232,7 @@ format_test {
format_test { format_test {
input = { math.cos, math.sin, math.abs }, input = { math.cos, math.sin, math.abs },
options = { short_builtins = true }, options = { short_builtins = true },
expect = '{ math.cos, math.sin, math.abs }', expect = '{\n\tmath.cos,\n\tmath.sin,\n\tmath.abs\n}',
} }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -339,6 +339,13 @@ do
end end
format_test {
name = 'Closures do not affect builtins',
input = math.abs,
options = { more_function_info = true, include_closure = true },
expect = 'builtin function (x)\n\t-- math.abs\n\t-- Returns the absolute value of x.\n\n\t...\nend',
}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Indent functions nicely -- Indent functions nicely