Skip to content

Commit c27ee55

Browse files
committed
refactor: rename base.objtype to std.type internally.
* specs/spec_helper.lua (objtype): Correct a reference to base.lua:objtype in a comment. * specs/object_spec.yaml: Show the difference between the object module table, and the root Object more clearly. * lib/std/base.lua (objtype): Rename from this... (type): ...to this. * lib/std.lua.in, lib/std/container.lua, lib/std/debug.lua, lib/std/object.lua, lib/std/operator.lua, lib/std/set.lua, lib/std/tree.lua, lib/std/tuple.lua: Adjust all callers. Signed-off-by: Gary V. Vaughan <gary@vaughan.pe>
1 parent 563bd1b commit c27ee55

File tree

11 files changed

+91
-92
lines changed

11 files changed

+91
-92
lines changed

lib/std.lua.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ M = {
280280
-- @param x anything
281281
-- @treturn string type of *x*
282282
-- @see std.object.type
283-
type = X ("type (?any)", std.objtype),
283+
type = X ("type (?any)", std.type),
284284

285285
version = "General Lua libraries / @VERSION@",
286286
}

lib/std/base.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,6 @@ local function collect (ifn, ...)
304304
end
305305

306306

307-
local function objtype (o)
308-
return (getmetatable (o) or {})._type or io.type (o) or type (o)
309-
end
310-
311-
312307
local function reduce (fn, d, ifn, ...)
313308
local argt = {...}
314309
if not callable (ifn) then
@@ -466,6 +461,11 @@ return {
466461
require = require,
467462
tostring = tostring,
468463

464+
type = function (x)
465+
return (getmetatable (x) or {})._type or io.type (x) or type (x)
466+
end,
467+
468+
469469
-- debug.lua --
470470
argerror = argerror,
471471

@@ -482,7 +482,6 @@ return {
482482
compare = compare,
483483

484484
-- object.lua --
485-
objtype = objtype,
486485

487486
-- package.lua --
488487
dirsep = dirsep,

lib/std/container.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ local debug = require "std.debug"
3838

3939
local ipairs, pairs, okeys = std.ipairs, std.pairs, std.okeys
4040
local insert, len = std.insert, std.len
41-
local okeys, objtype, tostring = std.okeys, std.objtype, std.tostring
41+
local okeys, stdtype, tostring = std.okeys, std.type, std.tostring
4242
local argcheck = debug.argcheck
4343

4444

@@ -232,7 +232,7 @@ end
232232

233233
function M.__tostring (self)
234234
local n, k_ = 1, nil
235-
local buf = { objtype (self), " {" } -- pre-buffer object open
235+
local buf = { stdtype (self), " {" } -- pre-buffer object open
236236
for _, k in ipairs (okeys (self)) do -- for ordered public members
237237
local v = self[k]
238238

@@ -296,8 +296,8 @@ return setmetatable ({
296296
-- it has to be done manually.
297297

298298
mapfields = modulefunction (M.mapfields),
299-
prototype = modulefunction (objtype),
300-
type = modulefunction (objtype),
299+
prototype = modulefunction (stdtype),
300+
type = modulefunction (stdtype),
301301
}, {
302302
_type = "Container",
303303

lib/std/debug.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ local std = require "std.base"
3434

3535
local _DEBUG = debug_init._DEBUG
3636
local argerror, raise = std.argerror, std.raise
37-
local objtype, unpack = std.objtype, std.unpack
37+
local stdtype, unpack = std.type, std.unpack
3838
local copy, split, tostring = std.copy, std.split, std.tostring
3939
local insert, last, len, maxn = std.insert, std.last, std.len, std.maxn
4040
local ipairs, pairs = std.ipairs, std.pairs
@@ -253,7 +253,7 @@ end
253253

254254

255255
local function extramsg_mismatch (expectedtypes, actual, index)
256-
local actualtype = objtype (actual)
256+
local actualtype = stdtype (actual)
257257

258258
-- Tidy up actual type for display.
259259
if actualtype == "nil" then
@@ -364,7 +364,7 @@ if _DEBUG.argcheck then
364364
end
365365
end
366366

367-
actualtype = objtype (actual)
367+
actualtype = stdtype (actual)
368368
if check == actualtype then
369369
return true
370370
elseif check == "list" or check == "#list" then

lib/std/object.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
-- Container is derived from it. Confused? ;-)
3131

3232

33-
local std = require "std.base"
3433
local container = require "std.container"
3534
local debug = require "std.debug"
35+
local std = require "std.base"
3636

3737
local Container = container {}
38-
local getmetamethod, objtype = std.getmetamethod, std.objtype
38+
local getmetamethod = std.getmetamethod
3939

4040
local DEPRECATED = debug.DEPRECATED
4141

@@ -122,7 +122,7 @@ return Container {
122122
--
123123
-- It's conventional to organise similar objects according to a
124124
-- string valued *\_type* field, which can then be queried using this
125-
-- function.
125+
-- method.
126126
--
127127
-- Additionally, this function returns the results of @{io.type} for
128128
-- file objects, or @{type} otherwise.
@@ -152,7 +152,7 @@ return Container {
152152
-- assert (objtype (h) == io.type (h))
153153
--
154154
-- assert (type {} == type {})
155-
type = objtype,
155+
type = std.type,
156156

157157

158158
--- Return *obj* with references to the fields of *src* merged in.
@@ -189,7 +189,7 @@ return Container {
189189

190190

191191
-- Backwards compatibility:
192-
prototype = DEPRECATED ("41.3", "'std.object.prototype'", objtype),
192+
prototype = DEPRECATED ("41.3", "'std.object.prototype'", std.type),
193193
},
194194

195195

lib/std/operator.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
local std = require "std.base"
88

9-
local pairs, objtype, tostring =
10-
std.pairs, std.objtype, std.tostring
9+
local pairs, stdtype, tostring =
10+
std.pairs, std.type, std.tostring
1111

1212

1313
local function eqv (a, b)
@@ -18,7 +18,7 @@ local function eqv (a, b)
1818
-- Unless we have two tables, what we have cannot be equivalent here.
1919
if type (a) ~= "table" or type (b) ~= "table" then return false end
2020

21-
local type_a, type_b = objtype (a), objtype (b)
21+
local type_a, type_b = stdtype (a), stdtype (b)
2222
if type_a ~= type_b then return false end
2323

2424
local keyeqv = {} -- keys requiring recursive equivalence test

lib/std/set.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ local std = require "std.base"
2121

2222
local Container = require "std.container" {}
2323

24-
local ielems, pairs, type = std.ielems, std.pairs, std.objtype
24+
local ielems, pairs, type = std.ielems, std.pairs, std.type
2525

2626

2727
local Set -- forward declaration

lib/std/tree.lua

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ local operator = require "std.operator"
2222

2323
local Container = require "std.container" {}
2424

25-
local ielems, ipairs, leaves, pairs, objtype =
26-
std.ielems, std.ipairs, std.leaves, std.pairs, std.objtype
25+
local ielems, ipairs, leaves, pairs, stdtype =
26+
std.ielems, std.ipairs, std.leaves, std.pairs, std.type
2727
local last, len = std.last, std.len
2828
local reduce = std.reduce
2929

@@ -138,12 +138,12 @@ Tree = Container {
138138
-- @usage
139139
-- del_other_window = keymap[{"C-x", "4", KEY_DELETE}]
140140
__index = function (tr, i)
141-
if objtype (i) == "table" then
142-
return reduce (operator.get, tr, ielems, i)
143-
else
144-
return rawget (tr, i)
145-
end
146-
end,
141+
if stdtype (i) == "table" then
142+
return reduce (operator.get, tr, ielems, i)
143+
else
144+
return rawget (tr, i)
145+
end
146+
end,
147147

148148
--- Deep insertion.
149149
-- @static
@@ -154,18 +154,18 @@ Tree = Container {
154154
-- @usage
155155
-- function bindkey (keylist, fn) keymap[keylist] = fn end
156156
__newindex = function (tr, i, v)
157-
if objtype (i) == "table" then
158-
for n = 1, len (i) - 1 do
159-
if objtype (tr[i[n]]) ~= "Tree" then
160-
rawset (tr, i[n], Tree {})
161-
end
162-
tr = tr[i[n]]
163-
end
164-
rawset (tr, last (i), v)
165-
else
166-
rawset (tr, i, v)
167-
end
168-
end,
157+
if stdtype (i) == "table" then
158+
for n = 1, len (i) - 1 do
159+
if stdtype (tr[i[n]]) ~= "Tree" then
160+
rawset (tr, i[n], Tree {})
161+
end
162+
tr = tr[i[n]]
163+
end
164+
rawset (tr, last (i), v)
165+
else
166+
rawset (tr, i, v)
167+
end
168+
end,
169169

170170
_functions = {
171171
--- Make a deep copy of a tree, including any metatables.

lib/std/tuple.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
]]
2323

2424
local Container = require "std.container" {}
25-
local objtype = require "std.base".objtype
25+
local stdtype = require "std.base".type
2626

2727

2828
-- Stringify tuple values, as a memoization key.
@@ -133,6 +133,6 @@ return Container {
133133
-- -- 'Tuple ("nil", nil, false)'
134134
-- print (Tuple ("nil", nil, false))
135135
__tostring = function (self)
136-
return ("%s (%s)"):format (objtype (self), argstr (self))
136+
return ("%s (%s)"):format (stdtype (self), argstr (self))
137137
end,
138138
}

0 commit comments

Comments
 (0)