lua-users home
lua-l archive

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


Let's say I wanted to a text-based multi-user game (eg. a MUD) and I
wanted to use the Lua scripting language.

We will have lots scripts running and I'm not sure how to handle a few issues:

1) Should I just have one lua_state or one lua_state for each user?
2) Suppose I want to ask the user a question and get a response in a Lua script?

Example #1:

@AskQuestion.lua

function YesAnswer()
  io.write("The user answered yes!");
end

function NoAnswer()
  io.write("The user answered no!");
end

Player.AskQuestion("Do you like pie?", YesAnswer, NoAnswer);

Example #2:

@AlternateAskQuestion.lua

-- Using C syntax, but just pretend it's Lua-syntax
if (Player.AskQuestion("Do you like pie"?) == ANSWER_YES)
  io.write("The user answered yes!");
else
  io.write("The user answered no!");

The two examples should accomplish the same thing, but the first
example can sort-of "queue" the functions and C++ can call them based
on the user's response.  The second example must receive a result from
AskQuestion before completing the if statement.

The other problem is that many users will have these scripts running
all-the-time.  There will also be more scripts running on items,
monsters, etc.

I don't know if I will use threading in my application, but everything
should be asynchronous so one script cannot tie-up the entire server.

Can anybody help me out with how to implement this?

Thanks!