thanks so much, i tried as bellow, but my C knowledge is BAD and I guess there is not just one bug in my converting to lua 
function moon_phase(y, m, d)
--[[
calculates the moon phase (0-7), accurate to 1 segment.
0 = > new moon.
4 => full moon.
--]]
local c = 0;
local e = 0;
local jd = 0;
local b = 0;
if (m < 3) then
y=y-1;
m=m+ 12;
end
m = m+1; – ++m;
c = 365.25*y;
e = 30.6*m;
jd = c+e+d-694039.09; – jd is total days elapsed */
jd = jd / 29.53; – divide by the moon cycle (29.53 days) */
b = jd; – int(jd) -> b, take integer part of jd */
jd = jd- b; – subtract integer part to leave fractional part of original jd */
b = jd*8 + 0.5; – scale fraction from 0-8 and round by adding 0.5 */
– b = b & 7; – 0 and 8 are the same so turn 8 into 0 */
if b == 8 then b = 0 end
return b;
end
i guess special the ++m is wrong and b = b & 7
any bug fix is welcomed 
