Module:ItemTables: Difference between revisionsGive feedback
test formatting |
just normal version |
||
| Line 25: | Line 25: | ||
return formatted | return formatted | ||
end | end | ||
--- Copies original table with its children as deep as possible. Does not handle metatables. (Copy is needed because Lua passes by reference, not value) | |||
-- @function Deepcopy | |||
-- @param {n-D table} | |||
-- @return {n-D table} | |||
function Deepcopy(orig) | |||
local orig_type = type(orig) | |||
local copy | |||
if orig_type == 'table' then | |||
copy = {} | |||
for orig_key, orig_value in next, orig, nil do | |||
copy[Deepcopy(orig_key)] = Deepcopy(orig_value) | |||
end | |||
else | |||
copy = orig | |||
end | |||
return copy | |||
end | |||
| Line 30: | Line 49: | ||
--check Data:ItemData.json for properties | --check Data:ItemData.json for properties | ||
p.get_prop = function(frame) | p.get_prop = function(frame) | ||
local item_name = frame.args[1] | local item_name = frame.args[1] | ||
local property = frame.args[2] | local property = frame.args[2] | ||
local item = get_json_item(item_name) | local item = get_json_item(item_name) | ||
if(item == nil) then return "Item Not Found" end | if(item == nil) then return "Item Not Found" end | ||
return item[property] | return item[property] | ||
end | end | ||
--{{#invoke:ItemData|get_cost|ITEM_NAME}}-- | --{{#invoke:ItemData|get_cost|ITEM_NAME}}-- | ||