{"action":"created","issue":{"url":"https://api.github.com/repos/Afforess/Factorio-Stdlib/issues/32","repository_url":"https://api.github.com/repos/Afforess/Factorio-Stdlib","labels_url":"https://api.github.com/repos/Afforess/Factorio-Stdlib/issues/32/labels{/name}","comments_url":"https://api.github.com/repos/Afforess/Factorio-Stdlib/issues/32/comments","events_url":"https://api.github.com/repos/Afforess/Factorio-Stdlib/issues/32/events","html_url":"https://github.com/Afforess/Factorio-Stdlib/issues/32","id":166971816,"number":32,"title":"Config Module","user":{"login":"credomane","id":1283031,"avatar_url":"https://avatars.githubusercontent.com/u/1283031?v=3","gravatar_id":"","url":"https://api.github.com/users/credomane","html_url":"https://github.com/credomane","followers_url":"https://api.github.com/users/credomane/followers","following_url":"https://api.github.com/users/credomane/following{/other_user}","gists_url":"https://api.github.com/users/credomane/gists{/gist_id}","starred_url":"https://api.github.com/users/credomane/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/credomane/subscriptions","organizations_url":"https://api.github.com/users/credomane/orgs","repos_url":"https://api.github.com/users/credomane/repos","events_url":"https://api.github.com/users/credomane/events{/privacy}","received_events_url":"https://api.github.com/users/credomane/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-07-22T05:18:49Z","updated_at":"2016-07-23T12:53:41Z","closed_at":null,"body":"What are the thoughts on a Config module? I have one I've been using that I can convert fairly easy for stdlib inclusion. I'll uncouple it from my use and convert to stdlib then post it tomorrow night if such a module is desired. It will come without tests or with poor test coverage at first.\r\n\r\nBasically, it would look/work like this in stdlib.\r\n\r\n```lua\r\n --Makes sure global._config exists as a table. Called at the start of every other Config functions for insurance.\r\nConfig._setup()\r\n\r\n-- Translates to global._config.some.path.to.variable or safeDefault.\r\n-- if desired a table can be grabbed with Config.get(\"some/path\") = {to={variable=\"example\"}}\r\nConfig.get(\"some/path/to/variable\", safeDefault)\r\n\r\n-- Translates to global._config.some.path.to.variable = data.\r\n-- data can be anything. Even more tables. Which can then be seen with get(). such as get(\"some/path/to/variable/with/more/table\")\r\nConfig.set(\"some/path/to/variable\")\r\n\r\n--Deletes \"some/path/to/variable\" (sets to nil)\r\nConfig.delete(\"some/path/to/variable\")\r\n```\r\n\r\nPerhaps adding a user \"facing\" Config.setup({options_table}) to allow changing the separator to any desired string. Store that in say a global._config_options table."},"comment":{"url":"https://api.github.com/repos/Afforess/Factorio-Stdlib/issues/comments/234716726","html_url":"https://github.com/Afforess/Factorio-Stdlib/issues/32#issuecomment-234716726","issue_url":"https://api.github.com/repos/Afforess/Factorio-Stdlib/issues/32","id":234716726,"user":{"login":"dkaisers","id":929028,"avatar_url":"https://avatars.githubusercontent.com/u/929028?v=3","gravatar_id":"","url":"https://api.github.com/users/dkaisers","html_url":"https://github.com/dkaisers","followers_url":"https://api.github.com/users/dkaisers/followers","following_url":"https://api.github.com/users/dkaisers/following{/other_user}","gists_url":"https://api.github.com/users/dkaisers/gists{/gist_id}","starred_url":"https://api.github.com/users/dkaisers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkaisers/subscriptions","organizations_url":"https://api.github.com/users/dkaisers/orgs","repos_url":"https://api.github.com/users/dkaisers/repos","events_url":"https://api.github.com/users/dkaisers/events{/privacy}","received_events_url":"https://api.github.com/users/dkaisers/received_events","type":"User","site_admin":false},"created_at":"2016-07-23T12:53:41Z","updated_at":"2016-07-23T12:53:41Z","body":"The extra array getter has one disadvantage. There is no way to do something like the following:\r\n```lua\r\nConfig.get(\"some/array[1]/value\")\r\n```\r\nThis is not only usable for arrays but for normal tables, too. In your current implementation I could add a table with numeric keys as data and would not be able to access that data through a config path, as all segments of the path are treated as string keys. But in lua `table[\"2\"]` and `table[2]` are distinct keys that can exist in the same table at the same time. Therefore my proposed syntax is not only usable for arrays and allows for that distinction.\r\n```lua\r\n-- Equivalent to table[\"2\"]\r\nConfig.get(\"table/2/some/value\")\r\n-- Equivalent to table[2]\r\nConfig.get(\"table[2]/some/value\")\r\n```\r\nAs for the implementation of such a query syntax, the easiest way that comes to my mind would be to prefix anything in the form of `[n]` with a `/` so that a path `some/array[1]/value` would be split into the segments `some`, `array`, `[1]` and `value`. Even floating point numbers like `3.5`are valid table keys interestingly.\r\n\r\nIn the methods each segment/key is first checked with `string.find(key, \"^%[-?%d*(%.%d+)?]$\")` to check if it is an *numeric key accessor* and if true, will be casted using `tonumber()` before accessing the table value for the key.\r\n\r\n```lua\r\nfor k = 1, #pathParts, 1 do\r\n    if (type(part) ~= \"table\") then\r\n        value = nil;\r\n        break;\r\n    end\r\n\r\n    key = pathParts[key]\r\n    if (string.find(key, \"^%[-?%d*(%.%d+)?]$\") then\r\n        key = tonumber(key)\r\n    end\r\n\r\n    value = part[key];\r\n    part = part[key];\r\nend\r\n```\r\n\r\nI have not actually tested that rewrite yet, it's just a simple idea on how to handle such a syntax extension. I would try to extend the config module from your pull request once it has been merged."}}
{"actor":{"display_login":"dkaisers"}}