This is of course not exactly what you want, just looks almost the same.
Saw function is from wikipedia formula I posted above (trigonometric version) and in lua looks like:
Code:
function saw(x,period)
if x ~= nil and period ~= nil then return
0.5-(math.atan(1/math.tan((x*math.pi)/period)))/math.pi
end
end
(I didn`t short it, just wrote directly as is)