A few years ago, I came across
this excellent article, written by Martin Echenique and hosted on
GameDev.net. It discusses integrating
Lua scripting into .NET projects by assigning custom attributes. Using reflection, these custom attributes can be examined at run-time, allowing Lua functions to be loaded into the virtual machine dynamically.
I have taken Matin's project and modified it somewhat. First, I added the capability to sub-class Lua packages, allowing packages to contain other packages.
Second, I have made the Lua virtual machine (VM) non-static. This was done for two reasons.
First, I was having issues with exceptions being thrown due to reloading objects multiple times into the VM. This is caused by trying to register any functions/packages with a name that has already been registered. This is still an outstanding issue to be corrected in a future version, but is avoidable if you only load the functions/packages when you create the VM, then destroy the VM when you are finished with it, so it gets re-built the next time you run it. Not the most elegant solution, but it has served my needs so far and I haven't gotten around to fixing this yet.
The second reason is that by creating separate virtual machines, you can restrict different security access in your Lua functions. For instance, you can have a public Lua VM that is available to end users of your game/application to modify interfaces or generate batch scripts. In addition, you could have a separate administrator VM that allows an admin to make network-wide changes to everyone's application, or to provide game masters with the ability to change change events, spawn new creatures, and fix bugged characters at run-time in your MMORPG.
These libraries are required to build the revised LuaNetInterface (LNI) project and must be locally available to any projects that use LNI. They do not need to be referenced by any libraries other than LNI itself, but they do need to be copied into your executable's local directory.
LuaLibraries_1.0.0.zip (652.09 KB)These libraries come from the official Lua and LuaNet releases at
http://luabinaries.luaforge.net/ and
http://luaforge.net/projects/luainterface, respectively.
Here is the code for the revised LuaNetInterface project. Reference luaXX.dll and LuaInterface.dll from the previous .zip into your build.
LuaNetInterface_0.1.0.zip (11.64 KB)Cheers!
Devan Stormont
--
[UPDATE] The files for this project have been added to
Codeplex. They can be accessed here:
http://www.codeplex.com/luanetinterface/. Future revisions to the project can be found there.