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


Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Accessing COM objects from Lua

Accessing COM objects from Lua

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1  2 3  

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #15 on Wed 01 Sep 2010 08:55 AM (UTC)
Message
http://code.google.com/p/luaforwindows/
[Go to top] top

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #16 on Wed 01 Sep 2010 10:48 AM (UTC)
Message
Oh. Wow.

A 212 Kb download, which is the entire Lua source, has morphed into a 19.6 Mb set of utilities.

But even if I download and install that, and update luacom.dll to be the one with the new entry point, and assuming that I don't also have to supply other things (an assumption I wouldn't make lightly, see screenshot below), then all existing MUSHclient users who happen to have scripts like the screen-readers that currently work with the existing entry point, would now fail if the DLL was quietly replaced by one with different entry points.


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #17 on Wed 01 Sep 2010 10:57 AM (UTC)

Amended on Wed 01 Sep 2010 10:59 AM (UTC) by Nick Gammon

Message
To be honest, I don't really want to download a 19.6 Mb executable which will install <I don't know what> <I don't know where> to find what the name of an entry point in a DLL is. Sorry.

- Nick Gammon

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

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #18 on Wed 01 Sep 2010 04:29 PM (UTC)
Message
I'm not asking ya to... Just, if you please, don't let MC's install break the environment.

I use Lua in a lot of places other than MC; it is in my home domain's login scripts, maintenance scripts, 'chron' type jobs...

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.

LfW is Lua precompiled into a binary (lua.exe, luac.exe), 43 libraries, samples, documentation, and SciTE in one package. It's not much different in bandwidth than DLing MC and Crimson Editor and a few random Libraries that you might want... Except you don't have to go hunting for the library's website.


I'd suggest that if a library is important enough to distribute, like lpeg; compile it into the exe like lpeg. If you're just trying to set up a 'batteries included' environment, someone already did that for you.

http://cid-73890baf188d56e7.photos.live.com/self.aspx/MCForum/luacom.dwi has the profile of my dll, if you're curious and since you can probably make more of it than I can. :)
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #19 on Wed 01 Sep 2010 04:31 PM (UTC)

Amended on Wed 01 Sep 2010 04:33 PM (UTC) by Twisol

Message
Why would it break the environment? AFAICT, MUSHclient doesn't affect any environment variables, and it's moved away from the registry.

[EDIT] I do agree with compiling these things into MUSHclient itself, though. You can add your loader function to package.preload['library name'], too, so you still have to call require() before you can access the libraries. I prefer package.preload over adding the libraries immediately, because just like the scripts in the lua/ folder, it's opt-in.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #20 on Wed 01 Sep 2010 09:15 PM (UTC)
Message
WillFa said:

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).

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #21 on Wed 01 Sep 2010 09:21 PM (UTC)
Message
WillFa said:

I'm not asking ya to... Just, if you please, don't let MC's install break the environment.

I use Lua in a lot of places other than MC; it is in my home domain's login scripts, maintenance scripts, 'chron' type jobs...


But it shouldn't, right? Your other Lua stuff will find your other DLLs first (wherever you have them, eg. in the Windows system folder).

The way the search paths work, only when you are running MUSHclient, from the MC directory, and choose to use luacom, should it pick up the luacom.dll I supply in the MC directory.

You can confirm it. Download this:

http://www.gammon.com.au/files/mushclient/lua5.1_extras/luacom.zip (90 Kb, not 20 Mb cough cough).

Put it in the MC install directory. Then see if all your other stuff still works. I'll be surprised if it doesn't. If it stops working, delete that DLL and you are back to how everything was.

I mean, honestly, it shouldn't be in the power of an application to stop all your other apps from working, particularly if you, as I do, localize installs to a single directory (and subdirectories). It might be different if MC shoved DLLs all over the shop, like into the Windows directories, but it doesn't do that.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #22 on Wed 01 Sep 2010 09:23 PM (UTC)
Message
WillFa said:

LfW is Lua precompiled into a binary (lua.exe, luac.exe), 43 libraries, samples, documentation, and SciTE in one package. It's not much different in bandwidth than DLing MC and Crimson Editor and a few random Libraries that you might want... Except you don't have to go hunting for the library's website.


I just don't like the idea of having to tell people to do a 20 Mb download (Lua for Windows) to add a small bit of extra functionality to a 3 Mb downloaded program (MUSHclient).

- Nick Gammon

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

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #23 on Wed 01 Sep 2010 10:35 PM (UTC)
Message
Nick Gammon said:

WillFa said:

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...
[Go to top] top

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #24 on Wed 01 Sep 2010 10:46 PM (UTC)
Message
WillFa said:

require "luacom"


It fails for you and Twisol; works just dandy for me.


That's not a syntax error. It is correctly reporting that the entry point does not exist in the DLL.

- Nick Gammon

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

Posted by WillFa   USA  (525 posts)  [Biography] bio
Date Reply #25 on Wed 01 Sep 2010 11:23 PM (UTC)

Amended on Wed 01 Sep 2010 11:26 PM (UTC) by WillFa

Message
So that syntax doesn't work...
It's not supported syntax...
It's lexically correct, but your module doesn't support it.
Pedantic... sorry. moving on.


Depends shows that your version has a missing 'required implicit or forwarded dependency' on my system. There's an unresolved link to MSVCR80.dll.

It has 4 exports, LfW's has 7, including luaopen_luacom, which is probably what require is looking for.

[Go to top] top

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #26 on Thu 02 Sep 2010 12:57 AM (UTC)
Message
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.

- Nick Gammon

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

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #27 on Thu 02 Sep 2010 06:47 AM (UTC)
Message
Nick Gammon said:

LuaCOM is now included in version 4.60 onwards of MUSHclient. So you can just use it without downloading any files. For example:


-- load Lua COM
com = require "luacom"
  
-- Instantiate a SAPI voice object
talk = assert (luacom.CreateObject ("SAPI.SpVoice"), "cannot open SAPI")
  
-- Method call
talk:Speak ("SAPI installed and is ready.", 1)


Amended so you just need to require "luacom", which is now built into the MUSHclient executable.


Your example here sets 'com' from the require call but never uses it. It doesn't affect anything, but it does look odd.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #28 on Thu 02 Sep 2010 08:12 AM (UTC)
Message
Sigh. That's what happens when you keep changing things. I fixed up that post.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,019 posts)  [Biography] bio   Forum Administrator
Date Reply #29 on Thu 02 Sep 2010 10:14 PM (UTC)
Message
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:


-- stop using it
itunes = nil
collectgarbage ( )


- 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.


128,816 views.

This is page 2, subject is 3 pages long:  [Previous page]  1  2 3  [Next page]

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at HostDash]