Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
398 changes: 283 additions & 115 deletions AIO_Client/AIO.lua

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion AIO_Client/AIO_Client.toc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
## SavedVariablesPerCharacter: AIO_sv_char

#dependencies
lua_compat.lua
Dep_LibWindow-1.1\LibStub.lua
Dep_LibWindow-1.1\LibWindow-1.1\LibWindow-1.1.lua
#Dep_LibWindow-1.1\LibWindow-1.1\LibWindow-1.1.lua
Dep_Smallfolk\smallfolk.lua
lualzw-zeros\lualzw.lua
queue.lua
Expand Down
15 changes: 12 additions & 3 deletions AIO_Client/Dep_LibWindow-1.1/LibStub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
-- LibStub is hereby placed in the Public Domain
-- Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]
local LibStub
if getglobal then
LibStub = getglobal(LIBSTUB_MAJOR)
else
LibStub = _G[LIBSTUB_MAJOR]
end

-- Check to see is this version of the stub is obsolete
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
if setglobal then
setglobal(LIBSTUB_MAJOR, LibStub)
else
_G[LIBSTUB_MAJOR] = LibStub
end
LibStub.minor = LIBSTUB_MINOR

-- LibStub:NewLibrary(major, minor)
Expand All @@ -35,7 +44,7 @@ if not LibStub or LibStub.minor < LIBSTUB_MINOR then
-- returns the library object if found
function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
error(format("Cannot find a library instance of %q.", tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end
Expand Down
102 changes: 63 additions & 39 deletions AIO_Client/Dep_Smallfolk/smallfolk.lua
Original file line number Diff line number Diff line change
@@ -1,68 +1,76 @@
local M = {}
Smallfolk = M
local expect_object, dump_object
local error, tostring, pairs, type, floor, huge, concat = error, tostring, pairs, type, math.floor, math.huge, table.concat
local error, tostring, pairs, type, floor, concat = error, tostring, pairs, type, math.floor, table.concat
local string_find = string.find
local gsub = string.gsub
local sub = string.sub
local format = string.format

local dump_type = {}

local len = AIO_LuaCompat.len
local huge = AIO_LuaCompat.math_huge
local print = AIO_LuaCompat.print -- not needed, but useful for debugging

function dump_type:string(nmemo, memo, acc)
local nacc = #acc
local nacc = len(acc)
acc[nacc + 1] = '"'
acc[nacc + 2] = self:gsub('"', '""')
acc[nacc + 2] = gsub(self, '"', '""')
acc[nacc + 3] = '"'
return nmemo
end

function dump_type:number(nmemo, memo, acc)
acc[#acc + 1] = ("%.17g"):format(self)
acc[len(acc) + 1] = format("%.17g", self)
return nmemo
end

function dump_type:table(nmemo, memo, acc)
--[[
if memo[self] then
acc[#acc + 1] = '@'
acc[#acc + 1] = tostring(memo[self])
acc[len(acc) + 1] = '@'
acc[len(acc) + 1] = tostring(memo[self])
return nmemo
end
nmemo = nmemo + 1
]]
memo[self] = nmemo
acc[#acc + 1] = '{'
local nself = #self
acc[len(acc) + 1] = '{'
local nself = len(self)
for i = 1, nself do -- don't use ipairs here, we need the gaps
nmemo = dump_object(self[i], nmemo, memo, acc)
acc[#acc + 1] = ','
acc[len(acc) + 1] = ','
end
for k, v in pairs(self) do
if type(k) ~= 'number' or floor(k) ~= k or k < 1 or k > nself then
nmemo = dump_object(k, nmemo, memo, acc)
acc[#acc + 1] = ':'
acc[len(acc) + 1] = ':'
nmemo = dump_object(v, nmemo, memo, acc)
acc[#acc + 1] = ','
acc[len(acc) + 1] = ','
end
end
acc[#acc] = acc[#acc] == '{' and '{}' or '}'
acc[len(acc)] = acc[len(acc)] == '{' and '{}' or '}'
return nmemo
end

function dump_object(object, nmemo, memo, acc)
if object == true then
acc[#acc + 1] = 't'
acc[len(acc) + 1] = 't'
elseif object == false then
acc[#acc + 1] = 'f'
acc[len(acc) + 1] = 'f'
elseif object == nil then
acc[#acc + 1] = 'n'
acc[len(acc) + 1] = 'n'
elseif object ~= object then
if (''..object):sub(1,1) == '-' then
acc[#acc + 1] = 'N'
if sub(''..object,1,1) == '-' then
acc[len(acc) + 1] = 'N'
else
acc[#acc + 1] = 'Q'
acc[len(acc) + 1] = 'Q'
end
elseif object == huge then
acc[#acc + 1] = 'I'
acc[len(acc) + 1] = 'I'
elseif object == -huge then
acc[#acc + 1] = 'i'
acc[len(acc) + 1] = 'i'
else
local t = type(object)
if not dump_type[t] then
Expand All @@ -89,48 +97,48 @@ local nonzero_digit = {['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true, [
local is_digit = {['0'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true, ['5'] = true, ['6'] = true, ['7'] = true, ['8'] = true, ['9'] = true}
local function expect_number(string, start)
local i = start
local head = string:sub(i, i)
local head = sub(string, i, i)
if head == '-' then
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
end
if nonzero_digit[head] then
repeat
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
until not is_digit[head]
elseif head == '0' then
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
else
invalid(i)
end
if head == '.' then
local oldi = i
repeat
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
until not is_digit[head]
if i == oldi + 1 then
invalid(i)
end
end
if head == 'e' or head == 'E' then
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
if head == '+' or head == '-' then
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
end
if not is_digit[head] then
invalid(i)
end
repeat
i = i + 1
head = string:sub(i, i)
head = sub(string, i, i)
until not is_digit[head]
end
return tonumber(string:sub(start, i - 1)), i
return tonumber(sub(string, start, i - 1)), i
end

local expect_object_head = {
Expand All @@ -144,30 +152,38 @@ local expect_object_head = {
['"'] = function(string, i)
local nexti = i - 1
repeat
nexti = string:find('"', nexti + 1, true) + 1
until string:sub(nexti, nexti) ~= '"'
return string:sub(i, nexti - 2):gsub('""', '"'), nexti
if string_find(string, '"', nexti + 1, true) == nil then
-- print("Unmatched quotes in string:", 'plöö', sub(string, nexti + 1), 'plöö')
error(string)
end
local nexta = nexti
nexti = string_find(string, '"', nexti + 1, true) + 1
--print("Q1: ", "'"..sub(string, nexta+1, nexti).."'")
--print("Q2: ", sub(string, nexti, nexti))
--print("Q3: ", sub(string, nexti + 1))
until sub(string, nexti, nexti) ~= '"'
return gsub(sub(string, i, nexti - 2), '""', '"'), nexti
end,
['0'] = function(string, i)
return expect_number(string, i - 1)
end,
['{'] = function(string, i, tables)
local nt, k, v = {}
local j = 1
tables[#tables + 1] = nt
if string:sub(i, i) == '}' then
tables[len(tables) + 1] = nt
if sub(string, i, i) == '}' then
return nt, i + 1
end
while true do
k, i = expect_object(string, i, tables)
if string:sub(i, i) == ':' then
if sub(string, i, i) == ':' then
v, i = expect_object(string, i + 1, tables)
nt[k] = v
else
nt[j] = k
j = j + 1
end
local head = string:sub(i, i)
local head = sub(string, i, i)
if head == ',' then
i = i + 1
elseif head == '}' then
Expand All @@ -182,7 +198,7 @@ local expect_object_head = {
local match = string:match('^%d+', i)
local ref = tonumber(match)
if tables[ref] then
return tables[ref], i + #match
return tables[ref], i + len(match)
end
invalid(i)
end,
Expand All @@ -201,18 +217,26 @@ expect_object_head['-'] = expect_object_head['0']
expect_object_head['.'] = expect_object_head['0']

expect_object = function(string, i, tables)
local head = string:sub(i, i)
local head = sub(string, i, i)
if expect_object_head[head] then
return expect_object_head[head](string, i + 1, tables)
end
invalid(i)
end

function M.loads(string, maxsize)
if #string > (maxsize or 10000) then
print("M.loads:", len(string), maxsize)
if len(string) > (maxsize or 10000) then
error 'input too large'
end
return (expect_object(string, 1, {}))
end

-- Tests
local tbl = {1/0, 0/0, -(1/0), -(0/0), huge, -huge, true, false, nil, "example string", 123.345, {"key1", "key2", 3, 4, 5, 6, 7, 8, 9, 10}, {a = "b", c = "d"}, {1, 2, 3}, {1, 2, {3, 4}}, {1, 2, {3, 4}, a = "b", c = "d"}, {}}
local data = M.loads(M.dumps(tbl))
-- print(M.dumps(tbl))
-- print(M.dumps(data))
print("smallfolk works:", M.dumps(tbl) == M.dumps(data))

return M
42 changes: 42 additions & 0 deletions AIO_Client/lua_compat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- library for compatibility between different wow lua versions
-- this is used to provide a consistent interface for functions

if AIO_LuaCompat ~= nil then
error("AIO_LuaCompat already defined")
end
AIO_LuaCompat = {}

function AIO_LuaCompat.print(...)
-- create message by concatenating all arguments from last to first
-- and ignoring nils until the first non-nil value encountered
local msg = ""
local printedSomething = false
for i = arg.n, 1, -1 do
if printedSomething or arg[i] ~= nil then
msg = (i == 1 and "" or " ") .. tostring(arg[i]) .. msg
printedSomething = true
end
end
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
-- setglobal("print", AIO_LuaCompat.print)

local len
if table.getn then
local getn = table.getn
local strlen = string.len
function len(t)
if type(t) == 'table' then
return getn(t)
end
if type(t) == 'string' then
return strlen(t)
end
error('len function does not support ' .. type(t))
end
else
len = loadstring("function(t) return #t end")
end
AIO_LuaCompat.len = len

AIO_LuaCompat.math_huge = math.huge or 1E+308 * 1E+308
12 changes: 6 additions & 6 deletions AIO_Client/lualzw-zeros/lualzw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ SOFTWARE.

local char = string.char
local type = type
local select = select
local sub = string.sub
local tconcat = table.concat
local length = AIO_LuaCompat.len

local basedictcompress = {}
local basedictdecompress = {}
Expand All @@ -53,7 +53,7 @@ local function compress(input)
if type(input) ~= "string" then
return nil, "string expected, got "..type(input)
end
local len = #input
local len = length(input)
if len <= 1 then
return "u"..input
end
Expand All @@ -74,7 +74,7 @@ local function compress(input)
return nil, "algorithm error, could not fetch word"
end
result[n] = write
resultlen = resultlen + #write
resultlen = resultlen + length(write)
n = n+1
if len <= resultlen then
return "u"..input
Expand All @@ -86,7 +86,7 @@ local function compress(input)
end
end
result[n] = basedictcompress[word] or dict[word]
resultlen = resultlen+#result[n]
resultlen = resultlen+length(result[n])
n = n+1
if len <= resultlen then
return "u"..input
Expand All @@ -112,7 +112,7 @@ local function decompress(input)
return nil, "string expected, got "..type(input)
end

if #input < 1 then
if length(input) < 1 then
return nil, "invalid input - not a compressed string"
end

Expand All @@ -123,7 +123,7 @@ local function decompress(input)
return nil, "invalid input - not a compressed string"
end
input = sub(input, 2)
local len = #input
local len = length(input)

if len < 2 then
return nil, "invalid input - not a compressed string"
Expand Down
Loading