PYPI PACKAGE AUDIT v0.2.0 Needs Improvement

moonpie

A Lua interpreter written in Python

PyPkgScore moonpie
Methodology & Criteria ♥ Donate
620 / 1000
Quick Install
pip install moonpie
1. Governance
50/200
2. PEP Metadata
200/200
3. Security
150/200
4. Docs & SEO
155/200
5. CI Engineering
65/200
📣 Share Audit: Share this report and visual preview in the current language
Advertisement
PYPI TELEMETRY

Downloads & Community Adoption

Last 30 days (without mirrors)
Last 7 days
107
Last 30 days
140
Total (180 days)
207
Metric / Ecosystem Status / Value Source
Downloads (30d / 180d) — PyPI Stats (without mirrors)
Trusted Publishing (PEP 740) ✕ Not detected PyPI Integrity / Sigstore
Django Packages — djangopackages.org
PyTech / PyPkgScore 620 / 1000 PyPkgScore Engine

Health & Engineering Analysis (5 Pillars)

1. Governance & Community50 / 200 ▾
LICENSE✓ 50 pts
SECURITY.md✕ 0 pts
CONTRIBUTING.md✕ 0 pts
CODE_OF_CONDUCT.md✕ 0 pts
2. PEP Metadata & Packaging200 / 200 ▾
Wheel (.whl)✓ 50 pts
pyproject.toml✓ 50 pts
Project URLs✓ 50 pts
Trove Classifiers✓ 50 pts
3. Security & Supply Chain150 / 200 ▾
Zero CVEs (OSV)✓ 60 pts
Trusted Publishing (OIDC)✕ 0 pts
Snyk / Audit Link✓ 40 pts
HTTPS Repository✓ 50 pts
4. Documentation, SEO & Ecosystem155 / 200 ▾
Structured README✓ 60 pts
Read the Docs✓ 50 pts
Django Packages✕ 0 pts
Website / Technical Articles✓ 45 pts
5. Engineering, CI & Quality65 / 200 ▾
Automated Tests✓ 65 pts
GitHub Actions CI✕ 0 pts
CHANGELOG.md✕ 0 pts
Env & Lockfile (uv/rye/poetry/pdm/hatch)✕ 0 pts
Advertisement
README & DOCS

Official Documentation & Usage Guide — moonpie

PyPI Metadata v0.2.0
Show full original documentation (English README) ▾

MoonPie - Lua Interpreter in Python

A Lua interpreter written in Python, implementing core Lua language features.

Installation

Requires Python 3.11 or newer.

From PyPI (when published)

pip install moonpie

From Source

git clone https://github.com/rhulha/MoonPie.git
cd MoonPie
pip install -e .

Features

Language Support

  • Data Types: nil, booleans, numbers, strings, tables, functions
  • Operators: arithmetic (+ - * / // % ^), comparison (== ~= < <= > >=, numbers and strings), logical (and or not, short-circuit), concatenation (..), length (#)
  • Variables: local and global, with proper block scoping and a fresh loop variable per iteration
  • Assignment: multiple assignment (a, b = b, a) and multiple return values
  • Functions: closures, varargs (...), methods (obj:method()), function a.b.c:m() definitions, f"str" / f{...} call syntax
  • Control Flow: if/elseif/else, while, repeat-until, numeric for, generic for (pairs, ipairs, custom iterators), break
  • Metatables: __index, __newindex, __call, __tostring, arithmetic, __concat, __eq, __lt, __le, __len, __unm, __pairs
  • Literals: decimal, exponent and hex numbers (1e3, 0xFF, 0x1p4), long strings and comments ([[...]], [==[...]==]), all string escapes
  • Errors: Lua-style messages with file:line: positions; error, pcall, xpcall

Built-in Functions

  • Basic: print, type, tostring, tonumber, assert, error, pcall, xpcall, select, next, pairs, ipairs, unpack, setmetatable, getmetatable, rawget, rawset, rawequal, rawlen, _G
  • Math: abs, floor, ceil, sqrt, sin, cos, tan, max, min, pi, huge
  • String: len, upper, lower, sub, rep, format, find, match, gmatch, gsub (strings also support s:method())
  • Table: insert, remove, concat, sort, unpack
  • IO: write

Architecture

The interpreter follows a classic architecture:

  1. Lexer (lexer.py) - Tokenizes Lua source code
  2. Parser (parser.py) - Builds an Abstract Syntax Tree (AST) from tokens
  3. AST Nodes (ast_nodes.py) - Defines all AST node types
  4. Evaluator (evaluator.py) - Traverses and executes the AST
  5. Object System (lua_object.py) - Lua tables, functions and value helpers
  6. Built-ins (lua_builtins.py) - Provides standard Lua functions
  7. Patterns (lua_patterns.py) - Translates Lua patterns to Python regular expressions

Usage

Command Line (after installation)

moonpie                    # Start interactive REPL
moonpie script.lua         # Execute a Lua file
moonpie examples/examples.lua

Python Module

python -m moonpie          # Start interactive REPL
python -m moonpie script.lua

As a Library

from moonpie import LuaInterpreter, LuaError

interpreter = LuaInterpreter()
results = interpreter.run("""
    function add(a, b)
        return a + b
    end
    print(add(5, 3))
    return add(1, 2), "done"
""")
print(results)  # [3.0, 'done']

try:
    interpreter.run("error('boom')")
except LuaError as e:
    print(e)  # input:1: boom

run returns the values returned by the chunk as a list and raises LuaError (or LuaSyntaxError) on errors. Lua values map to Python as nil -> None, booleans -> bool, numbers -> float, strings -> str; tables are LuaTable.

Example Code

-- Variables and arithmetic
local x = 10
local y = 20
print(x + y)  -- 30

-- Functions
function factorial(n)
    if n <= 1 then
        return 1
    else
        return n * factorial(n - 1)
    end
end
print(factorial(5))  -- 120

-- Tables
local person = {name = "John", age = 30}
print(person.name)  -- John

local array = {10, 20, 30}
print(array[1])  -- 10
print(#array)   -- 3

-- Loops
for i = 1, 5 do
    print(i)
end

-- String operations
local greeting = "Hello" .. " " .. "World"
print(greeting)  -- Hello World

Testing

Run the test suite:

pip install pytest
python -m pytest tests

Run examples:

moonpie examples/examples.lua

Implementation Details

  • Lexer: Tokenizes keywords, operators, numbers, short and long strings, and comments
  • Parser: Recursive descent parser using Lua 5.4 operator priorities
  • Evaluator: Tree-walking interpreter with lexical scopes and metatable-aware operations
  • Numbers: All numbers are floats (as in Lua 5.1) and print with %.14g
  • Recursion: Up to about 7000 nested Lua calls, then a catchable "stack overflow" error

Limitations

This is a Lua interpreter for educational purposes. Not implemented:

  • Coroutines, goto and labels
  • Integer subtype and bitwise operators (Lua 5.3+)
  • require, load, file I/O, os library, and most of io
  • %b in string patterns
  • Proper tail calls
  • Strings are Python (Unicode) strings, so # counts characters, not bytes

References