Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local meta={
- isNum=true;
- __add=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __add on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal+bVal
- end;
- __sub=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __sub on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal-bVal
- end;
- __mul=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __mul on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal*bVal
- end;
- __div=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __div on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal/bVal
- end;
- __mod=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __mod on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal%bVal
- end;
- __pow=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __pow on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal^bVal
- end;
- __unm=function(a)
- local aVal
- local isANum = (type(a)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- if not isANum then
- error("attempt to perform arithmetic on "..(isANum and "number" or type(a)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- return -aVal
- end;
- __concat=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number" or type(a)=="string"), (type(b)=="number" or type(b)=="string")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to concatenate "..((isANum and type(a)=="table" and "number") or type(a)).." and "..((isBNum and type(b)=="table" and "number") or type(b)),2)
- return nil
- end
- if type(a)== "table" then aVal=a["value"] else aVal=a end
- if type(b)== "table" then bVal=b["value"] else bVal=b end
- return aVal..bVal
- end;
- __len=function(a)
- local aVal
- local isANum = (type(a)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- if isANum or not (type(a)=="string" or type(a)=="table") then
- error("attempt to get length of "..(isANum and "number" or type(a)),2)
- return nil
- end
- return #a
- end;
- __eq=function(a,b)
- local aVal,bVal
- local isANum, isBNum = nil, nil
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if isANum then aVal=a["value"] else aVal=a end
- if isBNum then bVal=b["value"] else bVal=b end
- return aVal==bVal
- end;
- __lt=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __lt on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal<bVal
- end;
- __le=function(a,b)
- local aVal,bVal
- local isANum, isBNum = (type(a)=="number"), (type(b)=="number")
- isANum=isANum or (type(a)=="table" and getmetatable(a)["isNum"])
- isBNum=isBNum or (type(b)=="table" and getmetatable(b)["isNum"])
- if not isANum or not isBNum then
- error("attempt to perform arithmetic __le on "..(isANum and "number" or type(a)).." and "..(isBNum and "number" or type(b)),2)
- return nil
- end
- if type(a)~= "number" then aVal=a["value"] else aVal=a end
- if type(b)~= "number" then bVal=b["value"] else bVal=b end
- return aVal<=bVal
- end;
- __index=function() error("attempt to index ?: a number value",2) end;
- __newindex=function() error("attempt to index ?: a number value",2) end;
- __call=function() error("attempt to call number",2) end;
- }
- function newFakeNum(value)
- local t={value=value}
- return setmetatable(t,meta)
- end
Advertisement
Add Comment
Please, Sign In to add comment