|
Accessing COM objects from Lua
|
Reply to this subject
Start a new subject
 
Refresh page
| Posted by |
Nick Gammon
Australia (15,394 posts) 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 | top |
|
| Posted by |
Nick Gammon
Australia (15,394 posts) 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 | top |
|
| Posted by |
Nick Gammon
Australia (15,394 posts) bio
|
| Date |
Mon 26 Mar 2007 06:41 AM (UTC) [ quote
] |
| Message |
|
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
Start a new subject
 
Refresh page
top
Comments to:
Gammon Software support
Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )