/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function deprecate(o,name,instead) local msg = "%sWarning, deprecated feature "..(name and ("'"..name.."' ") or "").."in use."..(instead and (" Use '"..instead.."' instead.") or "") if(type(o) == "table") then return setmetatable({},{__index = function (t,k) local _,callpoint = pcall(function() error("",4) end) print(string.format(msg,string.gsub(callpoint,"(^w%*%.%w*%:%d+)","%1"))) return o[k] end, __newindex = function (t,k,v) local _,callpoint = pcall(function() error("",4) end) print(string.format(msg,string.gsub(callpoint,"(^w%*%.%w*%:%d+)","%1"))) o[k] = v return o[k] end }) elseif(type(o) == "function") then return function(...) local _,callpoint = pcall(function() error("",4) end) print(string.format(msg,string.gsub(callpoint,"(^w%*%.%w*%:%d+)","%1"))) return o(unpack(arg)) end end end Ace = {} function Ace:print(msg) print(msg) end function foo() print("FOO!") end ace = deprecate(Ace,"ace","Ace") FOO = deprecate(foo,"FOO","foo") FOO() ace:print("moo") ./deprecate.lua:38: Warning, deprecated feature 'FOO' in use. Use 'foo' instead. FOO! ./deprecate.lua:39: Warning, deprecated feature 'ace' in use. Use 'Ace' instead. moo