imported the util core module

This commit is contained in:
Manuel Simon Hirsig
2016-08-19 17:18:04 +02:00
parent e334a444df
commit 95250002a5
24 changed files with 93 additions and 93 deletions
+1 -1
View File
@@ -220,7 +220,7 @@ function public.bag_type(bag)
if bag == 0 then
return 1
end
for link in aux.util.present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do
for link in present(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) do
local item_id = aux.info.parse_link(link)
local item_info = aux.info.item(item_id)
return aux.info.item_subclass_index(3, item_info.subclass)
+16 -16
View File
@@ -5,7 +5,7 @@ function default_filter(str)
input_type = '',
validator = function()
return function(auction_record)
return aux.util.any(auction_record.tooltip, function(entry)
return any(auction_record.tooltip, function(entry)
return strfind(strlower(entry.left_text or ''), str, 1, true) or strfind(strlower(entry.right_text or ''), str, 1, true)
end)
end
@@ -205,7 +205,7 @@ public.filters = {
function operator(str)
local operator = str == 'not' and {'operator', 'not', 1}
for _, name in {'and', 'or'} do
for arity in aux.util.present(aux.util.select(3, strfind(str, '^'..name..'(%d*)$'))) do
for arity in present(select(3, strfind(str, '^'..name..'(%d*)$'))) do
arity = tonumber(arity)
operator = not (arity and arity < 2) and {'operator', name, arity}
end
@@ -223,7 +223,7 @@ do
if self.exact then
return
end
for number in aux.util.present(tonumber(aux.util.select(3, strfind(str, '^(%d+)$')))) do
for number in present(tonumber(select(3, strfind(str, '^(%d+)$')))) do
if number >= 1 and number <= 60 then
for _, filter in {'min_level', 'max_level'} do
if not self[filter] then
@@ -241,13 +241,13 @@ do
} do
if not self[parser[1]] then
tinsert(parser, str)
for index, label in aux.util.present(parser[2](aux.util.select(3, unpack(parser)))) do
for index, label in present(parser[2](select(3, unpack(parser)))) do
self[parser[1]] = {label, index}
return true
end
end
end
if not self[str] and (str == 'usable' or str == 'exact' and self.name and aux.util.size(self) == 1) then
if not self[str] and (str == 'usable' or str == 'exact' and self.name and size(self) == 1) then
self[str] = {str, 1}
elseif i == 1 and strlen(str) <= 63 then
self.name = {str, m.unquote(str)}
@@ -274,14 +274,14 @@ function parse_parameter(input_type, str)
elseif input_type == 'string' then
return str ~= '' and str or nil
elseif type(input_type) == 'table' then
return aux.util.key(str, input_type)
return key(str, input_type)
end
end
function public.parse_query_string(str)
local post_filter = {}
local blizzard_filter_parser = m.blizzard_filter_parser()
local parts = aux.util.map(aux.util.split(str, '/'), function(part) return strlower(aux.util.trim(part)) end)
local parts = map(split(str, '/'), function(part) return strlower(trim(part)) end)
local i = 1
while parts[i] do
@@ -353,11 +353,11 @@ function public.query(query_string)
end
function public.queries(query_string)
local parts = aux.util.split(query_string, ';')
local parts = split(query_string, ';')
local queries = {}
for _, str in parts do
str = aux.util.trim(str)
str = trim(str)
local query, _, error = m.query(str)
@@ -375,7 +375,7 @@ end
function suggestions(components)
local suggestions = {}
if components.blizzard.name and aux.util.size(components.blizzard) == 1 then
if components.blizzard.name and size(components.blizzard) == 1 then
tinsert(suggestions, 'exact')
end
@@ -422,7 +422,7 @@ function suggestions(components)
end
-- item names
if aux.util.size(components.blizzard) + getn(components.post) == 1 and components.blizzard.name == '' then
if size(components.blizzard) + getn(components.post) == 1 and components.blizzard.name == '' then
for _, name in g.aux_auctionable_items do
tinsert(suggestions, name..'/exact')
end
@@ -477,7 +477,7 @@ function prettified_query_string(components)
if component[2] ~= 'tooltip' then
prettified.append(aux.gui.color.aux(component[2]))
end
for parameter in aux.util.present(component[3]) do
for parameter in present(component[3]) do
if component[2] == 'item' then
prettified.append(aux.info.display_name(aux.cache.item_id(parameter)) or aux.gui.color.label.enabled('['..parameter..']'))
else
@@ -502,7 +502,7 @@ function public.quote(name)
end
function public.unquote(name)
return aux.util.select(3, strfind(name, '^<(.*)>$')) or name
return select(3, strfind(name, '^<(.*)>$')) or name
end
function blizzard_query(components)
@@ -559,15 +559,15 @@ function validator(components)
if name == 'not' then
tinsert(stack, not args[1])
elseif name == 'and' then
tinsert(stack, aux.util.all(args))
tinsert(stack, all(args))
elseif name == 'or' then
tinsert(stack, aux.util.any(args))
tinsert(stack, any(args))
end
elseif type == 'filter' then
tinsert(stack, validators[i](record) and true or false)
end
end
return aux.util.all(stack)
return all(stack)
end
end
+5 -5
View File
@@ -38,7 +38,7 @@ do
end
function public.container_item(bag, slot)
for link in aux.util.present(GetContainerItemLink(bag, slot)) do
for link in present(GetContainerItemLink(bag, slot)) do
local item_id, suffix_id, unique_id, enchant_id = parse_link(link)
local item_info = m.item(item_id, suffix_id, unique_id, enchant_id)
@@ -98,7 +98,7 @@ end
function public.auction(index, query_type)
query_type = query_type or 'list'
for link in aux.util.present(GetAuctionItemLink(query_type, index)) do
for link in present(GetAuctionItemLink(query_type, index)) do
local item_id, suffix_id, unique_id, enchant_id = parse_link(link)
local item_info = m.item(item_id, suffix_id, unique_id, enchant_id)
@@ -208,7 +208,7 @@ function public.set_shopping_tooltip(slot)
end
function public.tooltip_match(entry, tooltip)
return aux.util.any(tooltip, function(line)
return any(tooltip, function(line)
local left_match = line.left_text and strupper(line.left_text) == strupper(entry)
local right_match = line.right_text and strupper(line.right_text) == strupper(entry)
return left_match or right_match
@@ -244,7 +244,7 @@ function public.load_tooltip(frame, tooltip)
end
function public.display_name(item_id, no_brackets, no_color)
for item_info in aux.util.present(aux.info.item(item_id)) do
for item_info in present(aux.info.item(item_id)) do
local name = item_info.name
if not no_brackets then
name = '['..name..']'
@@ -355,7 +355,7 @@ end
function public.item(item_id, suffix_id)
local itemstring = 'item:'..(item_id or 0)..':0:'..(suffix_id or 0)..':0'
for name, itemstring, quality, level, class, subclass, max_stack, slot, texture in aux.util.present(GetItemInfo(itemstring)) do
for name, itemstring, quality, level, class, subclass, max_stack, slot, texture in present(GetItemInfo(itemstring)) do
return {
name = name,
itemstring = itemstring,
+4 -4
View File
@@ -58,7 +58,7 @@ end
--function public.to_string(params) -- TODO
-- local gold, silver, copper = to_gsc(params.copper or 0 + )
-- local settings = aux.util.set(unpack(arg))
-- local settings = set(unpack(arg))
--end
function public.to_string(money, pad, trim, decimal_points, color, no_color)
@@ -121,9 +121,9 @@ function public.from_string(value)
value = gsub(gsub(strlower(value), '|c%x%x%x%x%x%x%x%x', ''), FONT_COLOR_CODE_CLOSE, '')
-- extract gold/silver/copper values
local gold = tonumber(aux.util.select(3, strfind(value, '(%d*%.?%d+)g')))
local silver = tonumber(aux.util.select(3, strfind(value, '(%d*%.?%d+)s')))
local copper = tonumber(aux.util.select(3, strfind(value, '(%d*%.?%d+)c')))
local gold = tonumber(select(3, strfind(value, '(%d*%.?%d+)g')))
local silver = tonumber(select(3, strfind(value, '(%d*%.?%d+)s')))
local copper = tonumber(select(3, strfind(value, '(%d*%.?%d+)c')))
if not gold and not silver and not copper then return end
-- test that there are no extra characters (other than spaces)
+4 -4
View File
@@ -60,8 +60,8 @@ function public.read_list(schema, str)
local separator = schema[2]
local element_type = schema[3]
local parts = aux.util.split(str, separator)
return aux.util.map(parts, function(part)
local parts = split(str, separator)
return map(parts, function(part)
return m.read(element_type, part)
end)
end
@@ -69,7 +69,7 @@ end
function public.write_list(schema, list)
local separator = schema[2]
local element_type = schema[3]
local parts = aux.util.map(list, function(element)
local parts = map(list, function(element)
return m.write(element_type, element)
end)
return table.concat(parts, separator)
@@ -78,7 +78,7 @@ end
function public.read_record(schema, str)
local separator = schema[2]
local record = {}
local parts = aux.util.split(str, separator)
local parts = split(str, separator)
for i=3,getn(schema) do
local key, type = next(schema[i])
record[key] = m.read(type, parts[i - 2])
+3 -3
View File
@@ -12,7 +12,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
if auction_record.blizzard_query then
local blizzard_query1 = aux.util.copy(auction_record.blizzard_query)
local blizzard_query1 = copy(auction_record.blizzard_query)
blizzard_query1.first_page = auction_record.page
blizzard_query1.last_page = auction_record.page
tinsert(queries, {
@@ -20,7 +20,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
})
if auction_record.page > 0 then
local blizzard_query2 = aux.util.copy(auction_record.blizzard_query)
local blizzard_query2 = copy(auction_record.blizzard_query)
blizzard_query2.first_page = auction_record.page - 1
blizzard_query2.last_page = auction_record.page - 1
tinsert(queries, {
@@ -29,7 +29,7 @@ function public.find(auction_record, status_bar, on_abort, on_failure, on_succes
end
local item_query = m.item_query(auction_record.item_id, 1, 1)
if not aux.util.eq(auction_record.blizzard_query, item_query.blizzard_query) then
if not eq(auction_record.blizzard_query, item_query.blizzard_query) then
tinsert(queries, item_query)
end
end