Skip to content
Denis Kuzmin [ github.com/3F ] edited this page Jan 30, 2019 · 4 revisions

Architecture of LuNari provides a few ways to work with Lua:

  • Direct binding via Lambda expressions.
  • Binding via DLR.
  • .NET API Layer for Lua C API.

Direct binding

LuNari provides flexible binding between different versions via Lambda expressions.

It does not require the creation of any additional delegate. The LuNari will do it automatically instead of you.

Just use bind<> method and have fun!

l.bind<...>("api-function")

invoke it immediately:

l.bind<Action<LuaState, string>>("setglobal")(L, "onKeyDown");

or use it later:

var set = l.bind<Action<LuaState, string>>("setglobal");
...
set(L, "onKeyDown");

Data Types

LuNari covers easily minimum requirements even for data types:

  • Basic signature:
l.bind<Action<LuaState, string>>("pushstring")(L, "Hello from LuNari !");
  • Return value:
LuaNumber num = l.bind<Func<LuaState, int, LuaNumber>>("tonumber")(L, 7);
  • ByRef-arguments with out modifier:
size_t len;
CharPtr name = bind<FuncOut3<LuaState, int, size_t, IntPtr>>("tolstring")(L, 1, out len);
string myName += name; // (IntPtr)name; .Raw; .Ansi; .Utf8; ...

All additional types you can find in:

net.r_eg.LuNari.Types;
net.r_eg.Conari.Types;
Lua arg in arg out / return
lua_State* LuaState LuaState
const char* string / CharPtr CharPtr
lua_Integer LuaInteger LuaInteger
lua_Number LuaNumber LuaNumber
lua_CFunction LuaCFunction LuaCFunction
int int int
size_t size_t size_t
... ... ...

DLR

DLR features are similar to direct binding above, except fully automated binding generated at runtime by Conari!

Something like ~'.NET API Layer at runtime'. ou do not need to do anything:

d.any_function_of_Lua(L, 123, "arg3", ...)

Sample for return value:

var data = d.any_function_of_Lua<return_type>(L, 123, "arg3", ...)

For example:

// all this will be generated at runtime by LuNari:
d.pushcclosure(L, onProc, 0);
d.setglobal(L, "onKeyDown");
...
LuaNumber num = d.tonumber<LuaNumber>(L, 7);

.NET API-layer

As you can see, even the Direct binding is the most easy way to work without additional overhead.

But, LuNari aims to provide standardized use of Lua (5.4, 5.3, 5.2, 5.1, ...)

net.r_eg.LuNari.API

Full standardization by specific Lua version and flexible working between them (our internal structure allows to feel free).

Open issue, or use Pull Requests for some Lua functions that still are not presented yet in our API Layer.

To contribute in API, read this: API-Dev

πŸ—Ž

Clone this wiki locally