Implementing LUA

Adding LUA scripting to your .NET project is really simple.

1. Download LuaInterface
http://luaforge.net/projects/luainterface/

2. Copy LuaInterface.dll and lua51.dll to your project folder.

3. Add a project reference to LuaInterface.dll

Example C# code:
private readonly Lua lua = new Lua();

lua.DoFile("script.lua");

LuaFunction luaFunction = lua.GetFunction("square");
double ret = (double)luaFunction.Call(5).GetValue(0);

Console.WriteLine(ret.ToString());

The script.lua file looks like this:

function square(x)
 return (x * x)
end

It's also very easy to expose variables, functions, classes and even the whole CLR to LUA. I'll explain how this works in a later post.

0 kommentarer:

Post a Comment