Editing Module:Test
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | + | local proc_time = {} | |
− | local | + | proc_time[1] = os.clock() |
+ | local p = {} | ||
− | + | proc_time[2] = os.clock() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | local Races = mw.loadData('Module:Test/data/races') | |
− | + | local Biomes = mw.loadData('Module:Test/data/biomes') | |
− | + | proc_time[3] = os.clock() | |
− | |||
− | |||
− | + | function find_key_in_table(key, table) | |
+ | for k, v in pairs(table) do | ||
+ | if k == key then return v | ||
+ | elseif type(v) == "table" then | ||
+ | local found = find_key_in_table(key, v) | ||
+ | if found then return found end | ||
+ | end | ||
+ | end | ||
end | end | ||
− | function | + | function parent_defName(def, category) |
− | + | local parent_name = category[def]["ParentName"] | |
− | + | if type(category[parent_name]) == "table" then return parent_name end | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | function find_in_parents(tag, def, category) | |
− | + | if not category[def] then return def .. " not found in category" end | |
− | + | local parent_def = parent_defName(def, category) | |
− | + | if not parent_def then return tag .." not found in parent defs" end | |
− | + | local found = find_key_in_table(tag, category[parent_def]) | |
− | + | if found then return found | |
− | + | else | |
− | + | found = find_in_parents(tag, parent_def, category) | |
− | + | if found then return found end | |
− | + | end | |
− | |||
− | |||
− | |||
end | end | ||
− | + | function query(tag, def, category) | |
− | + | if not category[def] then return def .. " not found in category" end | |
− | + | local found = find_key_in_table(tag, category[def]) | |
− | + | if found then return found end | |
− | + | found = find_in_parents(tag, def, category) | |
− | + | if found then return found end | |
− | + | return tag .. " not found" | |
− | |||
− | |||
− | |||
end | end | ||
− | + | proc_time[4] = os.clock() | |
− | |||
− | |||
− | function | + | function p.query(frame) |
− | + | local category = nil | |
− | + | if frame.args[1] == "Races" then category = Races end | |
− | + | if frame.args[1] == "Biomes" then category = Biomes end | |
− | + | local def = frame.args[2] | |
+ | local tag = frame.args[3] | ||
+ | return query(tag, def, category) | ||
end | end | ||
− | + | frame:callParserFunction('#vardefine', 'foo', 'bar') | |
− | |||
− | |||
− | + | proc_time[5] = os.clock() | |
− | |||
− | |||
− | |||
− | + | mw.log("data: ".. (proc_time[3]-proc_time[2]) *1000 .."ms") | |
+ | mw.log("call: ".. (proc_time[5]-proc_time[4]) *1000 .."ms") | ||
− | + | return p | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |