1
0

Improved resilience of library.

This commit is contained in:
Jon Michael Aanes 2017-04-14 13:24:29 +02:00
parent 9050d53962
commit f29004fe17
4 changed files with 24 additions and 12 deletions

View File

@ -2,10 +2,12 @@
local function_library = {}
local function library_function ( func_def )
-- TODO: Add clause requiring that func_def.func is a builtin.
if func_def.func then
if not func_def.func then return false end
local is_func_builtin = not debug or not debug.getinfo or (debug.getinfo(func_def.func, 'S').what == 'C')
if not is_func_builtin then return false end
function_library[func_def.func] = func_def
end
end
--------------------------------------------------------------------------------
@ -1334,7 +1336,7 @@ end
--------------------------------------------------------------------------------
-- FFI
-- TODO
-- TODO: Add FFI documentation
-- Documentation is here: http://luajit.org/ext_ffi_api.html
--------------------------------------------------------------------------------

View File

@ -462,10 +462,9 @@ local TYPE_TO_FORMAT_FUNC = {
['thread'] = format_coroutine,
['table'] = format_table,
-- TODO
['function'] = format_function,
['userdata'] = format_primitive,
['cdata'] = format_primitive, -- Luajit exclusive ?
['function'] = format_function, -- TODO: Improve a little
['userdata'] = format_primitive, -- TODO
['cdata'] = format_primitive, -- TODO & Luajit only
}
function format_value (value, _, depth, l)

View File

@ -124,7 +124,7 @@ format_test {
--------------------------------------------------------------------------------
-- Userdata printing
-- TODO. First off figure out a way to test this stuff.
-- TODO: Figure out a way to print userdata.
-- Maybe look into using the one available debug.getupvalue(pairs, 1)
--------------------------------------------------------------------------------

View File

@ -57,7 +57,7 @@ end)
SUITE:addTest('a_very_small_part_of_math', function ()
-- This tests whether one could load the library with an empty env, without
-- an error.
local env = { math = { abs = math.abs } }
local env = { debug = debug, math = { abs = math.abs } }
local library = setfenv(loadfile('./library.lua'), env)()
assert( library[math.abs], 'Why is math.abs not defined in the library?' )
@ -66,13 +66,24 @@ end)
SUITE:addTest('redefined part of math', function ()
-- This tests whether the library ignores a redefined function of an
-- builtin, when defining documentation.
local env = { setfenv = setfenv, loadfile = function() end }
local env = { debug = debug, setfenv = setfenv, loadfile = function() end }
local library = setfenv(loadfile('./library.lua'), env)()
assert( library[env.setfenv], 'Why is setfenv not defined in the library?' )
assert( not library[env.loadfile], 'Why is loadfile defined in the library?' )
end)
SUITE:addTest('redefined part of math 2', function ()
-- This tests whether the library allows a redefined function of an
-- builtin, when defining documentation, due to not being able to determine
-- the origin of the function.
local env = { setfenv = setfenv, loadfile = function() end }
local library = setfenv(loadfile('./library.lua'), env)()
assert( library[env.setfenv], 'Why is setfenv not defined in the library?' )
assert( library[env.loadfile], 'Why is loadfile not defined in the library?' )
end)
--------------------------------------------------------------------------------
return SUITE