neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
466 stars 76 forks source link
c-sharp dlr dotnet language lua

NeoLua

A Lua implementation for the Dynamic Language Runtime (DLR).

Introduction

NeoLua is an implementation of the Lua language. Currently, the implementation is on the level of Lua_5.3 (http://www.lua.org/manual/5.3/manual.html). The goal is to follow the reference of the C-Lua implementation and combine this with full .NET Framework support. That means, it should be easy to call .NET functions from Lua and it should be easy access variables and functions from a .net language (e.g. C#, VB.NET, ...).

NeoLua is implemented in C# and uses the Dynamic Language Runtime. It therefore integrates very well with the .NET Framework.

Quickstart

You can play and test the language with the tool NeoCmd.

NeoCmd

Or there are two easy ways to use NeoLua in your project.

Simple example:

using (Lua lua = new Lua()) // Create the Lua script engine
{
    dynamic env = lua.CreateEnvironment(); // Create a environment
    env.dochunk("a = 'Hallo World!';", "test.lua"); // Create a variable in Lua
    Console.WriteLine(env.a); // Access a variable in C#
    env.dochunk("function add(b) return b + 3; end;", "test.lua"); // Create a function in Lua
    Console.WriteLine("Add(3) = {0}", env.add(3)); // Call the function in C#
}
Using lua As Lua = New Lua ' Create the Lua script engine
    Dim env As Object = lua.CreateEnvironment(Of LuaGlobal)() ' Create a environment
    env.dochunk("a = 'Hallo World!';", "test.lua") ' Create a variable in Lua
    Console.WriteLine(env.a) ' Access a variable in VB
    env.dochunk("function add(b) return b + 3; end;", "test.lua") ' Create a function in Lua
    Console.WriteLine("Add(3) = {0}", (New LuaResult(env.add(3)))(0)) ' Call the function in VB
End Using

A more "complex" script, that shows the interaction between lua and .net:

local t = clr.System.Int32[](6, 8, 9, 19);",
return t:Sum(), t:Where(function(c : int) : bool return c < 10 end):Sum()

NeoLua is a .NET portable assembly (IL) for

There will be no support for .NET Frameworks lower than 4.5.

It does not work with

What NeoLua is useful for

So, this could be reliable partner for your compiled .NET application or engine (e.g. game engines).

What I did not have in mind

Advantages of NeoLua

Drawbacks of NeoLua

Drawbacks of bridges to c-lua, that are solved with NeoLua

Documentation

This documention has the same structure like the official reference (Lua 5.3), so it should be easy to compare the two worlds.

  1. Introduction
  2. Basic concepts
  3. Language
  4. Application Program Interface
    1. Getting started
    2. Script engine
    3. Chunks
    4. Table's
  5. The Auxiliary Library
    1. clr library
    2. Extent lua table
    3. Debugging
  6. Standard libraries
  7. NeoCmd

If there is something unclear, wrong or misunderstanding please use the discussions.

Projects that use this library

Links

You want pay for your request, contact us under https://tecware-gmbh.de/kontakt.html (only for members of the european union).

Or you want todo something good for other people. Donate to https://angelman.de/unser-verein/spenden/ (only in german)