Skip to content
Niklas Rother edited this page Mar 3, 2014 · 3 revisions

Quick Start Guide

In this guide you will learn how to use the main features of DynamicLua. After reading this you should visit the Features-Site to learn more about the advanced features. Before reading this guide you should know:

  • C#
  • Lua
  • Your IDE (How to create projects, add references, etc.) This is not a Lua Guide!

Step 1: Download and install the package

We start by downloading the latest release of DynamicLua. Just install this NuGet package. Of cause you can also download the source code and build it on your own.

Fire up your IDE, VisualStudio in my case, but you can use virtually any IDE, and create a new project. Console App will be enough. Make sure your project targets .NET 4, because the DLR is a .NET 4 only feaure. Now add the NuGet package (or a reference to DynamicLua.dll if you build from source) The exact steps depend on your IDE (witch you should know, remember?)

Step 2: Create a DynamicLua instance

Now it comes to code: DynamicLua lies in the Namespace DynamicLua, and the main class is also called DynamicLua. This might had not been my best idea, but now its to late... We need to create an instance of DynamicLua, witch represents basically the Lua Interpreter. The type of this variable is dynamic, because we want to use the DLR. Enough talking here is the code:

using DynamicLua;
[...]
dynamic lua = new DynamicLua.DynamicLua(); //bad idea, you know...

Step 3: Start using DynamicLua

That's it! DynamicLua is ready to use. We start using it by registering a C#-Method in Lua and call it with Lua code:

lua.talk = new Action<string>((what) => Console.WriteLine("I say: " + what));
lua("talk('hi there!')"); //Prints "I say: Hi there!" to the console

You can store tables in C# variables (of type dynamic):

dynamic table = lua("return {name='me', action='writing this guide'}");
Console.WriteLine(table.action);

Just play a bit with DynamicLua, thanks to the underlying LuaInterface you can pass C# objects to Lua and use them a you would expect. I hope everything "just works" as expected, because that the goal of DynamicLua. If it don't. just fill an issue, and I will look at the problem. Have fun!

Further reading

After reading this guide you know the basics of DynamicLua. The Features site lists all available features. If you miss some, you can request them at the issue tracker. If you want to learn more about Lua, you can have a look at this site, to learn more about the DLR, look at the corresponding Codeplex Project. And finally: If you like to help me developing DynamicLua, just contact me like described on the main page