Capping the framerate? (not noob)

Hello, ladies and gentlemen of the SDL list!

Okay. You all know what Lua is, right? If not, ignore this thread.

Here’s my question. I’ve got a Lua script that will call SDL functions.
Well, I need to cap the framerate to 60FPS without the user having to
do anything to the script.

I thought of making the user have a ‘main loop’ function in Lua that
will execute in my program’s main loop, which will do the capping. But I
can’t do that. Don’t ask why, I’ve got my reasons.

So, anything like…

SDL_CapFramerate(60);

… that I can put in main() and will affect the whole program?

Yes? No? Didn’t think so. So what’s the closest approach?

Thanks in advance for any help provided!

(P.S., I know Allegro can do this, but it doesn’t support alpha
transparency which also is an underlined need.)

Hello !

… that I can put in main() and will affect the whole program?

Yes? No? Didn’t think so. So what’s the closest approach?

Thanks in advance for any help provided!

?!?!?!

Sorry i don’t see where the problem is.
I never used Lua, but i can image 3 cases :

  1. You can call SDL functions directly from Lua.
    Then do something like in Lua of course :

At the start of your main loop :

Uint32 startticks;
startticks = SDL_GetTicks ();

At the end :

Uint32 endticks = startticks + (1000/60);
SDL_Delay (therestofyourframetime);

  1. You can call C functions from Lua :

Then put the stuff from 1 into two C functions.

  1. You can only modify variables and arrays
    from Lua, then put it into the main loop of your c code
    at the start and end of it.

It affects all your code, but this is something
you normally want, when you have a frame limiter.

CU