All Projects → vapourismo → Luwra

vapourismo / Luwra

Licence: bsd-3-clause
Minimal-overhead C++ wrapper for Lua

Programming Languages

lua
6591 projects
cpp
1120 projects
cpp11
221 projects

Labels

Projects that are alternatives of or similar to Luwra

Terminal Canvas
Manipulate the cursor in your terminal via high-performant, low-level, canvas-like API
Stars: ✭ 125 (-17.76%)
Mutual labels:  wrapper
Python Twitch Client
Python wrapper for Twitch API
Stars: ✭ 137 (-9.87%)
Mutual labels:  wrapper
Heed
A fully typed LMDB/MDBX wrapper with minimum overhead
Stars: ✭ 142 (-6.58%)
Mutual labels:  wrapper
Pokeapi Js Wrapper
PokeAPI browser wrapper, fully async with built-in cache
Stars: ✭ 129 (-15.13%)
Mutual labels:  wrapper
Mastodonkit
MastodonKit is a Swift Framework that wraps Mastodon's API
Stars: ✭ 134 (-11.84%)
Mutual labels:  wrapper
Asana Api Php Class
A dependency free, lightweight PHP class that acts as wrapper for Asana API. Lets make things fast and easy! :)
Stars: ✭ 137 (-9.87%)
Mutual labels:  wrapper
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-20.39%)
Mutual labels:  wrapper
Vue Axios
A small wrapper for integrating axios to Vuejs
Stars: ✭ 1,887 (+1141.45%)
Mutual labels:  wrapper
Angular Diff Match Patch
An AngularJS wrapper for google-diff-match-patch
Stars: ✭ 135 (-11.18%)
Mutual labels:  wrapper
Youtube Music
🎵 A Mac app wrapper for music.youtube.com
Stars: ✭ 2,097 (+1279.61%)
Mutual labels:  wrapper
Rcloneexplorer
rclone GUI for Windows
Stars: ✭ 129 (-15.13%)
Mutual labels:  wrapper
Libfaketime
libfaketime modifies the system time for a single application
Stars: ✭ 1,932 (+1171.05%)
Mutual labels:  wrapper
Pacaptr
Pacman-like syntax wrapper for many package managers.
Stars: ✭ 138 (-9.21%)
Mutual labels:  wrapper
Rialto
Manage Node resources with PHP
Stars: ✭ 128 (-15.79%)
Mutual labels:  wrapper
Coinbasepro Csharp
The unofficial .NET/C# client library for the Coinbase Pro/GDAX API
Stars: ✭ 143 (-5.92%)
Mutual labels:  wrapper
Ahk Libs
AutoHotkey library archive.
Stars: ✭ 125 (-17.76%)
Mutual labels:  wrapper
Mailjet Apiv3 Nodejs
[API v3] Official Mailjet API v3 NodeJS wrapper
Stars: ✭ 137 (-9.87%)
Mutual labels:  wrapper
Python Overpy
Python Wrapper to access the Overpass API
Stars: ✭ 151 (-0.66%)
Mutual labels:  wrapper
Gl
Header-only C++17 wrapper for OpenGL 4.6 Core Profile.
Stars: ✭ 144 (-5.26%)
Mutual labels:  wrapper
Ytdlrc
☁️ Downloads videos and metadata with youtube-dl and moves each file on completion to an rclone remote
Stars: ✭ 140 (-7.89%)
Mutual labels:  wrapper

Integration

Luwra

A header-only C++ library which provides a Lua wrapper with minimal overhead.

Usage

Refer to the documentation. In order to use the library you must clone this repository and include lib/luwra.hpp.

Have a question? Simply send me a an email or open an issue.

Examples

In the following examples lua refers to an instance of lua_State*.

Easily push values onto the stack:

// Push an integer
luwra::push(lua, 1338);

// Push a number
luwra::push(lua, 13.37);

// Push a boolean
luwra::push(lua, false);

// Push a string
luwra::push(lua, "Hello World");

Or retrieve them:

// Your function
int my_fun(int a, int b) {
    return a + b;
}

// Prepare stack
luwra::push(lua, 13);
luwra::push(lua, 37);

// Read manually
int a = luwra::read<int>(lua, 1);

// Read with deduced type
int b = luwra::read(lua, -1);

// Apply your function
int result = luwra::apply(lua, my_fun);

// which is equivalent to
int result = luwra::apply(lua, 1, my_fun);

// and equivalent to
int result = luwra::apply(lua, -2, my_fun);

// All of this is essentially syntactic sugar for
int result = my_fun(luwra::read(lua, 1), luwra::read(lua, 2));

// You can also return the result to the stack
luwra::map(lua, 1, my_fun);
int result = luwra::read(state, -1);

Generate a C function which can be used by Lua:

// Assuming your function looks something like this
int my_function(const char* a, int b) {
    // ...
}

// Convert to lua_CFunction
lua_CFunction cfun = LUWRA_WRAP(my_function);

// Do something with it, for example set it as a Lua global function
luwra::setGlobal(lua, "my_function", cfun);
-- Invoke the registered function
local my_result = my_function("Hello World", 1337)
print(my_result)

Or register your own class:

struct Point {
    double x, y;

    Point(double x, double y):
        x(x), y(y)
    {
        std::cout << "Construct Point(" << x << ", " << y << ")" << std::endl;
    }

    ~Point() {
        std::cout << "Destruct Point(" << x << ", " << y << ")" << std::endl;
    }

    void scale(double f) {
        x *= f;
        y *= f;
    }

    std::string __tostring() {
        return "<Point(" + std::to_string(x) + ", " + std::to_string(y) + ")>";
    }
};

// Register the metatable and constructor
luwra::registerUserType<Point(double, double)>(
    lua,

    // Constructor name
    "Point",

    // Methods need to be declared here
    {
        LUWRA_MEMBER(Point, scale),
        LUWRA_MEMBER(Point, x),
        LUWRA_MEMBER(Point, y)
    },

    // Meta methods may be registered aswell
    {
        LUWRA_MEMBER(Point, __tostring)
    }
);
-- Instantiate 'Point'
local point = Point(13, 37)

-- Invoke 'scale' method
point:scale(1.5)

-- Convert to string via '__tostring' meta method
print(point)

-- Read properties 'x' and 'y'
print(point:x(), point:y())

-- Set property 'x'
point:x(4.2)

Requirements

You need a C++11-compliant compiler and at least Lua 5.1 to get this library to work. I recommend using Lua 5.3 or later, to avoid the messy lua_Integer situation. LuaJIT 2.0 seems to work aswell.

Tests

The attached GNU Makefile allows you to run both examples and tests using make examples and make test respectively. You might need to adjust LUA_* variables, so Luwra finds the Lua headers and library.

Assuming all headers are located in /usr/include/lua5.3 and the shared object name is liblua5.3.so, you need to invoke this:

make LUA_INCDIR=/usr/include/lua5.3 LUA_LIBNAME=lua5.3 test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].