I've read many of the excellent articles (posts) on this site about how to integrate Lua in SMAUG as well as other information about using Lua with MUDs in general, but I still have a few questions.
My main problem is that I'm still not sure how to structure the MUD to use Lua.
The articles by Nick Gammon indicated that when he integrated Lua with SMAUG he created one lua_state for each connected character, plus one "global" lua_state for other MUD functions.
Is this really the best way to go?
What if you only use one lua_state but use coroutines for every single action and yield/resume as needed?
I've never really used Lua before (nor have I ever integrated it), but here is what I'm thinking:
Every time a script needs to be executed, I simply push it onto the main Lua stack and execute it using lua_resume(). If user-input is needed, the coroutine would yield and resume after input is acquired. Other events could work the same way or I can use triggers.
Example: A sword has been equipped and the OnExecute Lua script sets a timer to damage the player in 60 seconds unless he removes the sword. This can be done via a timer system (scheduler?) or using a yield/resume system. I'm not sure which is better...
Does this make sense? When I yield a coroutine and wait for something to happen, I assume I need to store the coroutine id (the number it is in the stack?) so I can resume the correct one.
Any other help would be greatly appriciated :)
(Also, as I mentioned, I'm not using SMAUG or any other codebase. I'm designing my own using Delphi...)
My main problem is that I'm still not sure how to structure the MUD to use Lua.
The articles by Nick Gammon indicated that when he integrated Lua with SMAUG he created one lua_state for each connected character, plus one "global" lua_state for other MUD functions.
Is this really the best way to go?
What if you only use one lua_state but use coroutines for every single action and yield/resume as needed?
I've never really used Lua before (nor have I ever integrated it), but here is what I'm thinking:
Every time a script needs to be executed, I simply push it onto the main Lua stack and execute it using lua_resume(). If user-input is needed, the coroutine would yield and resume after input is acquired. Other events could work the same way or I can use triggers.
Example: A sword has been equipped and the OnExecute Lua script sets a timer to damage the player in 60 seconds unless he removes the sword. This can be done via a timer system (scheduler?) or using a yield/resume system. I'm not sure which is better...
Does this make sense? When I yield a coroutine and wait for something to happen, I assume I need to store the coroutine id (the number it is in the stack?) so I can resume the correct one.
Any other help would be greatly appriciated :)
(Also, as I mentioned, I'm not using SMAUG or any other codebase. I'm designing my own using Delphi...)