diff --git a/function.lua b/function.lua index 9ca29fd..12e3968 100644 --- a/function.lua +++ b/function.lua @@ -25,7 +25,7 @@ local function get_function_info (f) info.params = {} info.ups = {} 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 if info.isvararg or not info.nparams then info.params[#info.params+1] = '...' end -- Get upvalues @@ -120,7 +120,7 @@ end return function (value, options, depth, l, format_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) end @@ -130,6 +130,11 @@ return function (value, options, depth, l, format_value) return; end + if info.builtin and options.short_builtins then + l[#l+1] = info.name + return; + end + -- Include function modifier, and alignment info. l[#l+1] = info.builtin and 'builtin ' or '' l[#l+1] = { #l[#l], 'func_mod'} diff --git a/test/test_function.lua b/test/test_function.lua index a8d8b0e..3c9af29 100644 --- a/test/test_function.lua +++ b/test/test_function.lua @@ -232,7 +232,7 @@ format_test { format_test { input = { math.cos, math.sin, math.abs }, 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 +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