Skip to content

Instantly share code, notes, and snippets.

@arkenidar
Created May 5, 2025 18:52
Show Gist options
  • Save arkenidar/07ace83f2c718f0cd90155c5c3c523b7 to your computer and use it in GitHub Desktop.
Save arkenidar/07ace83f2c718f0cd90155c5c3c523b7 to your computer and use it in GitHub Desktop.
lang-tech : language techniques

enum

Lua enum

https://luascripts.com/lua-enum

function Enum(...)
    local enum = {}
    for index, value in ipairs({...}) do
        enum[value] = index
    end
    return enum
end

Status = Enum("Pending", "Active", "Completed")

Python enum

from enum import Enum

class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

# Accessing enum members
print(Color.RED)
print(Color.GREEN.name)
print(Color.BLUE.value)

# Iterating over enum members
for color in Color:
    print(color)

C enum

https://www.geeksforgeeks.org/enumeration-enum-c/

#include <stdio.h>

// Defining enum
enum direction {
    EAST, NORTH, WEST, SOUTH
};

int main() {

    // Creating enum variable
    enum direction dir = NORTH;
    printf("%d\n", dir);
    
    // This is valid too
    dir = 3;
    printf("%d", dir);
    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment