├── VERSION ├── .envrc ├── .gitignore ├── .luacheckrc ├── codecov.yml ├── config.ld ├── flake.lock ├── rockspec ├── enum-devel-1.rockspec ├── enum-0.1.0-1.rockspec ├── enum-0.1.1-1.rockspec ├── enum-0.1.2-1.rockspec └── enum-0.1.3-1.rockspec ├── .travis.yml ├── CHANGELOG ├── .luacov ├── Makefile ├── flake.nix ├── README.md ├── docs ├── index.html ├── topics │ └── README.md.html └── ldoc_pale.css ├── src └── enum │ └── init.lua ├── tests └── enum_spec.lua └── LICENSE /VERSION: -------------------------------------------------------------------------------- 1 | v0.1.3 -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | luacov.*.out 3 | .direnv/ 4 | result* 5 | RELEASE 6 | -------------------------------------------------------------------------------- /.luacheckrc: -------------------------------------------------------------------------------- 1 | std = "min" 2 | files["tests"] = { 3 | std = "+busted"; 4 | } 5 | max_line_length = false 6 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | layout: header, changes, diff 3 | coverage: 4 | status: 5 | patch: 6 | default: 7 | target: '95' 8 | project: 9 | default: 10 | target: auto 11 | -------------------------------------------------------------------------------- /config.ld: -------------------------------------------------------------------------------- 1 | title = "Lua Enum Documentation" 2 | project = "enum" 3 | merge = true 4 | readme = "README.md" 5 | format = "markdown" 6 | file = { 7 | "src/enum/init.lua", 8 | } 9 | dir = "docs" 10 | no_lua_ref = true 11 | style="!pale" 12 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1670543317, 6 | "narHash": "sha256-4mMR56rtxKr+Gwz399jFr4i76SQZxsLWxxyfQlPXRm0=", 7 | "owner": "NixOS", 8 | "repo": "nixpkgs", 9 | "rev": "7a6a010c3a1d00f8470a5ca888f2f927f1860a19", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "NixOS", 14 | "ref": "nixos-22.11", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /rockspec/enum-devel-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "enum" 2 | version = "devel-1" 3 | source = { 4 | url = "git://github.com/stefano-m/lua-enum", 5 | tag = "master" 6 | } 7 | description = { 8 | summary = "Simulate enumerations in Lua", 9 | detailed = "Simulate enumerations in Lua", 10 | homepage = "git+https://github.com/stefano-m/lua-enum", 11 | license = "Apache v2.0" 12 | } 13 | dependencies = { 14 | "lua >= 5.1", 15 | } 16 | supported_platforms = { "linux", "unix", "cygwin", "windows", "freebsd" } 17 | build = { 18 | type = "builtin", 19 | modules = { 20 | ["enum.init"] = "./src/enum/init.lua", 21 | }, 22 | copy_directories = { "./docs", "./tests"} 23 | } 24 | -------------------------------------------------------------------------------- /rockspec/enum-0.1.0-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "enum" 2 | version = "0.1.0-1" 3 | source = { 4 | url = "git://github.com/stefano-m/lua-enum", 5 | tag = "v0.1.0" 6 | } 7 | description = { 8 | summary = "Simulate enumerations in Lua", 9 | detailed = "Simulate enumerations in Lua", 10 | homepage = "git+https://github.com/stefano-m/lua-enum", 11 | license = "Apache v2.0" 12 | } 13 | supported_platforms = { 14 | "linux", 15 | "unix", 16 | "cygwin", 17 | "windows", 18 | "freebsd" 19 | } 20 | dependencies = { 21 | "lua >= 5.1" 22 | } 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["enum.init"] = "./src/enum/init.lua" 27 | }, 28 | copy_directories = { 29 | "./docs", 30 | "./tests" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rockspec/enum-0.1.1-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "enum" 2 | version = "0.1.1-1" 3 | source = { 4 | url = "git://github.com/stefano-m/lua-enum", 5 | tag = "v0.1.1" 6 | } 7 | description = { 8 | summary = "Simulate enumerations in Lua", 9 | detailed = "Simulate enumerations in Lua", 10 | homepage = "git+https://github.com/stefano-m/lua-enum", 11 | license = "Apache v2.0" 12 | } 13 | supported_platforms = { 14 | "linux", 15 | "unix", 16 | "cygwin", 17 | "windows", 18 | "freebsd" 19 | } 20 | dependencies = { 21 | "lua >= 5.1" 22 | } 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["enum.init"] = "./src/enum/init.lua" 27 | }, 28 | copy_directories = { 29 | "./docs", 30 | "./tests" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rockspec/enum-0.1.2-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "enum" 2 | version = "0.1.2-1" 3 | source = { 4 | url = "git://github.com/stefano-m/lua-enum", 5 | tag = "v0.1.2" 6 | } 7 | description = { 8 | summary = "Simulate enumerations in Lua", 9 | detailed = "Simulate enumerations in Lua", 10 | homepage = "git+https://github.com/stefano-m/lua-enum", 11 | license = "Apache v2.0" 12 | } 13 | supported_platforms = { 14 | "linux", 15 | "unix", 16 | "cygwin", 17 | "windows", 18 | "freebsd" 19 | } 20 | dependencies = { 21 | "lua >= 5.1" 22 | } 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["enum.init"] = "./src/enum/init.lua" 27 | }, 28 | copy_directories = { 29 | "./docs", 30 | "./tests" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rockspec/enum-0.1.3-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "enum" 2 | version = "0.1.3-1" 3 | source = { 4 | url = "git://github.com/stefano-m/lua-enum", 5 | tag = "v0.1.3" 6 | } 7 | description = { 8 | summary = "Simulate enumerations in Lua", 9 | detailed = "Simulate enumerations in Lua", 10 | homepage = "git+https://github.com/stefano-m/lua-enum", 11 | license = "Apache v2.0" 12 | } 13 | supported_platforms = { 14 | "linux", 15 | "unix", 16 | "cygwin", 17 | "windows", 18 | "freebsd" 19 | } 20 | dependencies = { 21 | "lua >= 5.1" 22 | } 23 | build = { 24 | type = "builtin", 25 | modules = { 26 | ["enum.init"] = "./src/enum/init.lua" 27 | }, 28 | copy_directories = { 29 | "./docs", 30 | "./tests" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | sudo: required 4 | 5 | env: 6 | global: 7 | - DISPLAY=fake 8 | matrix: 9 | - LUA="lua 5.2" 10 | - LUA="lua 5.3" 11 | 12 | branches: 13 | only: 14 | - travis-ci 15 | - master 16 | 17 | before_install: 18 | - pip install hererocks 19 | - hererocks ~/hererocks -r^ --$LUA 20 | - export PATH=$PATH:~/hererocks/bin 21 | - eval `luarocks path --bin` 22 | - lua -v 23 | - luarocks install luacheck 24 | - luarocks install luacov 25 | - luarocks install busted 26 | 27 | install: 28 | - luarocks install --only-deps rockspec/enum-devel-1.rockspec 29 | 30 | script: 31 | - luacheck . 32 | - busted . 33 | - busted --coverage . 34 | 35 | after_success: 36 | - bash <(curl -s https://codecov.io/bash) 37 | 38 | cache: 39 | directories: 40 | - $HOME/.cache/hererocks 41 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | * Release v0.1.3 2 | 3 | Stefano Mazzucco (11): 4 | Reformat flake with nixpkgs-fmt 5 | Refactor flake overlays so they can be composed 6 | Add note to README about nix overlay and luaPackages 7 | Improve sorting by release number in make release 8 | Fix typo in flake overlay: luaackages -> luaPackages 9 | Remove 'result' too when doing 'make clean' 10 | Update flake.lock 11 | Update flake.lock 12 | Use correct git+https url syntax in rockspec 13 | nixpkgs 21.05 -> 22.11 14 | 15 | * Release v0.1.2 16 | 17 | Stefano Mazzucco (11): 18 | Add info about installing with NixOS to README 19 | Add flake.nix 20 | Add release target to Makefile 21 | Use VERSION file in flake.nix 22 | Improve release target 23 | Add VERSION file so make release works 24 | Add version to README.md and module when releasing 25 | Add CHANGELOG 26 | Clean up make release output 27 | Restore dev versions after make release 28 | Update Copyright year 29 | 30 | * Release v0.1.1 31 | 32 | Stefano Mazzucco (5): 33 | Add codecov and travis configuration 34 | Add codecov and travis-ci badges to README.md 35 | Error if same key is reused 36 | Release version 0.1.1 37 | 38 | * Release v0.1.0 39 | 40 | Stefano Mazzucco (1): 41 | Add first public implementation 42 | 43 | -------------------------------------------------------------------------------- /.luacov: -------------------------------------------------------------------------------- 1 | --- luacov 0.12.0 configuration file. 2 | 3 | -- Patterns for files to include when reporting 4 | -- all will be included if nothing is listed 5 | -- (exclude overrules include, do not include 6 | -- the .lua extension, path separator is always '/') 7 | include = { 'src/enum' } 8 | 9 | -- Patterns for files to exclude when reporting 10 | -- all will be included if nothing is listed 11 | -- (exclude overrules include, do not include 12 | -- the .lua extension, path separator is always '/') 13 | exclude = { 14 | "luacov$", 15 | "luacov/reporter$", 16 | "luacov/defaults$", 17 | "luacov/runner$", 18 | "luacov/stats$", 19 | "luacov/tick$", 20 | } 21 | 22 | -- filename to store stats collected 23 | statsfile = "luacov.stats.out" 24 | 25 | -- filename to store report 26 | reportfile = "luacov.report.out" 27 | 28 | -- luacov.stats file updating frequency. 29 | -- The lower this value - the more frequenty results will be written out to luacov.stats 30 | -- You may want to reduce this value for short lived scripts (to for example 2) to avoid losing coverage data. 31 | savestepsize = 100 32 | 33 | -- Run reporter on completion? (won't work for ticks) 34 | runreport = true 35 | 36 | -- Delete stats file after reporting? 37 | deletestats = false 38 | 39 | -- Process Lua code loaded from raw strings 40 | -- (that is, when the 'source' field in the debug info 41 | -- does not start with '@') 42 | codefromstrings = false 43 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | project = enum 2 | sources = src/$(project)/*.lua 3 | files = README.md $(sources) 4 | 5 | tag ?= 6 | 7 | .PHONY: release 8 | ifndef tag 9 | release: 10 | $(error Fatal: must specify tag) 11 | else 12 | release: flake 13 | @git status -s --untracked-files=no \ 14 | | egrep '.+' >/dev/null \ 15 | && echo Cannot release with uncommitted files: \ 16 | && git status -s && exit 1 \ 17 | || true 18 | @echo -n $(tag) > VERSION 19 | echo -e '* Release $(tag)\n' > RELEASE 20 | @git shortlog -n `git tag | tr \. ' ' | sort -k1.2n -k2n -k3n | tr ' ' \. | tail -1`..HEAD \ 21 | | grep -v "Restart Development" >> RELEASE 22 | luarocks new_version --dir rockspec --tag $(tag) 23 | @sed -i 's/@VERSION@/$(tag)/' README.md src/enum/init.lua 24 | ldoc . 25 | @cat RELEASE CHANGELOG > CHANGELOG.2 && mv CHANGELOG.2 CHANGELOG 26 | git add src/enum/init.lua README.md CHANGELOG VERSION rockspec docs 27 | git commit -F RELEASE 28 | git tag -a $(tag) -F RELEASE 29 | @rm -f RELEASE 30 | @git reset HEAD~1 -- README.md src/enum/init.lua 31 | @git commit -m "Restart Development" 32 | @git co -- README.md src/enum/init.lua 33 | endif 34 | 35 | .PHONY: flake 36 | flake: 37 | nix flake check 38 | 39 | .PHONY: check 40 | check: lint test coverage 41 | 42 | .PHONY: lint 43 | lint: 44 | luacheck . 45 | 46 | .PHONY: test 47 | test: tests/*.lua 48 | busted . 49 | 50 | .PHONY: coverage 51 | coverage: 52 | busted --coverage . 53 | 54 | docs: $(files) 55 | ldoc . 56 | 57 | .PHONY: upload 58 | upload: check 59 | luarocks upload rockspec/$(project)-$(LUA_ENUM_VERSION).rockspec 60 | 61 | .PHONY: clean 62 | clean: 63 | rm -rf luacov.*.out result 64 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; 3 | 4 | outputs = { self, nixpkgs }: 5 | let 6 | 7 | currentVersion = builtins.readFile ./VERSION; 8 | 9 | flakePkgs = import nixpkgs { 10 | system = "x86_64-linux"; 11 | overlays = [ self.overlays.default ]; 12 | }; 13 | 14 | buildPackage = pname: luaPackages: with luaPackages; 15 | buildLuaPackage rec { 16 | name = "${pname}-${version}"; 17 | inherit pname; 18 | version = "${currentVersion}-${self.shortRev or "dev"}"; 19 | 20 | src = ./.; 21 | 22 | propagatedBuildInputs = [ lua ]; 23 | 24 | buildInputs = [ busted luacov luacheck ldoc ]; 25 | 26 | buildPhase = ":"; 27 | 28 | installPhase = '' 29 | mkdir -p "$out/share/lua/${lua.luaversion}" 30 | cp -r src/${pname} "$out/share/lua/${lua.luaversion}/" 31 | ''; 32 | 33 | doCheck = true; 34 | checkPhase = "make check"; 35 | 36 | }; 37 | 38 | in 39 | { 40 | checks.x86_64-linux = self.packages.x86_64-linux; 41 | 42 | packages.x86_64-linux = rec { 43 | default = lua_enum; 44 | lua_enum = buildPackage "enum" flakePkgs.luaPackages; 45 | lua51_enum = buildPackage "enum" flakePkgs.lua51Packages; 46 | lua52_enum = buildPackage "enum" flakePkgs.lua52Packages; 47 | lua53_enum = buildPackage "enum" flakePkgs.lua53Packages; 48 | luajit_enum = buildPackage "enum" flakePkgs.luajitPackages; 49 | }; 50 | 51 | devShells.x86_64-linux.default = flakePkgs.mkShell { 52 | LUA_PATH = "./src/?.lua;./src/?/init.lua"; 53 | buildInputs = (with self.packages.x86_64-linux.default; buildInputs ++ propagatedBuildInputs) ++ (with flakePkgs; [ 54 | nixpkgs-fmt 55 | luarocks 56 | ]); 57 | }; 58 | 59 | overlays.default = final: prev: with self.packages.x86_64-linux; { 60 | 61 | # NOTE: lua = prev.lua.override { packageOverrides = this: other: {... }} 62 | # Seems to be broken as it does not allow to combine different overlays. 63 | 64 | luaPackages = prev.luaPackages // { 65 | enum = lua_enum; 66 | }; 67 | 68 | lua51Packages = prev.lua51Packages // { 69 | enum = lua51_enum; 70 | }; 71 | 72 | lua52Packages = prev.lua52Packages // { 73 | enum = lua52_enum; 74 | }; 75 | 76 | lua53Packages = prev.lua53Packages // { 77 | enum = lua53_enum; 78 | }; 79 | 80 | luajitPackages = prev.luajitPackages // { 81 | enum = luajit_enum; 82 | }; 83 | 84 | }; 85 | 86 | 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/stefano-m/lua-enum.svg?branch=master)](https://travis-ci.org/stefano-m/lua-enum) [![codecov](https://codecov.io/gh/stefano-m/lua-enum/branch/master/graph/badge.svg)](https://codecov.io/gh/stefano-m/lua-enum) 2 | 3 | # Enum @VERSION@ - Simulate Enums in Lua 4 | 5 | This is a little module that simulates [enumerated 6 | types](https://en.wikipedia.org/wiki/Enumerated_type) in Lua. 7 | 8 | Its API is very similar to the [Python3 Enum 9 | API](https://docs.python.org/3/library/enum.html), although much more limited. 10 | 11 | ## Example Usage 12 | 13 | ``` lua 14 | enum = require("enum") 15 | 16 | sizes = {"SMALL", "MEDIUM", "BIG"} 17 | Size = enum.new("Size", sizes) 18 | print(Size) -- "" 19 | print(Size.SMALL) -- "" 20 | print(Size.SMALL.name) -- "SMALL" 21 | print(Size.SMALL.value) -- 1 22 | assert(Size.SMALL ~= Size.BIG) -- true 23 | assert(Size.SMALL < Size.BIG) -- error "Unsupported operation" 24 | assert(Size[1] == Size.SMALL) -- true 25 | Size[5] -- error "Invalid enum member: 5" 26 | 27 | -- Enums cannot be modified 28 | Size.MINI -- error "Invalid enum: MINI" 29 | assert(Size.BIG.something == nil) -- true 30 | Size.MEDIUM.other = 1 -- error "Cannot set fields in enum value" 31 | 32 | -- Keys cannot be reused 33 | Color = enum.new("Color", {"RED", "RED"}) -- error "Attempted to reuse key: 'RED'" 34 | ``` 35 | 36 | # Installing 37 | 38 | ## Using "classic" nix 39 | 40 | If you are on NixOS, you can install this package from 41 | [nix-stefano-m-overlays](https://github.com/stefano-m/nix-stefano-m-nix-overlays). 42 | 43 | ## Using nix flakes 44 | 45 | This package can be installed as a [nix 46 | flake](https://nixos.wiki/wiki/Flakes). It provides packages for the various 47 | versions of Lua shipped with nix as well as an 48 | [overlay](https://nixos.wiki/wiki/Overlays) that adds the `enum` attribute to 49 | the Lua package sets. 50 | 51 | ---------- 52 | 53 | **NOTE** 54 | 55 | To ensure that the flake overlays are composable, `enum` is added *directly* to 56 | the top-level `luaPackages`. An unfortunate consequence is that `enum` will 57 | **not** be present in `lua.pkgs`. To use `enum` in `lua.withPackages`, one must 58 | refer to the top-level `luaPackages`. 59 | 60 | For example, say that you want a Lua environment with `enum` and `http`, you 61 | need to do something like: 62 | 63 | ``` nix 64 | let 65 | # assume that enumOverlay is the overlay provided by the enum flake. 66 | pkgs = import {overlays = [enumOverlay];}; 67 | in 68 | # http is present in lua.pkgs 69 | # enum is not present in lua.pkgs 70 | myLuaEnv = pkgs.lua.withPackages(ps: [ps.http pkgs.luaPackages.enum]) 71 | ``` 72 | 73 | ---------- 74 | 75 | ## Using Luarocks 76 | 77 | This package is [published to Luarocks as 78 | `enum`](http://luarocks.org/modules/stefano-m/enum) and can be installed using 79 | 80 | ```shell 81 | luarocks install enum 82 | ``` 83 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | Lua Enum Documentation 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 15 |
16 |
17 |
18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 47 | 48 |
49 | 50 |

Module enum

51 |

52 | 53 |

54 |

55 | 56 |

57 |

Usage:

58 |
    59 |
    enum = require("enum")
     60 | 
     61 | sizes = {"SMALL", "MEDIUM", "BIG"}
     62 | Size = enum.new("Size", sizes)
     63 | print(Size) -- "<enum 'Size'>"
     64 | print(Size.SMALL) -- "<Size.SMALL: 1>"
     65 | print(Size.SMALL.name) -- "SMALL"
     66 | print(Size.SMALL.value) -- 1
     67 | assert(Size.SMALL ~= Size.BIG) -- true
     68 | assert(Size.SMALL < Size.BIG) -- error "Unsupported operation"
     69 | assert(Size[1] == Size.SMALL) -- true
     70 | Size[5] -- error "Invalid enum member: 5"
     71 | 
     72 | -- Enums cannot be modified
     73 | Size.MINI -- error "Invalid enum: MINI"
     74 | assert(Size.BIG.something == nil) -- true
     75 | Size.MEDIUM.other = 1 -- error "Cannot set fields in enum value"
     76 | 
     77 | -- Keys cannot be reused
     78 | Color = enum.new("Color", {"RED", "RED"}) -- error "Attempted to reuse key: 'RED'"
     79 | 
    80 |
81 |

Info:

82 |
    83 |
  • Copyright: 2017 - 2021 Stefano Mazzucco
  • 84 |
  • Release: v0.1.3
  • 85 |
  • License: Apache v2.0
  • 86 |
  • Author: Stefano Mazzucco
  • 87 |
88 | 89 | 90 |

Functions

91 | 92 | 93 | 94 | 95 | 96 |
new (name, values)Make a new enum from all the string values passed in.
97 | 98 |
99 |
100 | 101 | 102 |

Functions

103 | 104 |
105 |
106 | 107 | new (name, values) 108 |
109 |
110 | Make a new enum from all the string values passed in. 111 | 112 | 113 |

Parameters:

114 |
    115 |
  • name 116 | string 117 | the name of the enum 118 |
  • 119 |
  • values 120 | {string} 121 | array of string values 122 |
  • 123 |
124 | 125 |

Returns:

126 |
    127 | 128 | table 129 | a read-only Enum table 130 |
131 | 132 | 133 | 134 | 135 |
136 |
137 | 138 | 139 |
140 |
141 |
142 | generated by LDoc 1.4.6 143 | Last updated 1980-01-01 00:00:00 144 |
145 |
146 | 147 | 148 | -------------------------------------------------------------------------------- /src/enum/init.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Copyright 2017 - 2021 Stefano Mazzucco 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ]] 16 | 17 | --[[- 18 | @module enum 19 | @release @VERSION@ 20 | 21 | @author Stefano Mazzucco 22 | @copyright 2017 - 2021 Stefano Mazzucco 23 | @license Apache v2.0 24 | 25 | @usage 26 | enum = require("enum") 27 | 28 | sizes = {"SMALL", "MEDIUM", "BIG"} 29 | Size = enum.new("Size", sizes) 30 | print(Size) -- "" 31 | print(Size.SMALL) -- "" 32 | print(Size.SMALL.name) -- "SMALL" 33 | print(Size.SMALL.value) -- 1 34 | assert(Size.SMALL ~= Size.BIG) -- true 35 | assert(Size.SMALL < Size.BIG) -- error "Unsupported operation" 36 | assert(Size[1] == Size.SMALL) -- true 37 | Size[5] -- error "Invalid enum member: 5" 38 | 39 | -- Enums cannot be modified 40 | Size.MINI -- error "Invalid enum: MINI" 41 | assert(Size.BIG.something == nil) -- true 42 | Size.MEDIUM.other = 1 -- error "Cannot set fields in enum value" 43 | 44 | -- Keys cannot be reused 45 | Color = enum.new("Color", {"RED", "RED"}) -- error "Attempted to reuse key: 'RED'" 46 | ]] 47 | local string = string 48 | 49 | local enum = {} 50 | 51 | local function make_meta(idx, name, value, type_) 52 | return { 53 | __index = { value = idx, name = value, _type = type_ }, 54 | __newindex = function () 55 | error("Cannot set fields in enum value", 2) 56 | end, 57 | __tostring = function () 58 | return string.format('<%s.%s: %d>', name, value, idx) 59 | end, 60 | __le = function () 61 | error("Unsupported operation") 62 | end, 63 | __lt = function () 64 | error("Unsupported operation") 65 | end, 66 | __eq = function (this, other) 67 | return this._type == other._type and this.value == other.value 68 | end, 69 | } 70 | end 71 | 72 | local function check(values) 73 | local found = {} 74 | 75 | for _, v in ipairs(values) do 76 | if type(v) ~= "string" then 77 | error("Can create enum only from strings") 78 | end 79 | 80 | if found[v] == nil then 81 | found[v] = 1 82 | else 83 | found[v] = found[v] + 1 84 | end 85 | end 86 | 87 | local msg = "Attempted to reuse key: '%s'" 88 | for k, v in pairs(found) do 89 | if v > 1 then 90 | error(msg:format(k)) 91 | end 92 | end 93 | 94 | end 95 | 96 | --- Make a new enum from all the string values passed in. 97 | -- @string name the name of the enum 98 | -- @tparam {string} values array of string values 99 | -- @treturn table a read-only Enum table 100 | function enum.new (name, values) 101 | 102 | local _Private = {} 103 | local _Type = {} 104 | 105 | setmetatable( 106 | _Private, 107 | { 108 | __index = function (t, k) 109 | local v = rawget(t, k) 110 | if v == nil then 111 | error("Invalid enum member: " .. k, 2) 112 | end 113 | return v 114 | end 115 | } 116 | ) 117 | 118 | check(values) 119 | 120 | for i, v in ipairs(values) do 121 | local o = {} 122 | setmetatable(o, make_meta(i, name, v, _Type)) 123 | _Private[v] = o 124 | _Private[i] = o 125 | end 126 | 127 | -- public readonly table 128 | local Enum = {} 129 | setmetatable( 130 | Enum, 131 | { 132 | __index = _Private, 133 | __newindex = function () 134 | error("Cannot set enum value") 135 | end, 136 | __tostring = function () 137 | return string.format("", name) 138 | end, 139 | } 140 | ) 141 | 142 | return Enum 143 | end 144 | 145 | return enum 146 | -------------------------------------------------------------------------------- /tests/enum_spec.lua: -------------------------------------------------------------------------------- 1 | -- Works with the 'busted' framework. 2 | -- http://olivinelabs.com/busted/ 3 | require("busted") 4 | local enum = require("enum") 5 | 6 | describe("Enums", function () 7 | 8 | it("have sensible string representation", function () 9 | local Color = enum.new("Color", {"RED", "GREEN", "BLUE"}) 10 | assert.equals("", tostring(Color)) 11 | assert.equals("", tostring(Color.RED)) 12 | assert.equals("", tostring(Color.GREEN)) 13 | assert.equals("", tostring(Color.BLUE)) 14 | 15 | assert.equals("", tostring(Color[1])) 16 | assert.equals("", tostring(Color[2])) 17 | assert.equals("", tostring(Color[3])) 18 | end) 19 | 20 | it("cannot reuse the same key", function () 21 | assert.has_error( 22 | function () 23 | local _ = enum.new("Color", {"RED", "RED"}) 24 | end, 25 | "Attempted to reuse key: 'RED'" 26 | ) 27 | end) 28 | 29 | it("can be indexed by value", function () 30 | local Color = enum.new("Color", {"RED", "GREEN", "BLUE"}) 31 | 32 | assert.same(Color[1], Color.RED) 33 | assert.same(Color[2], Color.BLUE) 34 | assert.same(Color[3], Color.GREEN) 35 | 36 | end) 37 | 38 | it("error when created with other than strings", function () 39 | assert.has_error( 40 | function () 41 | local _ = enum.new('Wrong', {1, 2, 3}) 42 | end, 43 | "Can create enum only from strings") 44 | end) 45 | 46 | it("error when getting the wrong enum value", function () 47 | local Flavor = enum.new("Flavor", {"CHOCOLATE"}) 48 | assert.has_error( 49 | function () 50 | local _ = Flavor.VANILLA 51 | end, 52 | "Invalid enum member: VANILLA") 53 | 54 | assert.has_error( 55 | function () 56 | local _ = Flavor[5] 57 | end, 58 | "Invalid enum member: 5") 59 | 60 | end) 61 | 62 | it("error when trying to set new enum values", function () 63 | local Size = enum.new("Size", {"BIG"}) 64 | assert.has_error( 65 | function () 66 | Size.MEDIUM = 1 67 | end, 68 | "Cannot set enum value") 69 | end) 70 | 71 | it("have 'name' and 'value' fields", function () 72 | local Size = enum.new("Size", {"SMALL", "BIG"}) 73 | 74 | assert.equals("SMALL", Size.SMALL.name) 75 | assert.equals(1, Size.SMALL.value) 76 | assert.equals("BIG", Size.BIG.name) 77 | assert.equals(2, Size.BIG.value) 78 | end) 79 | 80 | it("error when trying to set a field", function () 81 | local Size = enum.new("Size", {"BIG"}) 82 | assert.has_error( 83 | function () 84 | Size.BIG.name = "does not work" 85 | end, 86 | "Cannot set fields in enum value") 87 | end) 88 | 89 | it("have nil non-existent fields", function () 90 | local Size = enum.new("Size", {"BIG"}) 91 | assert.is_nil(Size.BIG.foot) 92 | end) 93 | 94 | it("are not ordered", function () 95 | local Size = enum.new("Size", {"SMALL", "BIG"}) 96 | assert.has_error( 97 | function () 98 | local _ = Size.SMALL < Size.BIG 99 | end, 100 | _G._VERSION:match("5.1$") 101 | and "attempt to compare two table values" 102 | or "Unsupported operation") 103 | 104 | assert.has_error( 105 | function () 106 | local _ = Size.SMALL >= Size.BIG 107 | end, 108 | _G._VERSION:match("5.1$") 109 | and "attempt to compare two table values" 110 | or "Unsupported operation") 111 | end) 112 | 113 | it("have the equality operator", function () 114 | local Thing = enum.new("Thing", {"THING", "OTHER"}) 115 | local Other = enum.new("Other", {"OTHER"}) 116 | 117 | assert.not_equal(Thing.OTHER, Other.OTHER) 118 | assert.not_equal(Thing.THING, "a string") 119 | assert.not_equal(Thing.THING, Thing.OTHER) 120 | end) 121 | 122 | end) 123 | -------------------------------------------------------------------------------- /docs/topics/README.md.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | Lua Enum Documentation 7 | 8 | 9 | 10 | 11 |
12 | 13 |
14 | 15 |
16 |
17 |
18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 50 | 51 |
52 | 53 | 54 |

Build Status codecov

55 | 56 |

Enum v0.1.3 - Simulate Enums in Lua

57 | 58 |

This is a little module that simulates enumerated 59 | types in Lua.

60 | 61 |

Its API is very similar to the Python3 Enum 62 | API, although much more limited.

63 | 64 |

65 |

Example Usage

66 | 67 | 68 |
 69 | enum = require("enum")
 70 | 
 71 | sizes = {"SMALL", "MEDIUM", "BIG"}
 72 | Size = enum.new("Size", sizes)
 73 | print(Size) -- "<enum 'Size'>"
 74 | print(Size.SMALL) -- "<Size.SMALL: 1>"
 75 | print(Size.SMALL.name) -- "SMALL"
 76 | print(Size.SMALL.value) -- 1
 77 | assert(Size.SMALL ~= Size.BIG) -- true
 78 | assert(Size.SMALL < Size.BIG) -- error "Unsupported operation"
 79 | assert(Size[1] == Size.SMALL) -- true
 80 | Size[5] -- error "Invalid enum member: 5"
 81 | 
 82 | -- Enums cannot be modified
 83 | Size.MINI -- error "Invalid enum: MINI"
 84 | assert(Size.BIG.something == nil) -- true
 85 | Size.MEDIUM.other = 1 -- error "Cannot set fields in enum value"
 86 | 
 87 | -- Keys cannot be reused
 88 | Color = enum.new("Color", {"RED", "RED"}) -- error "Attempted to reuse key: 'RED'"
 89 | 
90 | 91 | 92 |

Installing

93 | 94 |

95 |

Using "classic" nix

96 | 97 |

If you are on NixOS, you can install this package from 98 | nix-stefano-m-overlays.

99 | 100 |

101 |

Using nix flakes

102 | 103 |

This package can be installed as a nix 104 | flake. It provides packages for the various 105 | versions of Lua shipped with nix as well as an 106 | overlay that adds the enum attribute to 107 | the Lua package sets.

108 | 109 |
110 | 111 |

NOTE

112 | 113 |

To ensure that the flake overlays are composable, enum is added directly to 114 | the top-level luaPackages. An unfortunate consequence is that enum will 115 | not be present in lua.pkgs. To use enum in lua.withPackages, one must 116 | refer to the top-level luaPackages.

117 | 118 |

For example, say that you want a Lua environment with enum and http, you 119 | need to do something like:

120 | 121 | 122 |
123 | let
124 |   # assume that enumOverlay is the overlay provided by the enum flake.
125 |   pkgs = import <nixpkgs> {overlays = [enumOverlay];};
126 | in
127 | # http is present in lua.pkgs
128 | # enum is not present in lua.pkgs
129 | myLuaEnv = pkgs.lua.withPackages(ps: [ps.http pkgs.luaPackages.enum])
130 | 
131 | 132 | 133 |
134 | 135 |

136 |

Using Luarocks

137 | 138 |

This package is published to Luarocks as 139 | enum and can be installed using

140 | 141 | 142 |
143 | luarocks install enum
144 | 
145 | 146 | 147 | 148 |
149 |
150 |
151 | generated by LDoc 1.4.6 152 | Last updated 1980-01-01 00:00:00 153 |
154 |
155 | 156 | 157 | -------------------------------------------------------------------------------- /docs/ldoc_pale.css: -------------------------------------------------------------------------------- 1 | /* BEGIN RESET 2 | 3 | Copyright (c) 2010, Yahoo! Inc. All rights reserved. 4 | Code licensed under the BSD License: 5 | http://developer.yahoo.com/yui/license.html 6 | version: 2.8.2r1 7 | */ 8 | html { 9 | color: #000; 10 | background: #FFF; 11 | } 12 | body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { 13 | margin: 0; 14 | padding: 0; 15 | } 16 | table { 17 | border-collapse: collapse; 18 | border-spacing: 0; 19 | } 20 | fieldset,img { 21 | border: 0; 22 | } 23 | address,caption,cite,code,dfn,em,strong,th,var,optgroup { 24 | font-style: inherit; 25 | font-weight: inherit; 26 | } 27 | del,ins { 28 | text-decoration: none; 29 | } 30 | li { 31 | margin-left: 20px; 32 | } 33 | caption,th { 34 | text-align: left; 35 | } 36 | h1,h2,h3,h4,h5,h6 { 37 | font-size: 100%; 38 | font-weight: bold; 39 | } 40 | q:before,q:after { 41 | content: ''; 42 | } 43 | abbr,acronym { 44 | border: 0; 45 | font-variant: normal; 46 | } 47 | sup { 48 | vertical-align: baseline; 49 | } 50 | sub { 51 | vertical-align: baseline; 52 | } 53 | legend { 54 | color: #000; 55 | } 56 | input,button,textarea,select,optgroup,option { 57 | font-family: inherit; 58 | font-size: inherit; 59 | font-style: inherit; 60 | font-weight: inherit; 61 | } 62 | input,button,textarea,select {*font-size:100%; 63 | } 64 | /* END RESET */ 65 | 66 | body { 67 | margin-left: 1em; 68 | margin-right: 1em; 69 | font-family: arial, helvetica, geneva, sans-serif; 70 | background-color: #ffffff; margin: 0px; 71 | } 72 | 73 | code, tt { font-family: monospace; font-size: 1.1em; } 74 | span.parameter { font-family:monospace; } 75 | span.parameter:after { content:":"; } 76 | span.types:before { content:"("; } 77 | span.types:after { content:")"; } 78 | .type { font-weight: bold; font-style:italic } 79 | 80 | body, p, td, th { font-size: .95em; line-height: 1.2em;} 81 | 82 | p, ul { margin: 10px 0 0 0px;} 83 | 84 | strong { font-weight: bold;} 85 | 86 | em { font-style: italic;} 87 | 88 | h1 { 89 | font-size: 1.5em; 90 | margin: 0 0 20px 0; 91 | } 92 | h2, h3, h4 { margin: 15px 0 10px 0; } 93 | h2 { font-size: 1.25em; } 94 | h3 { font-size: 1.15em; } 95 | h4 { font-size: 1.06em; } 96 | 97 | a:link { font-weight: bold; color: #004080; text-decoration: none; } 98 | a:visited { font-weight: bold; color: #006699; text-decoration: none; } 99 | a:link:hover { text-decoration: underline; } 100 | 101 | hr { 102 | color:#cccccc; 103 | background: #00007f; 104 | height: 1px; 105 | } 106 | 107 | blockquote { margin-left: 3em; } 108 | 109 | ul { list-style-type: disc; } 110 | 111 | p.name { 112 | font-family: "Andale Mono", monospace; 113 | padding-top: 1em; 114 | } 115 | 116 | pre { 117 | background-color: rgb(245, 245, 245); 118 | border: 1px solid #C0C0C0; /* silver */ 119 | padding: 10px; 120 | margin: 10px 0 10px 0; 121 | overflow: auto; 122 | font-family: "Andale Mono", monospace; 123 | } 124 | 125 | pre.example { 126 | font-size: .85em; 127 | } 128 | 129 | table.index { border: 1px #00007f; } 130 | table.index td { text-align: left; vertical-align: top; } 131 | 132 | #container { 133 | margin-left: 1em; 134 | margin-right: 1em; 135 | background-color: #ffffff; 136 | } 137 | 138 | #product { 139 | text-align: center; 140 | border-bottom: 1px solid #cccccc; 141 | background-color: #ffffff; 142 | } 143 | 144 | #product big { 145 | font-size: 2em; 146 | } 147 | 148 | #main { 149 | background-color:#FFFFFF; // #f0f0f0; 150 | //border-left: 2px solid #cccccc; 151 | } 152 | 153 | #navigation { 154 | float: left; 155 | width: 14em; 156 | vertical-align: top; 157 | background-color:#FFFFFF; // #f0f0f0; 158 | border-right: 2px solid #cccccc; 159 | overflow: visible; 160 | } 161 | 162 | #navigation h2 { 163 | background-color:#FFFFFF;//:#e7e7e7; 164 | font-size:1.1em; 165 | color:#000000; 166 | text-align: left; 167 | padding:0.2em; 168 | //border-top:1px solid #dddddd; 169 | border-bottom:1px solid #dddddd; 170 | } 171 | 172 | #navigation ul 173 | { 174 | font-size:1em; 175 | list-style-type: none; 176 | margin: 1px 1px 10px 1px; 177 | } 178 | 179 | #navigation li { 180 | text-indent: -1em; 181 | display: block; 182 | margin: 3px 0px 0px 22px; 183 | } 184 | 185 | #navigation li li a { 186 | margin: 0px 3px 0px -1em; 187 | } 188 | 189 | #content { 190 | margin-left: 14em; 191 | padding: 1em; 192 | width: 700px; 193 | border-left: 2px solid #cccccc; 194 | // border-right: 2px solid #cccccc; 195 | background-color: #ffffff; 196 | } 197 | 198 | #about { 199 | clear: both; 200 | padding: 5px; 201 | border-top: 2px solid #cccccc; 202 | background-color: #ffffff; 203 | } 204 | 205 | @media print { 206 | body { 207 | font: 12pt "Times New Roman", "TimeNR", Times, serif; 208 | } 209 | a { font-weight: bold; color: #004080; text-decoration: underline; } 210 | 211 | #main { 212 | background-color: #ffffff; 213 | border-left: 0px; 214 | } 215 | 216 | #container { 217 | margin-left: 2%; 218 | margin-right: 2%; 219 | background-color: #ffffff; 220 | } 221 | 222 | #content { 223 | padding: 1em; 224 | background-color: #ffffff; 225 | } 226 | 227 | #navigation { 228 | display: none; 229 | } 230 | pre.example { 231 | font-family: "Andale Mono", monospace; 232 | font-size: 10pt; 233 | page-break-inside: avoid; 234 | } 235 | } 236 | 237 | table.module_list { 238 | border-width: 1px; 239 | border-style: solid; 240 | border-color: #cccccc; 241 | border-collapse: collapse; 242 | } 243 | table.module_list td { 244 | border-width: 1px; 245 | padding: 3px; 246 | border-style: solid; 247 | border-color: #cccccc; 248 | } 249 | table.module_list td.name { background-color: #f0f0f0; ; min-width: 200px; } 250 | table.module_list td.summary { width: 100%; } 251 | 252 | table.function_list { 253 | border-width: 1px; 254 | border-style: solid; 255 | border-color: #cccccc; 256 | border-collapse: collapse; 257 | } 258 | table.function_list td { 259 | border-width: 1px; 260 | padding: 3px; 261 | border-style: solid; 262 | border-color: #cccccc; 263 | } 264 | table.function_list td.name { background-color: #f6f6ff; ; min-width: 200px; } 265 | table.function_list td.summary { width: 100%; } 266 | 267 | dl.table dt, dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;} 268 | dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;} 269 | dl.table h3, dl.function h3 {font-size: .95em;} 270 | 271 | ul.nowrap { 272 | overflow:auto; 273 | whitespace:nowrap; 274 | } 275 | 276 | /* stop sublists from having initial vertical space */ 277 | ul ul { margin-top: 0px; } 278 | ol ul { margin-top: 0px; } 279 | ol ol { margin-top: 0px; } 280 | ul ol { margin-top: 0px; } 281 | 282 | /* make the target distinct; helps when we're navigating to a function */ 283 | a:target + * { 284 | background-color: #FF9; 285 | } 286 | 287 | 288 | /* styles for prettification of source */ 289 | pre .comment { color: #558817; } 290 | pre .constant { color: #a8660d; } 291 | pre .escape { color: #844631; } 292 | pre .keyword { color: #aa5050; font-weight: bold; } 293 | pre .library { color: #0e7c6b; } 294 | pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } 295 | pre .string { color: #8080ff; } 296 | pre .number { color: #f8660d; } 297 | pre .operator { color: #2239a8; font-weight: bold; } 298 | pre .preprocessor, pre .prepro { color: #a33243; } 299 | pre .global { color: #800080; } 300 | pre .user-keyword { color: #800080; } 301 | pre .prompt { color: #558817; } 302 | pre .url { color: #272fc2; text-decoration: underline; } 303 | 304 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | 3 | Version 2.0, January 2004 4 | 5 | http://www.apache.org/licenses/ 6 | 7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | 9 | 1. Definitions. 10 | 11 | "License" shall mean the terms and conditions for use, reproduction, and 12 | distribution as defined by Sections 1 through 9 of this document. 13 | 14 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 15 | owner that is granting the License. 16 | 17 | "Legal Entity" shall mean the union of the acting entity and all other entities 18 | that control, are controlled by, or are under common control with that 19 | entity. For the purposes of this definition, "control" means (i) the power, 20 | direct or indirect, to cause the direction or management of such entity, 21 | whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or 22 | more of the outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity exercising 25 | permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, including 28 | but not limited to software source code, documentation source, and 29 | configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical transformation or 32 | translation of a Source form, including but not limited to compiled object 33 | code, generated documentation, and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or Object form, 36 | made available under the License, as indicated by a copyright notice that is 37 | included in or attached to the work (an example is provided in the Appendix 38 | below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object form, that 41 | is based on (or derived from) the Work and for which the editorial revisions, 42 | annotations, elaborations, or other modifications represent, as a whole, an 43 | original work of authorship. For the purposes of this License, Derivative Works 44 | shall not include works that remain separable from, or merely link (or bind by 45 | name) to the interfaces of, the Work and Derivative Works thereof. 46 | 47 | "Contribution" shall mean any work of authorship, including the original 48 | version of the Work and any modifications or additions to that Work or 49 | Derivative Works thereof, that is intentionally submitted to Licensor for 50 | inclusion in the Work by the copyright owner or by an individual or Legal 51 | Entity authorized to submit on behalf of the copyright owner. For the purposes 52 | of this definition, "submitted" means any form of electronic, verbal, or 53 | written communication sent to the Licensor or its representatives, including 54 | but not limited to communication on electronic mailing lists, source code 55 | control systems, and issue tracking systems that are managed by, or on behalf 56 | of, the Licensor for the purpose of discussing and improving the Work, but 57 | excluding communication that is conspicuously marked or otherwise designated in 58 | writing by the copyright owner as "Not a Contribution." 59 | 60 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 61 | of whom a Contribution has been received by Licensor and subsequently 62 | incorporated within the Work. 63 | 64 | 2. Grant of Copyright License. Subject to the terms and conditions of this 65 | License, each Contributor hereby grants to You a perpetual, worldwide, 66 | non-exclusive, no-charge, royalty-free, irrevocable copyright license to 67 | reproduce, prepare Derivative Works of, publicly display, publicly perform, 68 | sublicense, and distribute the Work and such Derivative Works in Source or 69 | Object form. 70 | 71 | 3. Grant of Patent License. Subject to the terms and conditions of this 72 | License, each Contributor hereby grants to You a perpetual, worldwide, 73 | non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this 74 | section) patent license to make, have made, use, offer to sell, sell, import, 75 | and otherwise transfer the Work, where such license applies only to those 76 | patent claims licensable by such Contributor that are necessarily infringed by 77 | their Contribution(s) alone or by combination of their Contribution(s) with the 78 | Work to which such Contribution(s) was submitted. If You institute patent 79 | litigation against any entity (including a cross-claim or counterclaim in a 80 | lawsuit) alleging that the Work or a Contribution incorporated within the Work 81 | constitutes direct or contributory patent infringement, then any patent 82 | licenses granted to You under this License for that Work shall terminate as of 83 | the date such litigation is filed. 84 | 85 | 4. Redistribution. You may reproduce and distribute copies of the Work or 86 | Derivative Works thereof in any medium, with or without modifications, and in 87 | Source or Object form, provided that You meet the following conditions: 88 | 89 | You must give any other recipients of the Work or Derivative Works a copy 90 | of this License; and You must cause any modified files to carry prominent 91 | notices stating that You changed the files; and You must retain, in the 92 | Source form of any Derivative Works that You distribute, all copyright, 93 | patent, trademark, and attribution notices from the Source form of the 94 | Work, excluding those notices that do not pertain to any part of the 95 | Derivative Works; and If the Work includes a "NOTICE" text file as part of 96 | its distribution, then any Derivative Works that You distribute must 97 | include a readable copy of the attribution notices contained within such 98 | NOTICE file, excluding those notices that do not pertain to any part of the 99 | Derivative Works, in at least one of the following places: within a NOTICE 100 | text file distributed as part of the Derivative Works; within the Source 101 | form or documentation, if provided along with the Derivative Works; or, 102 | within a display generated by the Derivative Works, if and wherever such 103 | third-party notices normally appear. The contents of the NOTICE file are 104 | for informational purposes only and do not modify the License. You may add 105 | Your own attribution notices within Derivative Works that You distribute, 106 | alongside or as an addendum to the NOTICE text from the Work, provided that 107 | such additional attribution notices cannot be construed as modifying the 108 | License. 109 | 110 | You may add Your own copyright statement to Your modifications and may 111 | provide additional or different license terms and conditions for use, 112 | reproduction, or distribution of Your modifications, or for any such 113 | Derivative Works as a whole, provided Your use, reproduction, and 114 | distribution of the Work otherwise complies with the conditions stated in 115 | this License. 116 | 117 | 5. Submission of Contributions. Unless You explicitly state otherwise, any 118 | Contribution intentionally submitted for inclusion in the Work by You to the 119 | Licensor shall be under the terms and conditions of this License, without any 120 | additional terms or conditions. Notwithstanding the above, nothing herein shall 121 | supersede or modify the terms of any separate license agreement you may have 122 | executed with Licensor regarding such Contributions. 123 | 124 | 6. Trademarks. This License does not grant permission to use the trade names, 125 | trademarks, service marks, or product names of the Licensor, except as required 126 | for reasonable and customary use in describing the origin of the Work and 127 | reproducing the content of the NOTICE file. 128 | 129 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in 130 | writing, Licensor provides the Work (and each Contributor provides its 131 | Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 132 | KIND, either express or implied, including, without limitation, any warranties 133 | or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 134 | PARTICULAR PURPOSE. You are solely responsible for determining the 135 | appropriateness of using or redistributing the Work and assume any risks 136 | associated with Your exercise of permissions under this License. 137 | 138 | 8. Limitation of Liability. In no event and under no legal theory, whether in 139 | tort (including negligence), contract, or otherwise, unless required by 140 | applicable law (such as deliberate and grossly negligent acts) or agreed to in 141 | writing, shall any Contributor be liable to You for damages, including any 142 | direct, indirect, special, incidental, or consequential damages of any 143 | character arising as a result of this License or out of the use or inability to 144 | use the Work (including but not limited to damages for loss of goodwill, work 145 | stoppage, computer failure or malfunction, or any and all other commercial 146 | damages or losses), even if such Contributor has been advised of the 147 | possibility of such damages. 148 | 149 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or 150 | Derivative Works thereof, You may choose to offer, and charge a fee for, 151 | acceptance of support, warranty, indemnity, or other liability obligations 152 | and/or rights consistent with this License. However, in accepting such 153 | obligations, You may act only on Your own behalf and on Your sole 154 | responsibility, not on behalf of any other Contributor, and only if You agree 155 | to indemnify, defend, and hold each Contributor harmless for any liability 156 | incurred by, or claims asserted against, such Contributor by reason of your 157 | accepting any such warranty or additional liability. 158 | 159 | END OF TERMS AND CONDITIONS 160 | --------------------------------------------------------------------------------