Moon-Moon is an IRC bot run with the Lua programming language; however,
the syntax used in the development version is called 'MoonScript' - this
syntax can be compiled using Leafo's MoonScript program moonc
and then
loaded as Lua bytecode.
LuaRocks (recommended)
To install rocks locally, pass the --local
flag to the luarocks
command.
This downloads and installs rocks to a local directory without requiring
access to system directories. LuaRocks is recommended to allow for easy
installation of all the required software.
$ luarocks install basexx
$ luarocks install cqueues
$ luarocks install luafilesystem
$ luarocks install moonscript
Lua is used as a configuration language; bots must each have their own separate
.lua
file in $XDG_CONFIG_HOME/moonmoon
(which defaults to $HOME/.config
).
bot "#!" {
server = "irc.hashbang.sh";
port = 6697; -- TLS is automatically set if port == 6697
autojoin = {
"#!FusionScript";
};
};
Moon Moon takes advantage of a coroutine-based asynchronous system which allows the software to have multiple things "running" at once - it's almost like having a threaded program, without threads. This offers some advantages:
- A single Lua state
- Fewer callbacks
- Cleaner code base
Adding in a routine to the queue is simple, as demonstrated by the below examples programmed in MoonScript and Lua for convenience:
MoonScript
cqueues = require 'cqueues'
queue = require 'queue'
queue\wrap ->
while true
cqueues.sleep 5
print 'Hello, World!'
Lua
local cqueues = require("cqueues")
local queue = require("queue")
queue:wrap(function()
while true do
cqueues.sleep(5)
print("Hello, World!")
end
end)