GithubHelp home page GithubHelp logo

atpath.lua's Introduction

atpath.lua

Access values deep inside modules and tables, using path strings.

API

v = atpath.at(t, path)

Use a relative path string "<key1/<key2>/.../<keyN>", to look for the value in the table at the path. e.g. when t is t and path is "a/b/c", it means looking for t.a.b.c.

v = atpath.at_module(path)

Use an absolute path string "/<modulename>/<key1>/<key2>/.../<keyN>", to search for a module and then look for the value at the path. e.g. when path is "/30log/new", it means looking for require("30log").new. Note there is a slash at the beginning; this slash is not omittable.

keys = atpath.parse(path)

Give the parsed result from a path. Also keys.is_absolute shows whether the path is an absolute path, otherwise a relative path.

path = atpath.build(keys, modulename?, i?, j?)

Build a path from a array of keys. If given a modulename, prepend it to the path and make it an absolute path. Use i and j to specify a range in the array of keys.

Notes

  • "." and ".." segments are supported in the path, meaning "current layer" and "one layer upper" respectively.
    • If a ".." goes up beyond the top layer, an error is thrown.
  • If a segment of the path is exactly convertable to a number using tonumber, it is regarded as a number.
  • If a segment of the path is exactly "true" or "false", it is regarded as a boolean with said value.
  • Use ' or " to quote a literal key that prevent any type conversions. i.e. atpath.at(t, [[/1/'2'/true/'false']]) means t[1]["2"][true]["false"].
  • Use "%xx" in hexadecimal escape format to represent special characters, i.e. "%27" to represent an actual ' character in the path.

License

MIT

atpath.lua's People

Contributors

rinkaa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.