lua-users home
lua-l archive

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


Hi,

I'm using Lua in a chatbot that I'm creating to be put in MUDs.  Everything
the bot does is scripted, and it's working quite well.  I've got a driver
script, which enters an infinite loop, calling my GetLine function (which
yields to pause the script) on each iteration to wait for the next line from
the MUD, and then processing the line.  However, I've run up against a few
problems.

1) OK, this problem is solved to some extent - before I had my driver
script, I was using a more event-based mechanism, where I would call a
function in the script each time I received a line.  This caused a problem
when I tried to implement a GetLine function, because I couldn't get the
script to resume properly.  I bypassed the problem by making the driver
script, which I'm pretty happy with, although I would've liked to have
understood the original problem instead of just avoiding it.

2) I want to be able to control the chatbot through the MUD, so I've got a
command system setup.  The script uses regex to recognise a command and
extract the caller, command name and parameters.  Then it checks the
configuration file to see whether a command with that name exists, and
whether the caller has permission to execute the command.  This bit works
fine.  But then, the driver script uses pcall() to safely call the command
function.  For some commands this worked, but when I tried to use GetLine()
in one of the commands, pcall came up with an error: "attempt to yield
across metamethod/C-call boundary".  I can get around it by not using pcall
(just calling the command directly) but if I do then I run the risk of
crashing the bot with a bad command function.  If there's no other way, then
I can live with it and just be careful, but if anyone knows a way that I can
safely execute functions from within a script, without preventing calls to
yielding functions, then I'd appreciate it.

3) lua_closethread() doesn't seem to be implemented (at least, I couldn't
see it - maybe I'm looking in the wrong place)

4) I also want to be able to re-load the script file, without closing the
chatbot, so that I can edit scripts "on-the-fly".  I don't need to be able
to store the current variables through the reload, but even so I'm not sure
what the best way to do it is.  I considered yielding from the
ReloadScript() function, and then closing, and re-opening the state and
thread.  Does this sound like a reasonable way of doing it?

Any help or comments would be greatly appreciated,

John B