# Apache Portable Runtime binding for Lua

Lua/APR is a binding of the Apache Portable Runtime (APR) for the Lua programming language. APR powers software such as the Apache webserver and Subversion and Lua/APR makes the APR operating system interfaces available to Lua, serving as an extended standard library. Thus far the following modules have been implemented (the following links take you straight to the relevant documentation):

- Base64 encoding
- Cryptography routines
- Date parsing
- Relational database drivers
- DBM routines
- Environment manipulation
- File path manipulation
- Filename matching
- Directory manipulation
- File I/O handling
- Network I/O handling
- Pipe I/O handling
- Memcached client
- Command argument parsing
- HTTP request parsing
- Process handling
- Shared memory
- String routines
- Multi threading
- Thread queues
- Time routines
- Uniform resource identifier parsing
- User/group identification
- Universally unique identifiers
- Character encoding translation
- XML parsing

## How to get and install the module

You can find the source code of the most recently released version under downloads. The source code is also available online in the GitHub repository. There are Windows binaries available that have been tested with Lua for Windows v5.1.4-40. You can also build the Lua/APR binding yourself. Here are your options:

### Install the Debian/Ubuntu package

I've setup an experimental Debian package repository to make it easier to install the Lua/APR binding on Debian and Ubuntu. The following commands should help you get started (see here for a detailed explanation):

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6CD27CBF
    sudo sh -c 'echo deb http://peterodding.com/code/lua/apr/packages ./ >> /etc/apt/sources.list'
    sudo apt-get update
    sudo apt-get install --no-install-recommends lua-apr
    lua -e "require 'apr.test' ()"

### Build on UNIX using LuaRocks

The easiest way to download, build & install the Lua/APR binding is to use LuaRocks. The following command will install the Lua/APR binding from the main repository:

    $ luarocks install lua-apr

You can also get the rockspec and sources directly from the author’s website (may be more recent):

    $ luarocks install http://peterodding.com/code/lua/apr/downloads/lua-apr-0.19-1.rockspec

If you have git installed you can also download and install the latest sources directly from GitHub:

    $ luarocks install http://peterodding.com/code/lua/apr/downloads/lua-apr-scm-1.rockspec

After installing the library you can run the test suite by executing:

    $ lua -e "require 'apr.test' ()"

### Build on UNIX using makefile

If you don’t have LuaRocks installed the following shell commands should help you get started on UNIX:

    $ if which git; then # Get the latest sources using `git'?
    $   git clone git://github.com/xolox/lua-apr.git
    $ else # Or get the most recently released archive using `wget'.
    $   wget http://peterodding.com/code/lua/apr/downloads/lua-apr-0.19-1.zip
    $   unzip lua-apr-0.19-1.zip
    $   mv lua-apr-0.19-1 lua-apr
    $ fi
    $ cd lua-apr
    $ sudo make install_deps # installs build & runtime dependencies for Debian/Ubuntu
    $ sudo make install # installs apr.lua and apr/core.so in /usr/local
    $ lua -e "require 'apr.test' ()" # runs the test suite

The makefile creates a debug build by default. Use `sudo make install DO_RELEASE=1` to create a release build instead. Just be sure to run `make clean` when switching between debug/release mode to avoid linking incompatible object files.

### Build on Windows using makefile

A makefile for Microsoft Windows is included in the repository. It has been tested on Windows XP with `NMAKE` from the free Microsoft Visual C++ Express 2010 tool chain. If you don’t have git installed you can download the latest sources directly from GitHub as a ZIP file. Please note that the Windows makefile only builds the Lua/APR binding, you need to build APR yourself (see the instructions).

The makefile creates a debug build by default. Use `NMAKE /f Makefile.win DO_RELEASE=1` to create a release build instead. Just be sure to run `NMAKE /f Makefile.win clean` when switching between debug/release mode to avoid linking incompatible object files.

## Status

The following functionality has not been implemented yet but is on the to-do list:

- Encrypted network communication (unfortunately this isn’t provided by APR so io_net.c could get messy…)
- zhiguo zhao contributed an LDAP module which will soon be integrated in the Lua/APR binding

## Contact

If you have questions, bug reports, suggestions, etc. the author can be contacted at peter@peterodding.com. The latest version is available at http://peterodding.com/code/lua/apr/ and http://github.com/xolox/lua-apr.

## License

This software is licensed under the MIT license.
© 2011 Peter Odding (peter@peterodding.com) and zhiguo zhao (zhaozg@gmail.com).