• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lunarmodules / Penlight / 583

11 Aug 2025 02:27PM UTC coverage: 89.269% (+0.4%) from 88.871%
583

Pull #498

appveyor

web-flow
fix(*): some more Lua 5.5 fixes for constant loop variables (#499)
Pull Request #498: fix(*): some Lua 5.5 fixes for constant loop variables

23 of 24 new or added lines in 4 files covered. (95.83%)

79 existing lines in 14 files now uncovered.

5482 of 6141 relevant lines covered (89.27%)

165.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/lua/pl/import_into.lua
1
--------------
2
-- PL loader, for loading all PL libraries, only on demand.
3
-- Whenever a module is implicitly accessed, the table will have the module automatically injected.
4
-- (e.g. `_ENV.tablex`)
5
-- then that module is dynamically loaded. The submodules are all brought into
6
-- the table that is provided as the argument, or returned in a new table.
7
-- If a table is provided, that table's metatable is clobbered, but the values are not.
8
-- This module returns a single function, which is passed the environment.
9
-- If this is `true`, then return a 'shadow table' as the module
10
-- See @{01-introduction.md.To_Inject_or_not_to_Inject_|the Guide}
11

12
-- @module pl.import_into
13

14
return function(env)
15
    local mod
16
    if env == true then
18✔
UNCOV
17
        mod = {}
3✔
UNCOV
18
        env = {}
3✔
19
    end
20
    local env = env or {}
18✔
21

22
    local modules = {
18✔
23
        utils = true,path=true,dir=true,tablex=true,stringio=true,sip=true,
18✔
24
        input=true,seq=true,lexer=true,stringx=true,
18✔
25
        config=true,pretty=true,data=true,func=true,text=true,
18✔
26
        operator=true,lapp=true,array2d=true,
18✔
27
        comprehension=true,xml=true,types=true,
18✔
28
        test = true, app = true, file = true, class = true,
18✔
29
        luabalanced = true, permute = true, template = true,
18✔
30
        url = true, compat = true,
18✔
31
        -- classes --
32
        List = true, Map = true, Set = true,
18✔
33
        OrderedMap = true, MultiMap = true, Date = true,
18✔
34
    }
35
    rawset(env,'utils',require 'pl.utils')
18✔
36

37
    for name,klass in pairs(env.utils.stdmt) do
90✔
38
        klass.__index = function(t,key)
39
            return require ('pl.'..name)[key]
×
40
        end;
41
    end
42

43
    -- ensure that we play nice with libraries that also attach a metatable
44
    -- to the global table; always forward to a custom __index if we don't
45
    -- match
46

47
    local _hook,_prev_index
48
    local gmt = {}
18✔
49
    local prevenvmt = getmetatable(env)
18✔
50
    if prevenvmt then
18✔
51
        _prev_index = prevenvmt.__index
4✔
52
        if prevenvmt.__newindex then
4✔
53
            gmt.__newindex = prevenvmt.__newindex
×
54
        end
55
    end
56

57
    function gmt.hook(handler)
18✔
58
        _hook = handler
×
59
    end
60

61
    function gmt.__index(t,name)
18✔
62
        local found = modules[name]
22✔
63
        -- either true, or the name of the module containing this class.
64
        -- either way, we load the required module and make it globally available.
65
        if found then
22✔
66
            -- e..g pretty.dump causes pl.pretty to become available as 'pretty'
67
            rawset(env,name,require('pl.'..name))
19✔
68
            return env[name]
19✔
69
        else
70
            local res
UNCOV
71
            if _hook then
3✔
72
                res = _hook(t,name)
×
73
                if res then return res end
×
74
            end
UNCOV
75
            if _prev_index then
3✔
76
                return _prev_index(t,name)
×
77
            end
78
        end
79
    end
80

81
    if mod then
18✔
UNCOV
82
        function gmt.__newindex(t,name,value)
3✔
UNCOV
83
            mod[name] = value
3✔
UNCOV
84
            rawset(t,name,value)
3✔
85
        end
86
    end
87

88
    setmetatable(env,gmt)
18✔
89

90
    return env,mod or env
18✔
91
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc