Skip to content
/ LuNari Public

πŸ—¦πŸŒ” Lua for .NET :: Lua 5.4, 5.3, 5.2, 5.1, ...

License

Notifications You must be signed in to change notification settings

3F/LuNari

Repository files navigation

πŸ—¦πŸŒ” LuNari is Lua for .NET on Conari engine

All actual Lua versions, like: Lua 5.4, 5.3, 5.2, 5.1, ...

Build status release-src NuGet package License

Build history

Why LuNari ?

Most popular features that will be adapted to your needs on the fly.

πŸ” Easy to start:

using(var l = new Lua<ILua53>("Lua.dll")) { // ILua51, ILua52, ILua53, ...
    // ...
}

πŸš€ Awesome speed:

Based on the fast versions of Conari engine with caching of 0x29 opcodes (Calli). [?]

πŸ”¨ Its amazing dynamic features:

using(dynamic l = new LuaD("Lua.dll"))
{
    // Lua now is yours ~
    IntPtr L = l.luaL_newstate<LuaState>();
    var num  = l.lua_tonumber<LuaNumber>(L, 1);
}

🍱 Damn customizable:

var l = new Lua<ILua52>("Lua52.dll");

    l.API.pushcclosure(L, onProc, 0);
    l.bind<Action<LuaState, LuaCFunction, int>>("pushcclosure")(L, onProc, 0);
    l.v<ILua53>().pushcclosure(L, onProc, 0);
    ...

πŸ”– Modern .NET Core

LuNari is ready for .NET Core starting from 1.6. Its awesome dynamic features are also available even for .NET Standard 2.0.

🌚 Unlimited extensible features:

Since this works through Conari, you can access to all newest features of the Lua immediately after introducing this in draft. Just use it without waiting for release.

πŸ—Έ License

The MIT License (MIT)

Copyright (c) 2016,2017,2019  Denis Kuzmin < entry.reg@gmail.com > GitHub/3F

[ β˜• Donate ]

LuNari contributors: https://github.com/3F/LuNari/graphs/contributors

We're waiting for your awesome contributions!

Take a look closer

There are several ways to use LuNari: API-layer and binding at runtime (DLR, Lambda expressions)

Dynamic features /DLR

This does not require neither our API(see below) nor something other from you at all. We will generate all your needs automatically at runtime!

This is possible because of Conari. Thus, do whatever you want:

// all this will be generated at runtime, i.e. you can use all of what you need from Lua as you like:
d.pushcclosure(L, onProc, 0);
d.setglobal(L, "onKeyDown");
...
LuaNumber num = d.tonumber<LuaNumber>(L, 7);

Lambda expressions

You also can use your custom binding for what you need:

using(ILua l = new Lua("Lua52.dll"))
{
    l.bind<Action<LuaState, LuaCFunction, int>>("pushcclosure")(L, onProc, 0);
    l.bind<Action<LuaState, string>>("setglobal")(L, "onKeyDown");
    //or any exported function like: bindFunc<...>("_full_name_")
    ...
    LuaNumber num = l.bind<Func<LuaState, int, LuaNumber>>("tonumber")(L, 7);
}

API Layer

Standardized way that covers an original Lua features. 5.3, 5.2, 5.1, ...

using(var l = new Lua<ILua53>("Lua53.dll"))
{
    l.API.pushcclosure(L, onProc, 0); // ILua53 lua = l.API
    l.API.setglobal(L, "onKeyDown");
}

Unified API level between different versions:

Lua<ILua53> l;
...
// to avoid ambiguity if exists: l.U as ILua51 ~
l.U.arith(L, LUA_OPSUB);
l.U.pop(L, 1);

Other lightweight access to specific:

// any direction, for example: v5.2 <-> v5.1
l.v<ILua51>().pushcclosure(L, onProc, 0);

// from the higher version to the lower, for example: v5.2 -> v5.1
((ILua51)l.API).pushcclosure(L, onProc, 0);

Something else

Powerful work with several libraries:

using(var lSpec = new Lua("SpecLua.dll"))
{
    using(ILua l = new Lua<ILua52>("Lua52.dll"))
    {
        // ...
    }
}

Additional types:

size_t len;
CharPtr name = lua.tolstring(L, 1, out len);
...
string myName += name; // (IntPtr)name; .Raw; .Ansi; .Utf8; ...
...
LuaNumber mv = lua.tonumber(L, 2);

Lazy loading:

using(var l = new Lua<ILua51>(
                    new LuaConfig("Lua51.dll") {
                        LazyLoading = true
                    }))
{
    ...
}

and more!

How to Get LuNari

Roadmap

LuNari already provides flexible binding at runime. That is, as you can see above, you already can do anything between different versions via lambda-functions and DLR features. However, an important goal of this project is also to provide a fully compatible API layer for more comfortable work with any popular Lua versions like: Lua 5.1, 5.2, 5.3 ...

Contribute

Extend our API layer or improve all of what you want. It's completely transparent with our flexible architecture.

Here's how to extend API: in a few steps (Wiki). Please use Pull Requests if you ready to contribute.

The Application Program Interface of Lua:

How to Build LuNari

Our build was based on vssbe scripts.

You don't need to do anything else, just navigate to root directory of this project, and:

.\build Debug

Or please use v1.14+ plugin for Visual Studio