ModMaker.Lua is a complete rebuild of Lua for use in .NET. The code has been entirely written in C# with no unmanaged code. This library parses Lua code, creates a dynamic IL assembly, and executes it in a custom run-time. This library also supports object-oriented Lua by allowing the creation of new types from within Lua code. It is designed to be simple and easy to use while providing extensibility.

Getting Started

This is a .NET library, to use it you need to either download the binaries from the Downloads tab or compile the current source. This library contains no external dependencies and can be easily compiled from the included Visual Studio Project.

After you get the binary (.dll) file, you need to add it to the application you want to use. It is highly suggested that it is added as a reference to your main application so the Lua code is run at full-trust. However, the code does use the transparency model so it can run in partial trust scenarios.

First, you need to set up the main Lua object, this is done by creating an instance of ModMaker.Lua.Lua. You can pass a LuaSettings object to the constructor to change the behavior of the library. You can have more than one Lua object as they are all independent of each-other.

It is suggested that you maintain a reference to the environment through Lua.Environment. This library supported dynamic binding on all Lua objects, so it is also suggested that you store the environment in a dynamic object to simplify code. Any indexer or dynamic member access will result in getting/setting the global Lua variable.

Once you have a Lua object, you need to register any user-defined methods or types that you want Lua to have access to, see Maintaining Visibility. This is done through Lua.Register.

After any types/methods have been registered, you need to load and execute the code. Any code is parsed into a ModMaker.Lua.Runtime.IMethod object. If you use the indexer on the Lua object, you will get the loaded code at that index. If you call Lua.Load, it will return the loaded code. You can also use Lua.DoFile as a shortcut to load and execute the code.

Example

 

Lua lua = new Lua();
dynamic E = lua.Environment;
lua.Register(typeof(T));
lua.DoFile("Life.lua", "arguments");
int i = E.Variable;

 

Helping Out

This framework is really early and probably has a lot of bugs. If you come across a bug, make sure to report it. The only way I will fix them if you tell me. If there is a feature you want or don't like, also tell me. This has not undergone rigorous testing. It would be greatly appreciated if you could submit tests that you have done (good or bad) so that I can perfect this framework. This only gets better if I know where the problems are. Thanks!

What to do Next

This library contains a large number of features, below is a list of how to use each one.

Last edited May 26, 2013 at 3:28 AM by ModMaker, version 4

Comments

No comments yet.