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 reference the DLL

We start by downloading the latest release of DynamicLua. It's probably the best to use the binary release, but you can grab the source code and build DynamicLua on your own if you like. At the time of writing, the latest release is 1.0beta.
After downloading and unzipping the download (and optional building everything) you should have three *.dll-files:
  • lua.dll This is the code of the associated Lua release. At the time of writing this is 5.1.4.
  • LuaInterface.dll This DLL contains the Lua<->C#/.NET Bridge
  • DynamicLua.dll Thats easy, right? Yes, thats the the DLL containing DynamicLua ;)
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. You need to copy all three DLL at a place where your program can find them.
Just next to the .exe file is always a good place. Then add a reference to DynamicLua.dll. 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'}");
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 or start a discussion about it. 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.

Last edited Sep 1, 2013 at 9:59 AM by simsmaster, version 3


No comments yet.