lua-users home
lua-l archive

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



> -----Original Message-----
> From: Ignacio Castaño [mailto:castanyo@yahoo.es]
> Sent: Wednesday, 21 May 2003 11:50 AM
> To: Lua list
> Subject: Re: Game Integration
> 
> 
> Sorry Chris, that's what you would do on the C side:
> 
> First, create your main lua state with lua_open.
> 
> Create a new thread for each scripts that you want to run in 
> parallel, that
> is a state with its own stack.
> 
> Instead of lua_dofile, use lua_load or any of the functions 
> that provides
> the aux library (ie. luaL_loadbuffer). That parses your 
> script and leaves
> the main function on the top of the stack.
> 
> Instead of using lua_pcall to run that function, use 
> lua_resume, that way,
> it will yield when it finds a yield function. You can resume 
> the thread as
> many times as you want, but you will have to use some kind of 
> return codes
> to determine the end of the execution (or use lua_getstack).
> 
> while(1) {
>     lua_resume( thread, 0 );
> 
>     // check return code
>     if( !lua_isnil( thread ) ) break;
> 
>     // render your world
>     ...
> }
> 
> 
> > Ignacio, are you suggesting that my game script need to 
> call in to my C
> > code to 'resume'. If that is so doesn't it mean that the 
> misson script
> will
> > need to know how to drive the game, rather than just be 
> concerned about
> the
> > mission at hand?
> 
> I was suggesting the use of a message queue to have better 
> control over the
> execution of the script. Instead of resuming the script every 
> frame you
> could do it just when the script wants, that is, after a few 
> seconds, when
> an animation ends, when some event happens, etc.
> 
> 
> Hope that helps,
> 
> 
> Ignacio Castaño
> castanyo@yahoo.es
> 
> 
> Chris Brodie wrote:
> I still cannot see how I can get the C code working. How do I stop my
> lua_dofile from blocking my applications main loop from executing?
> 
> For example I run a script that runs my mission. How can the 
> game render
> while the mission is running? The script never returns. If someone can
> suggest a way that doesn't block my games code from executing 
> I'll also need
> some kind of C function to resume that script periodically.
> 
> I thank everyone for their help but nobody seems to suggest 
> what I should be
> doing ni C to make this all work.
> 
> Ignacio, are you suggesting that my game script need to call 
> in to my C code
> to 'resume'. If that is so doesn't it mean that the misson 
> script will need
> to know how to drive the game, rather than just be concerned about the
> mission at hand?
> 
> 
> 


NOTICE
This e-mail and any attachments are confidential and may contain copyright material of Macquarie Bank or third parties. If you are not the intended recipient of this email you should not read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and should destroy all copies of them. Macquarie Bank does not guarantee the integrity of any emails or any attached files. The views or opinions expressed are the author's own and may not reflect the views or opinions of Macquarie Bank.