Actually, the hardware limit is 8 dynamic lights and, from what I can tell, an unlimited number of static lights. Using models and sprites might help "fake" dynamic lights to some extent.
As for the function, just replace the light_XX_action with whatever the actions are for your dynamic lights. This way, 8 of them get processed per frame, but, to make best use of it, you'll need a decent or sufficient frame rate or you may notice the "faking" of it.