Skip to content

Instantly share code, notes, and snippets.

@Afforess
Created July 23, 2016 17:42
Show Gist options
  • Save Afforess/3d9b4a47900dcf84a0277f3a719bc6be to your computer and use it in GitHub Desktop.
Save Afforess/3d9b4a47900dcf84a0277f3a719bc6be to your computer and use it in GitHub Desktop.
--- Data module
-- @module Data
require 'stdlib/core'
Data = {}
--- Selects all data values where the key matches the selector pattern.
-- The selector pattern is divided into groups. The pattern should have a colon character `:` to denote the selection for each group.
-- <br/>The first group is for the class of the data type (item, recipe, entity-type, etc)
-- <br/>The second group is for the name of the data element, and is optional. If missing, all elements matching prior groups are returned.
-- <br/>The third group is for the name of keys inside of the data element, and is optional. If missing, all elements matching prior groups are returned.
-- <br/>The fourth group is for the name of values inside of the data element, and is optional. If missing, all elements matching prior groups are returned.
-- <p> Selectors without a colon `:` separator are assumed to select all values in the first group.
-- <p> Selectors may have more
-- @usage Data.select('recipe') -- returns a table with all recipes
-- @usage Data.select('recipe:steel.*') -- returns a table with all recipes whose name matches 'steel.*'
-- @usage Data.select('recipe:steel.*:ingredients') -- returns a table with all ingredients from all recipes whose name matches 'steel.*'
-- @usage Data.select('recipe:steel.*:ingredients:iron-plate') -- returns a table with all iron-plate ingredient objects, from all recipes whose name matches 'steel.*'
-- @param the pattern to search with
-- @return table containing the elements matching the selector pattern, or an empty table if there was no matches
function Data.select(pattern)
fail_if_missing(pattern, "missing pattern argument")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment