mirror of
https://github.com/TangentFoxy/inspect.lua.git
synced 2025-07-28 11:02:18 +00:00
implement simple rawlen function for Lua 5.1
This commit is contained in:
13
inspect.lua
13
inspect.lua
@@ -31,6 +31,19 @@ local inspect ={
|
|||||||
inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end})
|
inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end})
|
||||||
inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})
|
inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})
|
||||||
|
|
||||||
|
local rawlen = rawlen or function(t)
|
||||||
|
local _M, len = getmetatable(t)
|
||||||
|
if _M then
|
||||||
|
setmetatable(t, {})
|
||||||
|
len = #t
|
||||||
|
setmetatable(t, _M)
|
||||||
|
else
|
||||||
|
len = #t
|
||||||
|
end
|
||||||
|
|
||||||
|
return len
|
||||||
|
end
|
||||||
|
|
||||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
||||||
-- Otherwise, it returns a regular quoted string
|
-- Otherwise, it returns a regular quoted string
|
||||||
local function smartQuote(str)
|
local function smartQuote(str)
|
||||||
|
Reference in New Issue
Block a user