[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Accessing COM objects from Lua
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Accessing COM objects from Lua

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Nick Gammon   Australia  (15,394 posts)  [Biography] bio
Date Thu 27 Oct 2005 12:55 AM (UTC)  quote  ]

Amended on Sat 27 May 2006 09:33 PM (UTC) by Nick Gammon

Message
Although Lua is not implemented using the COM (Component Object Model) interface, sometimes it is useful to be able to use COM from within your scripts.

This is possible if you download luacom from LuaForge, and use it in your Lua scripts.

I obtained it from:


http://luaforge.net/


Specifically this section:


http://luaforge.net/projects/luacom/


For this demonstration I only needed the file luacom-1.3-bin.tgz, although the file luacom-1.3-doc.pdf is also useful, being the documentation.

I extracted the archive and got the file luacom-lua5-1.3.dll which I placed in the same directory as the MUSHclient executable.

Then, running the following invoked the Microsoft Calendar program:




-- load luacom
assert (loadlib ("luacom-lua5-1.3.dll","luacom_openlib")) ()

-- Instantiate a Microsoft(R) Calendar Object
calendar = luacom.CreateObject("MSCAL.Calendar")

-- Error check
if calendar == nil then
  error ("Error creating object")
end

-- Method call
calendar:AboutBox()

-- Property Get
current_day = calendar.Day

-- Property Put
calendar.Month = calendar.Month + 1

print(current_day)
print(calendar.Month)

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (15,394 posts)  [Biography] bio
Date Sat 27 May 2006 09:52 PM (UTC)  quote  ]

Amended on Sat 27 May 2006 09:53 PM (UTC) by Nick Gammon

Message
The method described above does not seem to work with recent versions of MUSHclient that use the lua50.dll, because the earlier LuaCom implementations required different DLLs.

The latest download from their site works with slightly different code. This time I will use the SAPI object to "speak" something:


assert (loadlib ("luacom.dll","luaopen_luacom")) ()

-- Instantiate a SAPI voice obejct
talk = assert (luacom.CreateObject ("SAPI.SpVoice"), "cannot open SAPI")

-- Method call
talk:Speak ("hi there")



The link I used to download the luacom.dll was:


http://luaforge.net/frs/download.php/922/luacom-1.3-luabinaries-bin.zip


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (15,394 posts)  [Biography] bio
Date Mon 26 Mar 2007 06:41 AM (UTC)  quote  ]
Message
For more recent versions of MUSHclient (3.80 onwards) you need to use package.loadlib, like this:


assert (package.loadlib ("luacom.dll","luacom_open")) ()


Also, the version of luacom that has been compiled for Lua 5.1 is available here:

http://www.gammon.com.au/files/mushclient/lua5.1_extras/luacom.zip


See this thread for more discussion:

http://www.gammon.com.au/forum/bbshowpost.php?id=6593

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


6,829 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]