[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Turning an entire script into a coroutine
- From: "Richard Ranft" <rranft@...>
- Date: Sun, 13 Feb 2005 08:17:44 -0800
Have you thought of using a table to keep active object handles? Then you
just pass the handle in and it knows what to do. Each object on the C++
side keeps its own handle and can therefore pass it (or heck, use the this
pointer as the handle maybe) to the script engine when it gets its turn to
Of course, I've never tried it, I'm just popping off.
You might want to take a look at Game Scripting Mastery as well as
Programming in Lua for more useful hints - GSM has a short example of
getting the Lua interpreter working with a very small game framework in C.
[mailto:email@example.com]On Behalf Of Michael Abbott
Sent: Sunday, February 13, 2005 4:58 AM
Subject: Turning an entire script into a coroutine
I'm fairly new to both Lua the language and the C-API, so please bear
with me. I also hope this hasn't been asked to often, I've done
searches through the archives and come across similar information but
nothing that really solves my particular situation.
I have a number of entities in a game I'm working on and I want to bind
a lua script to each entity that will be used to describe it's
behaviour. I want to do this with coroutines so that each entity can
yield once it has done it's current bit of the update. There appeared
to be some functions called lua_cobegin(), etc. that helped implement
coroutines from the C end in the lua 4 days, but I can't find it in the
version I'm using (5.0.2) so I assume it's deprecated.
I want to implement something that looks like this:
-- various state functions will go in this section
while true do
-- initialisation code and the call to the first state will go here
This doesn't appear possible by what I can tell because the yield()
would need to know what coroutine this script is in relation to (a
script is not a coroutine right?). Please tell me I'm wrong because I'm
not proud of the next solution I started implementing. So I ended up
doing something like this:
while true do
From the C-side of things, I lua_open(), luaopen_base() (to get the
coroutines). I then luaL_loadfile() the script. I then call
lua_call(). I assume this now creates a global player_idle function and
then returns a new coroutine. From the C side of things I now have a
number on the stack, but I'm not sure what to do with that number?
Where do I go from here?
Thanks in advance,
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 10/02/2005