Computer: Add Settings to env

Adds the Settings() function for easily parsing configuration files and others of that sort.
This commit is contained in:
octacian 2017-01-31 18:54:49 -08:00
parent 6c640f5823
commit a1701f4513
2 changed files with 12 additions and 0 deletions

View File

@ -84,6 +84,11 @@ Refresh the computer display, typically after making changes to a buffer, field,
Run code under the environment (e.g. run data in the input field whenever it is submitted). Run code under the environment (e.g. run data in the input field whenever it is submitted).
#### `Settings(path)`
__Usage:__ `Settings(<path (string)>)`
Returns a userdata value containing a list of the "settings" defined in a file. Each setting should be on a new line, like variables but without `local` as a prefix. This "object" has several methods that you can use on it (e.g. `:to_table()`), however they are not documented here. Instead, see the methods section in the [documentation for node meta](http://dev.minetest.net/NodeMetaRef#Methods) as `Settings()` and node meta share the same methods.
## Filesystem ## Filesystem
This API section introduces function to interact with the computer's physical filesystem. This API section introduces function to interact with the computer's physical filesystem.

View File

@ -508,6 +508,13 @@ function digicompute.c:make_env(pos, player)
function fs.run(path) function fs.run(path)
return digicompute.c:run_file(pos, player, path) return digicompute.c:run_file(pos, player, path)
end end
-- [function] Settings
function main.Settings(path)
local fpath = cpath..path
if digicompute.builtin.exists(fpath) then
return Settings(fpath)
end
end
-- Get default env table -- Get default env table