{"id":13668493,"url":"https://github.com/stefano-m/lua-enum","last_synced_at":"2025-04-11T23:17:13.524Z","repository":{"id":96809140,"uuid":"109051381","full_name":"stefano-m/lua-enum","owner":"stefano-m","description":"Enumerated Types for Lua","archived":false,"fork":false,"pushed_at":"2022-12-09T12:43:41.000Z","size":36,"stargazers_count":22,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T23:17:07.929Z","etag":null,"topics":["enum","enumerated-types","enumeration","lua"],"latest_commit_sha":null,"homepage":"https://stefano-m.github.io/lua-enum/","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefano-m.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-10-31T20:55:56.000Z","updated_at":"2024-05-29T09:38:08.000Z","dependencies_parsed_at":"2024-01-29T14:53:22.952Z","dependency_job_id":"b08a8cda-af13-41de-a1fe-f754e3a77597","html_url":"https://github.com/stefano-m/lua-enum","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-m%2Flua-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-m%2Flua-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-m%2Flua-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-m%2Flua-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefano-m","download_url":"https://codeload.github.com/stefano-m/lua-enum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492885,"owners_count":21113163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["enum","enumerated-types","enumeration","lua"],"created_at":"2024-08-02T08:00:37.660Z","updated_at":"2025-04-11T23:17:13.505Z","avatar_url":"https://github.com/stefano-m.png","language":"Lua","readme":"[![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)\n\n# Enum @VERSION@ - Simulate Enums in Lua\n\nThis is a little module that simulates [enumerated\ntypes](https://en.wikipedia.org/wiki/Enumerated_type) in Lua.\n\nIts API is very similar to the [Python3 Enum\nAPI](https://docs.python.org/3/library/enum.html), although much more limited.\n\n## Example Usage\n\n``` lua\nenum = require(\"enum\")\n\nsizes = {\"SMALL\", \"MEDIUM\", \"BIG\"}\nSize = enum.new(\"Size\", sizes)\nprint(Size) -- \"\u003cenum 'Size'\u003e\"\nprint(Size.SMALL) -- \"\u003cSize.SMALL: 1\u003e\"\nprint(Size.SMALL.name) -- \"SMALL\"\nprint(Size.SMALL.value) -- 1\nassert(Size.SMALL ~= Size.BIG) -- true\nassert(Size.SMALL \u003c Size.BIG) -- error \"Unsupported operation\"\nassert(Size[1] == Size.SMALL) -- true\nSize[5] -- error \"Invalid enum member: 5\"\n\n-- Enums cannot be modified\nSize.MINI -- error \"Invalid enum: MINI\"\nassert(Size.BIG.something == nil) -- true\nSize.MEDIUM.other = 1 -- error \"Cannot set fields in enum value\"\n\n-- Keys cannot be reused\nColor = enum.new(\"Color\", {\"RED\", \"RED\"}) -- error \"Attempted to reuse key: 'RED'\"\n```\n\n# Installing\n\n## Using \"classic\" nix\n\nIf you are on NixOS, you can install this package from\n[nix-stefano-m-overlays](https://github.com/stefano-m/nix-stefano-m-nix-overlays).\n\n## Using nix flakes\n\nThis package can be installed as a [nix\nflake](https://nixos.wiki/wiki/Flakes). It provides packages for the various\nversions of Lua shipped with nix as well as an\n[overlay](https://nixos.wiki/wiki/Overlays) that adds the `enum` attribute to\nthe Lua package sets.\n\n----------\n\n**NOTE**\n\nTo ensure that the flake overlays are composable, `enum` is added *directly* to\nthe top-level `luaPackages`. An unfortunate consequence is that `enum` will\n**not** be present in `lua.pkgs`. To use `enum` in `lua.withPackages`, one must\nrefer to the top-level `luaPackages`.\n\nFor example, say that you want a Lua environment with `enum` and `http`, you\nneed to do something like:\n\n``` nix\nlet\n  # assume that enumOverlay is the overlay provided by the enum flake.\n  pkgs = import \u003cnixpkgs\u003e {overlays = [enumOverlay];};\nin\n# http is present in lua.pkgs\n# enum is not present in lua.pkgs\nmyLuaEnv = pkgs.lua.withPackages(ps: [ps.http pkgs.luaPackages.enum])\n```\n\n----------\n\n## Using Luarocks\n\nThis package is [published to Luarocks as\n`enum`](http://luarocks.org/modules/stefano-m/enum) and can be installed using\n\n```shell\nluarocks install enum\n```\n","funding_links":[],"categories":["Working Around `attempt to call field 'new' (a nil value)` error"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefano-m%2Flua-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefano-m%2Flua-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefano-m%2Flua-enum/lists"}