I write a spawn function for mudlet. I tried to add the diff but whatever extension I chose, I get an error. Tell me where I can put it, if you are interested.
The idea is to be able to spawn an external process from a script and to be able to communicate with it.
Here is an example script:
Code: Select all
catProcess = nil
function readCatProcess( a )
echo(a)
end
function getCatProcess()
if catProcess == nil or not catProcess.isRunning() then
if catProcess ~= nil then
echo("Process did finish. Starting a new one!\n")
end
catProcess = spawn(readCatProcess, "/bin/cat")
end
return catProcess
end
Code: Select all
^cat *(.*) -> getCatProcess().send(matches[2] .. "\n")
Code: Select all
^close -> getCatProcess().close()
It returns a process object that contains 3 functions:
send String -> () that send a string to the process
close () -> () that close the channel to the process (it does not end the process)
isRunning () -> bool that returns whether the process is still running or not.