Amended on Fri 15 Oct 2010 04:30 PM (UTC) by FenceWalker
Message
Thanks for the help after a couple days of reading and experimentation. I managed to get it working. Adding the line
val = var.value
was needed to actually display what was contained in the variable.
require("luacom")
require("luacom5")
local data = 1
if data == 1 then
cmud = luacom.CreateObject("cMUD.Application")
cmuds = cmud.CurrentSession
var = cmuds.getvar(MSDP,"MSDP")
val = var.value
end
print(val)
Sorry I was a bit slow to respond - got a bit distracted by the mapper.
The easiest thing might be to do what some others have done, and just get at the Access database which I believe Cmud uses. There was someone recently doing that to grab mapper information.
If that doesn't work, you could try looking at the saved data (I think Cmud uses XML?) which you might be able to parse reasonably simply.
Another thing to try would be to follow the example earlier up this page and try to get the HTML type library from the program, like this:
require "luacom" -- built into MUSHclient
require "luacom5" -- supplied as luacom5.lua
luacom.DumpTypeLib ("cMUD.Application", "c:\\cmud_typelib.html")
I don't have a copy of cMUD so I can't try that, but you might find from that what your next step would be.
Yeah I guess I was a bit non descriptive, sorry. Here is the full picture. I am trying to get the values of variables from within CMUD. *gasp* Hehe, specifically I would like to use MC and CMUD together. I have alot of scripts written in in zscript already, but there are plugins for MUSHclient that I would like to use aswell. My idea is if I could get MUSHclient to draw the info from the variables I have populated in CMUD directly I could have the best of both worlds. :)
I am using the folowing:
require("luacom")
require "tprint"
local data = 1
cmud = nil
cmuds = nil
var = nil
if data > 0 then
cmud = luacom.CreateObject("cMUD.Application")
cmuds = cmud.CurrentSession
var = cmuds.getvar(test,"\test")
data = 0
end
print(var)
tprint(var)
Can anyone offer some insight on where I need to go from here to turn that table reference into usable information?
It might be easier to answer if you gave a specific example. COM can be obscure at the best of times. But if you say something like "I want to play song 3 in my iTunes list", or "I want to get data from Cell A13 in Excel" then that gives us something to get our teeth into.
Amended on Tue 12 Oct 2010 12:50 AM (UTC) by Worstje
Message
You'll want to look into Nick's tprint function. Basically, do this:
require "tprint"
tprint(table_of_interest)
Regarding the COM object server functionality.. I am not sure that is possible. I've tried something like that once while trying to abuse the MUSHclient world object, and that basically was a big world of 'let us crash MUSHclient' since MUSHclient is not made to have its own object used outside its own process. (Technically, one probably could consider it a bug, but I think very few people know how to fix it or even need it.)
Amended on Mon 11 Oct 2010 11:34 PM (UTC) by FenceWalker
Message
Hello. MC looks to have come along nicely since the last time I used it. I have a question about COM objects in MC and was hoping I might get a little help with a couple of questions.
First I can get info from the program I have the object set up for, like the version of the program, printed to the screen of MC, so that part is ok. Some information that I am trying to view from the object however comes out like this:
table: 05E35C40
Can anyone offer some insight on where I need to go from here to turn that table reference into usable information?
Second I'm a bit confused about what ProgID or ClassID I need to use if I want to set up a COM object for MC to use with another program, if that is possible?
I'm a bit rusty with LUA in general, so try to keep that in mind and maybe dumb responses down a little if anyone has time to reply.
Amended on Fri 03 Sep 2010 01:20 AM (UTC) by Nick Gammon
Message
If you want to find more about the "type library" you can do this:
require "luacom" -- built into MUSHclient
require "luacom5" -- supplied as luacom5.lua
-- grab raw type library
rawtlb = luacom.LoadTypeLibrary("itunes.Application")
assert (rawtlb, "Type library not found")
-- convert to table
tlb = luacomE.FillTypeLib(rawtlb)
rawtlb = nil
require "tprint"
tprint (tlb) --> 17,982 lines ouptput
Example of some of the output:
71:
"helpcontext"=0
"type"="void"
"description"="True if playback position is remembered."
"prototype"="void RememberBookmark(VARIANT_BOOL p1)"
"parameters":
1:
"in"=true
"type"="VARIANT_BOOL"
"name"="p1"
"out"=false
"opt"=false
"name"="RememberBookmark"
"num_params"=1
"dispid"=1610874884
"rawMethod":
"helpcontext"=0
"type"="void"
"description"="True if playback position is remembered."
"invkind"="propput"
"memid"=1610874884
"name"="RememberBookmark"
"parameters"=table: 01A75228
"ParamsOpt"=0
"helpfile"=""
"Params"=1
"typeinv"="propput"
Or you can get a rather nifty HTML document like this:
require "luacom" -- built into MUSHclient
require "luacom5" -- supplied as luacom5.lua
luacom.DumpTypeLib ("itunes.Application", "c:\\itunes_typelib.html")
(Lengthy file appears in the nominated location). Opening that with your web browser reveals stuff like this:
Just to help people get a bit more out of COM, I tried to interface with iTunes using it. This is my preliminary test:
require "luacom"
itunes = assert (luacom.CreateObject ("iTunes.Application"))
-- print version
print (itunes.Version) --> 10.0.0.68
-- get the library
library = itunes.LibraryPlayList
-- get tracks from library
trackslist = library.Tracks
-- get count of tracks
n = trackslist.Count
print ("Number of tracks =", n)
-- enumerate each track
tracks = luacom.GetEnumerator (trackslist)
-- get first one
track = tracks:Next ()
-- play first track
track:Play ()
-- print all track names
while track do
print (track.Name)
track = tracks:Next ()
end -- while
Afterwards, and I'm not sure where you would put this, if anywhere, you can dispose of the COM object:
Well based on the advice from you guys, I have modified my approach.
Luacom is now compiled into MUSHclient, so the issue of clashing DLLs goes away.
LuaSocket is not, however as the relevant DLLs (core.dll and core.dll - sigh) are in a subdirectory they are unlikely to clash with your stuff.
You need to require "luacom" based on Twisol's suggestion of using package.preload. This stops any possible overhead or difficulty under Wine/Parallels, because nothing will happen if you don't "require" it.
My tests show it works more reliably than the earlier DLL anyway.
The documentation is supplied in the distribution, plus the file luacom5.lua which adds extra functionality if you want to require that as well.
The executable is only about 90 Kb larger, and that includes the other enhancements in this version as well.
We've already seen that there's something different between the dlls you've compiled and the ones that LfW has distributed, like the Lua 5.1 syntax actually working with theirs.
Huh? What syntax? Can you give an example? I haven't changed the way Lua works except maybe turn off some of the deprecated functions they actually recommend you turn off (via the standard config file).
require "luacom"
It fails for you and Twisol; works just dandy for me.
I can require() 95% of the included libs distributed with LfW fine (and just that one funky one I asked about last year fails).
I guess I'm thinking that of all the libs to distribute, I'm wondering about a funky version of LuaCom. (btw, your version is 204,800 bytes. LfW's is 172,032 bytes.)
Lpeg? Definitely.
LuaCURL or LuaSocket? Yup I can see them being included.
A LuaCom distro that behaves weirdly? When you've always maintained that you want MC to run fine under WINE and Parallels (No real COM support)? Just seems weird.
In all of MC's history it hasn't really been needed, and the only reason it's come up now is because one person wanted a plugin ported from one language to another (I suspect the same flakiness he saw in the VB implementation will appear with Lua using the same COM interfaces.)
And you don't have to tell them to get LfW. Luaforge or LuaRocks can get them libs as well. There's multiple ways to get them...
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.