tags:

views:

383

answers:

2

I'm wondering if anyone has any tips for integrating LUA and VB6. I am running a small Online RPG that would be awesome to add some scripting to.

+4  A: 

Well, it is doable. I once did it for Lua 5.0.2 but I can't find the files. Among the options you have, you can:

  • Wrap Lua in a COM dll exposing the Lua API, so in VB you can add a reference to it.

  • Build your custom Lua version, using the __stdcall calling convention, so you can use Declare in VB to import the needed Lua functions. Writing a Type Library will ease a lot the integration with VB (mainly, it will do the conversion from C strings to VB strings for you).

  • Build a wrapper DLL, that replicates Lua's interface but using __stdcall, adding the functions that are defined with macros, etc.

I remember that using a custom built Lua, I could register VB functions (defined in modules) into Lua and call them from a script. I don't recall if I ever got it to call member functions.

I hope this can get you started.

Ignacio
+1. Note that Matt Curland's book "Advanced Visual Basic 6" includes a way to call CDECL DLLs from VB6, but it is to be used with discretion since it adds an overhead to each function call. It might be better to build a custom __stdcall version of this LUA RPG thingy.
MarkJ
Overhead that is about a string assignment in size and performance :-))
wqw
@wqw: it's true that most of the time the overhead might not be relevant, just like the overhead of a string assignment mostly isn't relevant.
MarkJ
+1  A: 

Use LuaInterface. It's a .NET Library that allows you to use lua. However it doesnt come with docs in and of itself, look at this for some helpful guides.

Basically, you add the DLL to your project and reference it/add using satements, then create a new Lua object. From there, you can access it like an array to extract variables, and there are methods to call lua functions and manipulate tables.

RCIX