As Jamie said calling into Lua should be very simple through a DLL.
Probably your difficult bits will be having Lua call you when scripts call
functions you've registered cause metamethod invocations etc. Without
putting a lot of thought into it I'd expect that you're going to want to
make an OLE DLL or OCX and trigger OLE events to handle "callbacks from
Lua".
In order to make a generic interface for this (as opposed to hardcoding a
particular event to a particular registered function) you will probably want
to use a single function inside the DLL as the callback function, then
trigger one particular event and pass it some context value so that the VB
code knows why the event fired (what particular registered
function/metamethod/whatever). Unfortunately, the Lua API does not allow
you to supply a "context" parameter along with the callback function pointer
so at first this seems to be a dead-end. However, you should be able to use
upvalues as your "context parameter". So rather than just using
lua_registerfunction or lua_pushcfunction you will probably want to use
lua_pushcclosure.
At any rate, that's the first path that I would look into myself.
Hope this helps. Good Luck.
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Jamie Webb
Sent: Wednesday, January 28, 2004 11:19 PM
To: Lua list
Subject: Re: Lua Use in Visual Basic
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