xtype (halted)

Check-in [9470e9e52e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improve check functions to return booleans.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9470e9e52ed5fe16193a2f98878cbe12da43e50aab8fe5a26612b0415ad74495
User & Date: imagic 2021-11-11 20:10:09.000
Context
2021-11-14
18:01
Minor doc improvements. ... (check-in: 90e4f5b8b9 user: imagic tags: trunk)
2021-11-11
20:10
Improve check functions to return booleans. ... (check-in: 9470e9e52e user: imagic tags: trunk)
2021-11-10
19:54
Add rockspec. ... (check-in: 0fddfde383 user: imagic tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/xtype.lua.
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
end
xtype.get = xtype_get

-- Check if a value is of type t.
xtype_is = function(v, t)
  check_type(t, 2)
  local vt = xtype_get(v)
  if type(vt) == "table" then return vt.xtype_set[t]
  else return vt == t end
end
xtype.is = xtype_is

-- Create a type.
--
-- The created type is a table with 3 fields: xtype_name, xtype_stack and xtype_set.







|







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
end
xtype.get = xtype_get

-- Check if a value is of type t.
xtype_is = function(v, t)
  check_type(t, 2)
  local vt = xtype_get(v)
  if type(vt) == "table" then return vt.xtype_set[t] ~= nil
  else return vt == t end
end
xtype.is = xtype_is

-- Create a type.
--
-- The created type is a table with 3 fields: xtype_name, xtype_stack and xtype_set.
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  end
  return t
end

-- Check if a type is of type ot.
function xtype.of(t, ot)
  check_type(t, 1); check_type(ot, 2)
  if type(t) == "table" then return t.xtype_set[ot]
  else return t == ot end
end

-- Get the name of a type.
-- return string or nothing if not a type
function xtype.name(t)
  if xtype_check(t) then return type(t) == "string" and t or t.xtype_name end







|







168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  end
  return t
end

-- Check if a type is of type ot.
function xtype.of(t, ot)
  check_type(t, 1); check_type(ot, 2)
  if type(t) == "table" then return t.xtype_set[ot] ~= nil
  else return t == ot end
end

-- Get the name of a type.
-- return string or nothing if not a type
function xtype.name(t)
  if xtype_check(t) then return type(t) == "string" and t or t.xtype_name end