No description
Find a file
2022-08-10 09:30:57 +02:00
glass Initial commit 🎉 2022-08-10 09:29:51 +02:00
spec Write some actual tests 😅 2022-08-10 09:30:57 +02:00
.busted Initial commit 🎉 2022-08-10 09:29:51 +02:00
config.ld Initial commit 🎉 2022-08-10 09:29:51 +02:00
glass-dev-1.rockspec Initial commit 🎉 2022-08-10 09:29:51 +02:00
glass.lua Initial commit 🎉 2022-08-10 09:29:51 +02:00
license Initial commit 🎉 2022-08-10 09:29:51 +02:00
readme.md Initial commit 🎉 2022-08-10 09:29:51 +02:00

Glass

Makes your configs (almost) see-through.

About

Glass is a Lua library that makes it easy to lazy-load configuration files into a Lua table at runtime. Its main purpose is to make accessing different configuration files "transparent" to the programmer.

Example

Assume the file app/config/settings.json exists in your project directory with the content {"user":{"name":"User"}}

local glass = require 'glass'
local config = glass.bind('app/config', {
   (require 'glass.json');
})
print(config.settings.user.name) -- prints "User"

How it Works

A glass loader is initialised with a list of loaders and will try each of them in order in its __index metamethod. The first loader that is able to fetch the wanted configuration will be used.

Loaders

Glass offers the following loaders out of the box:

  • cosmo loads cosmo templates
  • discount loads markdown files*.
  • json loads a JSON file as a Lua table.
  • lua loads and executes a Lua file.
  • moonhtml loads a MoonHTML template and returns it as a function.
  • readfile loads a file as a string.
  • skooma loads a skooma template and returns it as a function.
  • yaml loads a YAML file as a Lua table.

* For easier interoperability with other template loaders, the discount loader returns a static function which can be called to return the generated HTML. The markdown file is only parsed the first time.