• Stars
    star
    120
  • Rank 287,305 (Top 6 %)
  • Language
    OCaml
  • License
    BSD 2-Clause "Sim...
  • Created almost 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An embeddable Lua 2.5 interpreter implemented in OCaml

Lua-ML

Lua-ML is an implementation of the Lua 2.5 programming language written in OCaml and designed for extending OCaml programs.

Highly configurable programs like games, text editors, or test generators require extensibility since it's not possible to include functionality for every possible use case.

For many such programs, embedding a small general purpose language can be a better option than implementing their own DSL, and definitely better than creating an accidentally Turing-complete configuration file format.

Overview

Lua-ML is not a set of bindings for the PUC-Rio implementation written in C. It's a complete implementation of a Lua 2.5 interpreter and runtime in OCaml.

This has a number of advantages:

Modular runtime library

The Lua library is not a single module, but a set of OCaml modules and functors. That allows you to exclude some modules from the runtime, add your own modules, or even completely replace the default standard library with your own modules.

Type and memory safety

Registering functions and passing (embedding) values to Lua is as type safe as everything else in OCaml, so errors in interfacing with Lua are caught at compile time.

Since there is no unmanaged code involved, Lua code cannot crash its host program or access memory it's not supposed to access (assuming there are no memory safety bugs in the OCaml runtime of course).

It should be safe to use it even for untrusted scripts, if you don't include modules like Luaiolib into the runtime. Of course, you still should exercise extreme caution if you actually choose to run untrusted scripts.

Resistance to bit rot

Bindings usually require a specific version of the PUC-Rio implementation (e.g. 5.1) and may stop working with newer versions, which makes software harder to build and introduces new maintenance costs.

A pure OCaml implementation doesn't have that problem. The fact that this project was revived with minimal effort after more than a decade of dormancy is telling.

Disadvantages

  • Incompatible with existing Lua libraries.
  • Impelements, at this time, only antiquated Lua 2.5.

Project status

Lua-ML is usable and works quite well, but there's still room for improvement, especially in error reporting.

It doesn't make an API stability promise yet, which is why the versions are 0.9.x. I do promise to keep breaking changes to the minimum, but there's a chance they will be necessary.

One problem with backporting improvements from post-2.5 Lua specifications is that PUC-Rio Lua itself made a bunch of incompatible change on the way, so future direction requires a discussion with the user community.

Installation

opam install lua-ml

Usage

There isn't much documentation now. Any help is welcome!

For an example application, take a look at example/luaclient.ml. It shows how to provide a custom type (2-tuple) as userdata, register your own module, and run Lua code.

dune exec example/luaclient.exe

You can also read the original papers by Norman Ramsey:

Lua-ML once was a literate program and a snapshot of the last pre-revival NoWeb version is kept in docs/noweb. There's no easy way to make a PDF out of it, but reading the NoWeb source can give a good insight into the internals.

A real life example of a project using Lua-ML is soupault, a native but extensible static site generator/HTML processor. It exposes the element tree of the page as an abstract type (userdata) and makes HTML manipulation functions from lambdasoup available to plugins.

Historical examples that used older Lua-ML versions include:

History and Authors

Lua-ML was developed as part of the C-- compiler project developed by Norman Ramsey and was part of its source code. The complicated build process of C-- made it hard to build and use in other programs.

Then Christian Lindig, who also worked on C-- from 2000 to 2002, extracted it from C-- and reworked it into a standalone library to preserve it and make easier to use.

In 2018-2019, effort of Gabriel Radanne and Daniil Baturin allowed Lua-ML to build with modern OCaml and become an OPAM package.

The current maintainer is Daniil Baturin [email protected].

Copyright

Lua-ML is distributed under the two-clause BSD license. See the LICENSE file for details.

More Repositories

1

ocaml-style

A style guide for OCaml
98
star
2

hello

A minimal OCaml project
OCaml
42
star
3

lipsum

A Literate Programming Tool inspired by NoWeb, implemented in OCaml
OCaml
33
star
4

quest

A tool for testing C compilers automatically
C
19
star
5

strsim

strsim - compare strings for similarity
OCaml
9
star
6

polly

OCaml bindings for Linux epoll(2)
OCaml
8
star
7

fit

Minimal OCaml library to parse Garmin FIT files
OCaml
8
star
8

ocaml-hyphenate

OCaml module for the hyphenation of words based on TeX hyphenation patterns
OCaml
8
star
9

colibri-ml

Formal Concept Analysis in OCaml
OCaml
8
star
10

mkdir

Creating a directory in OCaml with given uid/gid and permissions
OCaml
8
star
11

certify

Minimal and pure OCaml tool to create SSL certificates for a host.
OCaml
5
star
12

logan

Experimental log analyzer
OCaml
4
star
13

bisect-summary

A simple tool to analyse coverage data created with bisect_ppx
OCaml
4
star
14

jbuild-pp

Pretty printer for jbuilder's jbuild files
OCaml
4
star
15

roman

OCaml module and command line tool to convert a roman numeral to an integer and vice versa
OCaml
4
star
16

ocaml-linebreak

Module for breaking words into lines using an optimal algorithm.
3
star
17

xen-ocaml-tools

The OCaml code from the Xen hypervisor
OCaml
3
star
18

xs-shipyard

XenServer Shipyard - Docker environment for building XenServer toolstack components
Shell
3
star
19

ascii85

Adobe's Ascii85 encoding as a module and a command line tool
OCaml
2
star
20

ocaml-ago

Command line tool that computes the difference between two calendar dates. Implemented in OCaml
OCaml
2
star
21

xen-msr-proto

Explore OCaml/Xen interface
C
2
star
22

ps-label

PostScript code to print simple signs and labels
PostScript
1
star
23

xenctrl

Mock OCaml Xen bindings
OCaml
1
star
24

namesort

Command-line tool to sort names by last name. Implemented in OCaml.
1
star
25

xen-libs

OCaml bindings for the Xen hypervisor
1
star
26

lindig.github.io

Christian Lindig
HTML
1
star