lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I want to give the luaVM a certain timeslice every frame of execution. I know that there's lua_sethook(), but that's not quite what i'm looking for. What i'm mainly interested in is something like this:


void ScriptEngine::Setup()
{
lua_settimeslice(L, LUA_MASKCOUNT, 5); // return after every 5 instructons
   lua_setpcall(L, <insert something here>);
}

void ScriptEngine::Update(float elapsed)
{
   float timeSlice = 0.0f;
   while (timeSlice < MAX_ALLOWED_SLICE)
   {
      Timer timer();
       lua_pcallfortimeslice(L);
       // will execute 5 instructions, then return.

      timeSlice += timer.elapsed();
   }
}


It would be similar to the hooks in lua, but rather lua calling the hook every 5 instructions, i let it execute those 5 instructions, then it comes back to me.

Because, otherwise, what's the usual idea for letting lua execute only bits every frame?

Cheers!

--
// David Morris-Oliveros
// Camera Coder & Lua Coder ;)
// Team Bondi


------------------------------------------------------------------------
Contact:
Team Bondi Pty Ltd
Level 2, 608 Harris Street
Ultimo, NSW 2007
Australia
Tel: +61 (0)2 8218 1500
Fax: +61 (0)2 8218 1507
Web: http://www.teambondi.com
------------------------------------------------------------------------
This email may contain confidential information.  If you are not
the intended recipient, you may not copy or deliver this message to
anyone. In such case, you should destroy this message and kindly
notify the sender by reply email. Opinions, conclusions and other
information in this message that do not relate to the official business
of our firm shall be understood as neither given nor endorsed by it.
------------------------------------------------------------------------