-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.lua
More file actions
115 lines (94 loc) · 3.49 KB
/
Copy pathinit.lua
File metadata and controls
115 lines (94 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
--[[
Debug Hints Library for Lua 5.1, 5.2, 5.3, 5.4 & 5.5
Copyright (C) 2002-2026 std._debug authors
]]
--[[--
Manage debug mode, and associated substate hints.
Set or change all the debug substate hints by calling the returned
module functable with no argument to reset to defaults; with `true`
to set all substate hints into development mode, or `false` for
production mode.
local _debug = require 'std._debug'(false)
Query substate hints by indexing the returned module functable keys:
local isstrict = _debug.strict
Beware that even though you can change std._debug state at any time,
stdlib libraries in particular (but probably other clients too) are
configured at load time according to the state at the time they are
required - e.g. changing _debug.strict after require 'std' does not
affect the strict environment already created for the 'std' module
when it was previously loaded.
@module std._debug
]]
local _DEBUG = 'default'
--- Nothing!
local spec = {
argcheck = { default=true, safe=true, fast=false},
deprecate = { default=nil, safe=true, fast=false},
level = { default=1, safe=1, fast=math.huge},
strict = { default=true, safe=true, fast=false},
}
local metatable = {
--- Metamethods
-- @section metamethods
--- Change the all builtin debug hints.
-- @function __call
-- @bool[opt] enable or disable all debugging substate hints
-- @treturn Substates substates
-- @usage
-- -- Enable all debugging substates
-- local _debug = require 'std._debug'(true)
__call = function(self, x)
if x == true then
_DEBUG = 'safe'
elseif x == false then
_DEBUG = 'fast'
elseif x == nil then
_DEBUG = 'default'
else
error("bad argument #1 to '_debug' (boolean or nil expected, got " .. type(x) .. ')', 2)
end
return self
end,
--- Lazy loading of std._debug modules.
-- Don't load everything on initial startup, wait until first attempt
-- to access a submodule, and then load it on demand.
-- @function __index
-- @string name submodule name
-- @treturn table|nil the submodule that was loaded to satisfy the missing
-- `name`, otherwise `nil` if nothing was found
-- @usage
-- local version = require 'std._debug'.version
__index = function(_, name)
local v = spec[name]
if type(v) == 'table' then
return v[_DEBUG]
elseif v ~= nil then
return v
end
local ok, r = pcall(require, 'std._debug.' .. name)
if ok then
spec[name] = r
return r
end
end,
}
return setmetatable({}, metatable)
--- Types
-- @section types
--- Builtin debug substate hints.
--
-- Use `__call` metamethod to set all substate hints at once.
-- Note that none of the debugging features required to implement these
-- hints are encoded here, this module is merely a central location to
-- record systemwide hint; other modules you load subsequently may or may
-- not choose to behave according to their content.
-- @table Substates
-- @bool[opt=true] argcheck `true` if runtime argument checking is desired
-- @bool[opt] deprecate `nil` if deprecated api warnings are desired;
-- `false` if deprecated apis without warnings are desired; `true` if
-- removal of deprecated apis is preferred
-- @int[opt=1] level debugging level
-- @bool[opt=true] strict `true` if strict enforcement of variable declaration
-- before use is desired
-- @usage
-- require 'std._debug'.argcheck = false