[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Best way to pause (sleep?) inside of lua script
- From: Thomas Wrensch <twrensch@...>
- Date: Fri, 9 Dec 2005 16:21:41 +0000 (UTC)
I suggest using coroutines.
Each user script is a function that is wrapped in a coroutine. Functions
like sleep call yield. The scripts can be managed by a simple scheduler
written in Lua (There's one on the Wiki somewhere, and I can send you one
if that one doesn't work).
The problem with this technique is that coroutines can't yield if there is
a C-call between them. This is not to say you can't call into C/C++ code
from a coroutine, just that you cannot have situations such as having a
Lua coroutine call C-code, which in turn executes some Lua code, which in
turn does a yield. This problem has been discussed extensively on the
list in the past.
The advantage is natural scripts that doesn't need to register action
handlers, and the ability to share a single Lua state for all scripts.
I'm not sure if this approach will work for you. Depends on the
architecture of your MUD.
On Thu, 8 Dec 2005, John Klimek wrote:
Date: Thu, 8 Dec 2005 16:09:12 -0500
From: John Klimek <email@example.com>
Reply-To: Lua list <firstname.lastname@example.org>
To: Lua list <email@example.com>
Subject: Best way to pause (sleep?) inside of lua script
I'm developing a MUD (multi-user dungeon game) as a side project and
I'm going to use Lua for scripting. You've probably seen my last
e-mail regarding how to share objects but I have that mostly figured
out. However, I have another question...
Let's say I want to have a script do something like this: (pseudo-code)
npc = CreateNPC("Bob");
npc:Say("Hello everybody in the room!");
SLEEP(1000); -- Sleep for one second
SLEEP(1000); -- Sleep for another second
npc:Say("I'm being really annoying now!!");
Now I'm not even sure if SLEEP() is the correct command, but as far as
my host application is concerned if I pause in a Lua script it will
halt the entire program until lua_dofile() returns.
What's the best way to implement the Lua scripting engine into a game?
How can I get Lua to pause (eg. sleep) without stopping my entire game?
Can one Lua instance be shared between shared threads? (eg. several
players in the game will be executing Lua scripts)
Should I spawn a seperate thread for every single lua script being run?
Any advice would be greatly appriciated!!
SDF Public Access UNIX System - http://sdf.lonestar.org