You could watch the playback position and detect when it returned to the start of the loop, then call your function. It won't be perfectly precise though.
There was a similar thread recently for a JSFX I think.
Code:
function callback()
-- do something when the loop restarts
end
function detectLoopRestart()
if someCondition then
callback()
end
reaper.defer(detectLoopRestart)
end
detectLoopRestart()