lua-users home
lua-l archive

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


Mohammad,

Yes it's possible.  And it is possible to expose your VB functions to
Lua so you can have integration, is it easy?  No.  But not impossible.

Dave Bollinger did a lot of work on this back in 2000 (if my memory
serves me correctly).  I built off of his work for my own
implementation (commerical product).

Quoting from the Lua mailing list:

>This DLL must be created using the standard call convention for each
>exported function. Otherwise VB will not be able to load the functions.
>BTW, In the LUA.H file you must add the _sdtcall before each function
>name.

You will have to recompile the Lua DLL, modifying the source so that
each (externally visible) function you want to call from  VB is
compiled with the stdcall convention.

Then you have to declare all of the functions you want to call out of
the DLL in VB as shown below (this is from an old project using Lua
3.2).

Hope this helps
Terry

* **** Lots of snippage **** *
Public Const LUA_VERSION = "Lua 3.2"
Public Const LUA_COPYRIGHT = "Copyright (C) 1994-1999 TeCGraf, PUC-Rio"
Public Const LUA_AUTHORS = "W. Celes, R. Ierusalimschy & L. H. de Figueiredo"


Public Const LUA_NOOBJECT = 0

Public Const LUA_ANYTAG = (-1)

Public Declare Sub lua_open Lib "lua32" ()
Public Declare Sub lua_close Lib "lua32" ()
Public Declare Function lua_setstate Lib "lua32" (ByRef st As
lua_State) As lua_State

Public Declare Function lua_settagmethod Lib "lua32" (ByVal tag As
Long, ByVal evnt As String) As Long
Public Declare Function lua_gettagmethod Lib "lua32" (ByVal tag As
Long, ByVal evnt As String) As Long
* ---------------------------------------------------------------------------------------------------------------------------------------------------------

Then in your VB program setup the Lua Engine:

Sub StopLUA()
    lua_close
End Sub
Sub InitLUA()

    lua_open
    lua_userinit
    lua_strlibopen
    lua_iolibopen
    lua_strlibopen
    lua_mathlibopen
    lua_dblibopen
    RegisterLuaExtensions

End Sub

* Register your VB code so it can be called by Lua:
Private Sub RegisterLuaExtensions()

    lua_register "MsgBox", AddressOf VBLMsgBox
    ' This next one overrides the default LUA _ALERT function so that
    ' we get a somewhat informative message box if a chunk of code doesnt work
    lua_register "_ALERT", AddressOf VBLMsgBox
    lua_register "DbgMsg", AddressOf VBLDbgMsg
End Sub

Public Sub VBLMsgBox()
    Dim s As String
        s = luaL_opt_string(1, "")
    s = Replace(s, vbLf, vbCrLf)
    DbgMsg (s)
    MsgBox (s)
End Sub

Public Sub VBLDbgMsg()
    Dim s As String
    's = luaL_opt_string(1, "")
    s = VBSafeGetOptStr(1, "")
    s = "LUA: " & s
    s = Replace(s, vbLf, vbCrLf)
    DbgMsg (s)
End Sub

On Mon, Jun 24, 2013 at 8:40 PM, mohammad <mm_617@yahoo.com> wrote:
> Hello everyone,
> I was wondering if anyone can answer to my question. Is it possible to
> execute lua code in Visual Basic 6.0 or not? if yes please explain how?
> Thanks in advance.
> Regards,
> Mohammad
>