Skip to content
Completely managed .NET Lua
Find file
Latest commit 0556318 Apr 7, 2016 @frabert Fix ~= operator bug
Failed to load latest commit information.
NetLua Fix ~= operator bug Apr 7, 2016


Project description

NetLua is a completely managed interpreter for the Lua dynamic language. It was inspired by (and the LuaObject class is loosely based on) AluminumLua by Alexander Corrado. Check his project out at


I started this project because I needed a managed Lua interpreter and AluminumLua had a few bugs and caveats that were difficult to solve because of its structure. I so decided to do my own attempt at it.

Source code parsing

As of now, the parsing is made using Irony, but any LALR parser can be used to build the internal AST interpreted by NetLua. Irony looks a bit slow, but it is the easiest solution for a neat C# LALR Parser.


Using Lua from C#

Lua lua = new Lua();
lua.DoString("a={4, b=6, [7]=10}"); // Interpreting Lua

var a = lua.Context.Get("a"); // Accessing Lua from C#
var a_b = a["b"].AsNumber();

double number = a[7]; // Automatic type coercion

Registering C# methods

static LuaArguments print(LuaArguments args)
  string[] strings = Array.ConvertAll<LuaObject, string>(args, x => x.ToString()); // LuaArguments can be used as a LuaObject array
  Console.WriteLine(String.Join("\t", strings));
  return Lua.Return(); // You can use the Lua.Return helper function to return values

Lua lua = new Lua();
lua.Context.SetGlobal("print", (LuaFunction)print);

Using .NET 4.0 dynamic features

dynamic lua = new Lua();
dynamic luaVariable = lua.var; // Lua.DynamicContext provides a dynamic version of Lua.Context

double a = luaVariable.numberValue; // Automatic type casting
double d = luaVariable.someFunc(a); // Automatic function arguments and result boxing / unboxing

lua.x = 5;

Bitdeli Badge Build status

Something went wrong with that request. Please try again.