Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 717a9895cf
Fetching contributors…

Cannot retrieve contributors at this time

90 lines (65 sloc) 5.685 kb

LuaD - Lua for the D Programming Language

Hello, world!

import luad.all;

void main()
{
    auto lua = new LuaState;
    lua.openLibs();

    auto print = lua.get!LuaFunction("print");
    print("hello, world!");
}

LuaD is a bridge between the D and Lua programming languages. Unlike many other libraries built on the Lua C API, LuaD doesn't expose the Lua stack - instead, it has wrappers for references to Lua objects, and supports seamlessly and directly converting any D type into a Lua type and vice versa. This makes it very easy to use and encourages a much less error-prone style of programming, as well as boosting productivity by a substantial order. Due to D's powerful generic programming capabilities, performance remains the same as the equivalent using the C API.

LuaD also includes bindings for the Lua C API. To use it, import the module luad.c.all or selectively import the modules in the luad.c package. Usage is identical to that of working with the Lua C API. Documentation for the C API can be found here.

(LuaD currently supports Lua version 5.1)

Goals

Current progress noted in parentheses:

  • Run Lua code from D, and D code from Lua (Yes)
  • Support automatic conversions between any D type and its Lua equivalent (Yes)
  • Support automatic conversions between D classes and Lua userdata (Partial)
  • Provide access to the entire underlying Lua C API (Yes)
  • Support Lua 5.2 (Not yet)

Support for D1 might be added later, once the codebase is more stable. A hypothetical D1 version would lack some of LuaD's current features, like automatic class conversions. Support for Tango would be in a D1 version. Also, if Tango is ported to D2, LuaD will support it.

Directory Structure

  • luad - the LuaD package.
  • visuald - VisualD project files.
  • test - unittest executable (when built).
  • lib - LuaD library files (when built).
  • example - LuaD examples.

Usage

To use, import the luad.all module in your project, and compile all the files in the luad, luad.c and luad.conversions packages. You can also compile the LuaD packages to a static libary, but you still need the full LuaD sources available at compile-time due to heavy use of templates. You must also link Lua version 5.1; on Unix-like systems, the library is typically called liblua5.1.a or similar. On Windows, you need a lua51.lib in OMF format to be linkable with DMD.

Check out the binaries branch for a lua51.lib import library and download instructions for a DMD-compatible library for Unix-like systems. Since the provided lua51.lib is only an import library, you also need the Lua DLLs at runtime (which can be found here).

The example directory is a work-in-progress collection of examples, it's a bit thin at the moment, in the mean-time look at the tutorial and the examples found throughout the documentation.

Makefiles as well as VisualD project files are included for both the library and the examples.

If you find any bugs, please report them to the Github issue tracker.

Build with Make

The MODEL variable should be either 32 or 64 depending on whether you want to make a 32 bit or 64 bit build. It defaults to 64.

The BUILD variable controls the build configuration; it can be debug, release or test. debug and release will build lib/libluad.a in debug and release mode respectively. The test configuration will build test/luad_unittest and then run it with gdb. Additionally, code coverage files (*.lst) are generated. The BUILD variable defaults to debug.

For example, if you want to build and run the unit tests on a 32 bit machine, the command would be:

make MODEL=32 BUILD=test

Build with VisualD/Windows

VisualD project files are included in the visuald subdirectory. The Release and Debug configurations produce lib/luad.lib and lib/luad-d.lib respectively. The Unittest configuration produces test/luad_unittest.exe.

Project files for the examples can be found in visuald/examples and produce binaries in the example/bin directory.

The location of lua51.lib needs to be configured for the LuaD Unittest configuration as well as for the examples. The projects are pre-configured to %LUA_OMFLIB%/lua51.lib; either add the LUA_OMFLIB environment variable, or edit the linker settings manually. lua51.lib in OMF format can be found on the binaries branch.

Documentation

You can find automatically generated documentation on the gh-pages branch, or you can browse it online.

Tutorial

A tutorial can be found on the project's Wiki.

License

LuaD is licensed under the terms of the MIT license (see the LICENSE file for details).

Jump to Line
Something went wrong with that request. Please try again.