mehtap Documentation

Lua 5.4 programming language implementation in Pure Python

Status

mehtap is in an early alpha stage. Since there is active development, API changes may happen without any special notice. Please pin your dependencies using a specific commit hash.

Installation

mehtap is supported on Python 3.10+. First, make sure you have a Python environment set up.

# in the shell
poetry add mehtap
# in the shell
pipenv install mehtap
# in the shell
pip install mehtap

What does mehtap have?

  • Everything in the Lua 5.4 grammar is supported.

  • There are utility functions to convert values from Python to Lua and from Lua to Python.

  • Most of the standard library is supported. (100% support is planned.) See this issue for progress.

    Basic Functions (25/25)
    • assert()

    • collectgarbage() — Does nothing.

    • dofile()

    • error()

    • _G

    • getmetatable()

    • ipairs()

    • load() — No binary chunks, no upvalues and no _ENV.

    • loadfile() — see load().

    • next()

    • pairs()

    • pcall()

    • print()

    • rawequal()

    • rawget()

    • rawlen()

    • rawset()

    • select()

    • setmetatable()

    • tonumber()

    • tostring()

    • type()

    • _VERSION

    • warn()

    • xpcall()

    Table Manipulation (7/7) - [x] table.concat() - [x] table.insert() - [x] table.move() - [x] table.pack() - [x] table.remove() - [x] table.sort() — uses bubble sort... - [x] table.unpack()
    Input and Output Facilities (18/18)
    • io.close()

    • io.flush()

    • io.input()

    • io.lines()

    • io.open()

    • io.output()

    • io.popen()

    • io.read()

    • io.tmpfile()

    • io.type()

    • io.write()

    • file:close()

    • file:flush()

    • file:lines()

    • file:read()

    • file:seek()

    • file:setvbuf() — Does nothing.

    • file:write()

    Operating System Facilities (11/11)
    • os.clock()

    • os.date()

    • os.difftime()

    • os.execute()

    • os.exit()

    • os.getenv()

    • os.remove()

    • os.rename()

    • os.setlocale()

    • os.time()

    • os.tmpname()

What’s the catch?

There are some differences with the specification of the reference manual. They are:

  • garbage collection,

  • frame scope.

For the most part, behaviour differences with the reference implementation are only allowed if the reference manual does not specify the behaviour. For example, the exact formatting of error messages is not specified in the reference manual, so it is allowed to be different.

Also, since this is a Python implementation, it is SLOW.

Acknowledgements

I want to hereby thank the following people for their (uninformed) contributions to the project:
(If you are reading this, hello! 👋)


Copyright (c) 2024-2025 Emre Özcan