lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Thursday 29 January 2004 04:20, Isaac Raway wrote:
> Hello,
>
> I was wondering if there are any examples of using Lua with Visual
> Basic, or if there are any libraries designed to access Lua from within
> VB. I'm writing an application in VB 6.0 and would like to call the Lua
> library to provide scripting capabilities (instead of using the horrible
> VBS control).

Not that I've noticed, but there are plenty of C examples, and you should find 
that it's little different once you've got a Lua DLL and some suitable 
Declares. IIRC pretty much all the arguments should be Longs, except for 
char*s which become Strings. If you've not constructed Declare statements 
before, you can probably find tutorials for that on the Web.

As a very much untested-and-I-haven't-touched-VB-in-years example:

Public Declare Function lua_open Lib "lua50" () As Long
Public Declare Sub lua_close Lib "lua50" (ByVal lua_state As Long)
Public Declare Function luaL_loadfile Lib "lua50" (ByVal lua_state As Long, 
ByVal filename As String) As Long
Public Declare Sub lua_call Lib "lua50" (ByVal lua_state As Long, ByVal nargs 
As Long, ByVal nresults As Long)
' etc...

Public Sub test()
	Dim L&, err&
	L = lua_open()
	err = luaL_loadfile(L, "test.lua")
	lua_call(L, 0, 0)   ' Execute the contents of test.lua
	lua_close(L)
End Sub

 -- Jamie Webb