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.
[EDIT] (September 2010) The module luacom will let you access COM objects. This is now built into version 4.60 onwards of MUSHclient. Instead of following the instructions below about downloading luacom, simply do this:
This is possible if you download luacom from LuaForge, and use it in your Lua scripts.
I obtained it from:
Specifically this section:
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:
[EDIT] Updated example, using MUSHclient 4.60 onwards:
[EDIT] (September 2010) The module luacom will let you access COM objects. This is now built into version 4.60 onwards of MUSHclient. Instead of following the instructions below about downloading luacom, simply do this:
require "luacom"
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)
[EDIT] Updated example, using MUSHclient 4.60 onwards:
require "luacom"
-- 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)