Lua Basics


To use Lua in a VB program is not exceptionally hard. Its just about half a dozen things that can go wrong and the error messages aren't all that friendly. The main issue with using Lua in a VB program is the fact that everything about Lua is designed for C languages (C++, C#). Thanks to the LuaInterface thingamabob, Lua is available to the CLR. That means that, in theory, any language using the CLR can use Lua.

HowTo: Extend W/ Lua


To extend your program to use Lua Scripting is fairly straightforward, you'll need a copy of LuaInterface, and a copy of Lua (find links here in the materials section)
Ok, now, here are the steps (Example at end of steps):

  1. Create a new project, or open an old one that you want to extend
  2. Add a reference to your LuaInterface.dll
  3. Import the LuaInterface namespace into the code/class you want to extend
  4. Create a new Instance of the Lua… engine? I dunno, its just called Lua
  5. Register your function(s)
  6. Write your script(s)
  7. Add code to fire scripts when needed
  8. Enjoy


Step By Step

The Import Code

The Lua Object Code

The Register functions Code (assume we have a class called Class1, with a method "SuperCool". In our Lua Scripts we will call this function "Joe")

Now, for the script, lets assume that "SuperCool" from our last code block expects a string as a parameter. Don't forget this is our Lua Script File (we'll call it "Joe.txt"):

Back to our VB Code, add the follow line to execute the script file "Joe.txt":

That should be it. It should run, Joe should say his witty line, and then well, thats a wrap.

Full Example



Script "Joe.txt"


VB.Net Express 2008

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License