TypeOf |
|
當使用 module() 函數建立模組時,它會增加一個模組名稱的值為 metatable._NAME。此函數會利用此預設行為。注意:這不適用於 C 延伸模組,除非作者特別加入此值。
function typeof(var) local _type = type(var); if(_type ~= "table" and _type ~= "userdata") then return _type; end local _meta = getmetatable(var); if(_meta ~= nil and _meta._NAME ~= nil) then return _meta._NAME; else return _type; end end