Luapp

A library for creating bindings between C++ and Lua

Latest version Tutorial online View on GitHub

luapp

It's a useful tool for lua. To help you use lua in C++ style and work better with object-oriented programming.

Features

Header file only.
To register C++ class into lua.
C++ and lua could call each other's function.
Read/Write/Add/Remove lua global variable at C++ side.
Lua could send any variable to C++, and C++ could send then back.
Support to create C extension module.
Design a C++ container to simulate lua table.
Design a class whose instances can hold instances of any type supported by luapp.
Let lua script embedded in C++.
Be able to search lua script by custom rule.
Support to call lua function that has multiple return value.

Requirements

CMake 2.8+
Lua 5.3+

Example

-- ClassIntoLua.lua

object = NewObject()

num = object:count(3,4)

print("3 + 4 = " .. num)
// main.cpp

#include "luapp.hpp"

class MyClass
{
public:

    MyClass()
    {
        printf("do MyClass::MyClass()\n");
    }

    ~MyClass()
    {
        printf("do MyClass::~MyClass()\n");
    }

    lua::Int count( lua::Int num01,
                    lua::Int num02)
    {
        return num01 + num02;
    }
};

int main()
{
    lua::State<>    lua;

    lua.bindMethod("count",&MyClass::count);

    lua.bindClassEx<MyClass>("NewObject");

    lua.run(".","ClassIntoLua.lua");

    return 0;
}