diff --git a/Make.config b/Make.config index da14798..ce636ec 100644 --- a/Make.config +++ b/Make.config @@ -1,5 +1,5 @@ # Path to your Lua library directory (LUA_PATH) -LUA_DIR = /usr/local/share/lua/5.1 +LUA_DIR = /usr/local/share/lua/5.3 # Set this to the path of your luadoc executable if you want to regenerate the # documentation and the luadoc script isn't in your PATH diff --git a/README b/README index 50112b9..35135c5 100644 --- a/README +++ b/README @@ -1,5 +1,6 @@ -LuaIRC v0.3 +LuaIRC v0.3 (Lua 5.3 Port) Jesse Luehrs (jluehrs2@uiuc.edu) +Elias Fleckenstein (fleckenstein@elidragon.com) OVERVIEW ======== @@ -7,16 +8,18 @@ LuaIRC is a fully featured IRC framework written entirely in Lua. It provides an INSTALL ======= -This module requires LuaSocket (http://www.cs.princeton.edu/~diego/professional/luasocket/) and Lua 5.1. To install, modify the Make.config file with paths appropriate to your system and run 'make install'. +This module requires LuaSocket (http://www.cs.princeton.edu/~diego/professional/luasocket/) and Lua 5.3. To install, modify the Make.config file with paths appropriate to your system and run 'make install'. DOCUMENTATION ============= Documentation of the API can be found in the doc/ directory. It was autogenerated from the source files by LuaDoc (http://luadoc.luaforge.net/). -LuaIRC has only been tested on Freenode so far, but I plan to expand this to other servers in the future. It's quite possible that it works on other servers anyway, however, so feel free to try it out, and send in bug reports for things that break. +LuaIRC has only been tested on Freenode and Libera.chat so far, but I plan to expand this to other servers in the future. It's quite possible that it works on other servers anyway, however, so feel free to try it out, and send in bug reports for things that break. CHANGES ======= +0.3 (Lua 5.3 Port) +- Unofficial port to work with Lua 5.3 0.3 - Major cleanup and restructuring again, documentation added, first public release 0.2 diff --git a/src/irc.lua b/src/irc.lua index a0c22b4..948864e 100644 --- a/src/irc.lua +++ b/src/irc.lua @@ -1,31 +1,46 @@ --- -- Implementation of the main LuaIRC module --- initialization {{{ -local base = _G -local constants = require 'irc.constants' -local ctcp = require 'irc.ctcp' -local c = ctcp._ctcp_quote -local irc_debug = require 'irc.debug' -local message = require 'irc.message' -local misc = require 'irc.misc' -local socket = require 'socket' -local os = require 'os' -local string = require 'string' -local table = require 'table' --- }}} - --- -- LuaIRC - IRC framework written in Lua -- @release 0.3 -module 'irc' +local irc = {} -- constants {{{ -_VERSION = 'LuaIRC 0.3' +irc._VERSION = 'LuaIRC 0.3 (Lua 5.3 Port)' +-- }}} + +-- libraries {{{ +local libs = {} + +libs.irc = irc +libs.socket = require 'socket' + +local old_libs = _G.libs +_G.libs = libs + +libs.constants = require 'irc.constants' +libs.ctcp = require 'irc.ctcp' +libs.debug = require 'irc.debug' +libs.misc = require 'irc.misc' +libs.channel = require 'irc.channel' +libs.dcc = require 'irc.dcc' +libs.message = require 'irc.message' + +_G.libs = old_libs + +-- localize modules {{{ +local constants = libs.constants +local ctcp = libs.ctcp +local c = ctcp._ctcp_quote +local irc_debug = libs.debug +local message = libs.message +local misc = libs.misc +local socket = libs.socket -- }}} -- classes {{{ -local Channel = base.require 'irc.channel' +local Channel = libs.channel -- }}} -- local variables {{{ @@ -51,14 +66,14 @@ local ip = nil -- }}} -- defaults {{{ -TIMEOUT = 60 -- connection timeout -NETWORK = "localhost" -- default network -PORT = 6667 -- default port -NICK = "luabot" -- default nick -USERNAME = "LuaIRC" -- default username -REALNAME = "LuaIRC" -- default realname -DEBUG = false -- whether we want extra debug information -OUTFILE = nil -- file to send debug output to - nil is stdout +irc.TIMEOUT = 60 -- connection timeout +irc.NETWORK = "localhost" -- default network +irc.PORT = 6667 -- default port +irc.NICK = "luabot" -- default nick +irc.USERNAME = "LuaIRC" -- default username +irc.REALNAME = "LuaIRC" -- default realname +irc.DEBUG = false -- whether we want extra debug information +irc.OUTFILE = nil -- file to send debug output to - nil is stdout -- }}} -- private functions {{{ @@ -68,21 +83,21 @@ local function main_loop_iter() local rready, wready, err = socket.select(rsockets, wsockets) if err then irc_debug._err(err); return false; end - for _, sock in base.ipairs(rready) do + for _, sock in ipairs(rready) do local cb = socket.protect(rcallbacks[sock]) local ret, err = cb(sock) if not ret then irc_debug._warn("socket error: " .. err) - _unregister_socket(sock, 'r') + irc._unregister_socket(sock, 'r') end end - for _, sock in base.ipairs(wready) do + for _, sock in ipairs(wready) do local cb = socket.protect(wcallbacks[sock]) local ret, err = cb(sock) if not ret then irc_debug._warn("socket error: " .. err) - _unregister_socket(sock, 'w') + irc._unregister_socket(sock, 'w') end end @@ -103,7 +118,7 @@ local function incoming_message(sock) local msg = message._parse(raw_msg) misc._try_call_warn("Unhandled server message: " .. msg.command, handlers["on_" .. msg.command:lower()], - (misc._parse_user(msg.from)), base.unpack(msg.args)) + (misc._parse_user(msg.from)), table.unpack(msg.args)) return true end -- }}} @@ -119,7 +134,7 @@ end -- command handlers {{{ -- on_nick {{{ function handlers.on_nick(from, new_nick) - for chan in channels() do + for chan in irc.channels() do chan:_change_nick(from, new_nick) end callback("nick_change", new_nick, from) @@ -128,7 +143,7 @@ end -- on_join {{{ function handlers.on_join(from, chan) - base.assert(serverinfo.channels[chan], + assert(serverinfo.channels[chan], "Received join message for unknown channel: " .. chan) if serverinfo.channels[chan].join_complete then serverinfo.channels[chan]:_add_user(from) @@ -157,7 +172,7 @@ function handlers.on_mode(from, to, mode_string, ...) if to:sub(1, 1) == "#" then -- handle channel mode requests {{{ - base.assert(serverinfo.channels[to], + assert(serverinfo.channels[to], "Received mode change for unknown channel: " .. to) local chan = serverinfo.channels[to] local ind = 1 @@ -204,7 +219,7 @@ end -- on_topic {{{ function handlers.on_topic(from, chan, new_topic) - base.assert(serverinfo.channels[chan], + assert(serverinfo.channels[chan], "Received topic message for unknown channel: " .. chan) serverinfo.channels[chan]._topic.text = new_topic serverinfo.channels[chan]._topic.user = from @@ -223,7 +238,7 @@ end -- on_kick {{{ function handlers.on_kick(from, chan, to) - base.assert(serverinfo.channels[chan], + assert(serverinfo.channels[chan], "Received kick message for unknown channel: " .. chan) if serverinfo.channels[chan].join_complete then serverinfo.channels[chan]:_remove_user(to) @@ -235,7 +250,7 @@ end -- on_privmsg {{{ function handlers.on_privmsg(from, to, msg) local msgs = ctcp._ctcp_split(msg) - for _, v in base.ipairs(msgs) do + for _, v in ipairs(msgs) do local msg = v.str if v.ctcp then -- ctcp message {{{ @@ -245,16 +260,16 @@ function handlers.on_privmsg(from, to, msg) table.remove(words, 1) -- not using try_call here because the ctcp specification requires -- an error response to nonexistant commands - if base.type(ctcp_handlers[cb]) == "function" then + if type(ctcp_handlers[cb]) == "function" then ctcp_handlers[cb](from, to, table.concat(words, " ")) else - notice(from, c("ERRMSG", received_command, ":Unknown query")) + irc.notice(from, c("ERRMSG", received_command, ":Unknown query")) end -- }}} else -- normal message {{{ if to:sub(1, 1) == "#" then - base.assert(serverinfo.channels[to], + assert(serverinfo.channels[to], "Received channel msg from unknown channel: " .. to) callback("channel_msg", serverinfo.channels[to], from, msg) else @@ -269,7 +284,7 @@ end -- on_notice {{{ function handlers.on_notice(from, to, msg) local msgs = ctcp._ctcp_split(msg) - for _, v in base.ipairs(msgs) do + for _, v in ipairs(msgs) do local msg = v.str if v.ctcp then -- ctcp message {{{ @@ -283,7 +298,7 @@ function handlers.on_notice(from, to, msg) else -- normal message {{{ if to:sub(1, 1) == "#" then - base.assert(serverinfo.channels[to], + assert(serverinfo.channels[to], "Received channel msg from unknown channel: " .. to) callback("channel_notice", serverinfo.channels[to], from, msg) else @@ -297,7 +312,7 @@ end -- on_quit {{{ function handlers.on_quit(from, quit_msg) - for name, chan in base.pairs(serverinfo.channels) do + for name, chan in pairs(serverinfo.channels) do chan:_remove_user(from) end callback("quit", from, quit_msg) @@ -307,7 +322,7 @@ end -- on_ping {{{ -- respond to server pings to make sure it knows we are alive function handlers.on_ping(from, respond_to) - send("PONG", respond_to) + irc.send("PONG", respond_to) end -- }}} -- }}} @@ -316,7 +331,7 @@ end -- on_rpl_topic {{{ -- catch topic changes function handlers.on_rpl_topic(from, chan, topic) - base.assert(serverinfo.channels[chan], + assert(serverinfo.channels[chan], "Received topic information about unknown channel: " .. chan) serverinfo.channels[chan]._topic.text = topic end @@ -324,7 +339,7 @@ end -- on_rpl_notopic {{{ function handlers.on_rpl_notopic(from, chan) - base.assert(serverinfo.channels[chan], + assert(serverinfo.channels[chan], "Received topic information about unknown channel: " .. chan) serverinfo.channels[chan]._topic.text = "" end @@ -333,21 +348,21 @@ end -- on_rpl_topicdate {{{ -- "topic was set by at