That sounds great, and it sounds like you have done a much neater job than I did when I did the Lua task system a while ago.
I had lots of individual routines to pull in data from the C side via function calls, eg.
race = mud.race (char_or_mob)
The system you describe, and which I see on your web site is much neater, eg.
I wouldn't worry too much about the __call metamethod. Although it is fleetingly documented in the Lua Reference Manual, I have never found a need to use it.
By the way, since you are using coroutines a lot, I wonder if you noticed something I just found out the other day (you probably have).
Anyway, for future reference, I was playing with coroutines a fair bit when testing my MUD stress test program, and was a bit irritated when something inside a coroutine crashed, and I wasn't sure why. A small example will demonstrate:
function send (s)
print ("sending " .. s) --> line 2
end -- send
function a ()
send ("hi there") --> line 6
end -- a
function b ()
send (nil) --> line 10
end -- b
function f ()
b () --> line 14
end -- f
thread = coroutine.create (f)
result = assert (coroutine.resume (thread)) --> line 19
The coroutine here is function f, and if you run this you get this error message:
Run-time error
World: smaug 2
Immediate execution
[string "Immediate"]:19: [string "Immediate"]:2: attempt to concatenate local 's' (a nil value)
stack traceback:
[C]: in function 'assert'
[string "Immediate"]:19: in main chunk
All we know from this message is that the coroutine.resume at line 19 failed, and it was because of a problem with a nil value in line 2. But where is the traceback? In my example both functions a and b call "send" so I don't know which one to blame (line 6 or line 10). Obviously I do in this short example, but in a more complex case I wouldn't.
Thankfully you can traceback a failed coroutine. I will replace line 19 with the following code:
local ok, err = coroutine.resume (thread)
if not ok then
print (debug.traceback (thread))
assert (ok, err)
end -- if
Now if I run the code I see this:
stack traceback:
[string "Immediate"]:2: in function 'send'
[string "Immediate"]:10: in function 'b'
[string "Immediate"]:14: in function <[string "Immediate"]:13>
Run-time error
World: smaug 2
Immediate execution
[string "Immediate"]:22: [string "Immediate"]:2: attempt to concatenate local 's' (a nil value)
stack traceback:
[C]: in function 'assert'
[string "Immediate"]:22: in main chunk
Now it is clear that function b (at line 10) is the culprit and this particular instance of b was called from line 14.
This makes the debugging much easier. Of course, this is the sort of message that could be logged or sent to an admin for corrective action.