- 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
- 598x
- 1x
- 585x
- 585x
- 451x
- 451x
- 134x
- 54x
- 54x
- 8x
- 46x
- 46x
- 6x
- 46x
- 1x
- 1x
- 1x
- -------------------------------------------------------------------------------
- -- Extended type functions handling PUMAS metatypes as well
- -- Author: Valentin Niess
- -- License: GNU LGPL-3.0
- -------------------------------------------------------------------------------
- -- XXX Add string representations for all metatypes
- -------------------------------------------------------------------------------
- -- Return the PUMAS metatype. Fallback to the usual type otherwise
- -------------------------------------------------------------------------------
- local metatype
- do
- local function get_metatype (obj)
- return obj.__metatype
- end
- function metatype (_, obj)
- local tp = type(obj)
- if (tp == 'table') or (tp == 'cdata') then
- local ok, mt = pcall(get_metatype, obj)
- if (ok and mt) then return mt else return tp end
- else
- return tp
- end
- end
- end
- -------------------------------------------------------------------------------
- -- Return `a {metatype}` handling the nil case and metatypes
- -------------------------------------------------------------------------------
- local function a_metatype (obj)
- local mt = metatype(nil, obj)
- if mt == 'nil' then
- return mt
- else
- local tp = type(obj)
- if mt ~= tp then
- mt = mt..' '..tp
- end
- return 'a '..mt
- end
- end
- -------------------------------------------------------------------------------
- -- Return the package
- -------------------------------------------------------------------------------
- return setmetatable(
- {a = a_metatype},
- {__call = metatype})