PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Kagehi on 03 December, 2004, 19:04:59

Title: Using unknown COM events..
Post by: Kagehi on 03 December, 2004, 19:04:59
Let me see if I get what Lua is doing when it deal with events and ActiveX objects..

1. Reads the internal table.
2. Exposes properties, etc.
3. Creates dummy functions for each event???

Then later, when you create an event handler, it overrides the dummy function for it, right?

So, here is the problem. What if you are not sure what events have been exposed? How do you figure out what events Lua found, so that you can create a proper function to handle it? I mean, I have no clue even how such names get assigned to an event, just that somehow in the background something gets read from the table and certain applications assign a predetermined name to the events found, and not always the exact name in the table. How do I know what Lua 'found', so I know what to connect to? I would kind of like to avoid getting an error telling me I guessed wrong, then having no where to go from there. ;)
Title:
Post by: Kagehi on 06 December, 2004, 22:45:44
Ok.. Having rethought things.. I realize that the code in the examples I saw merely creates an entry in a table and that table is passed to the connect command... So, there is no way through that to figure out what the events are before hand.

I suppose a better explaination of what the problem really is would be in order. The most basic code involved would be:

winampCOM = luacom.CreateObject("WinampCOM.Application")
events_handler = {}
function events_handler:SongChange()
  print "Song changed to " + winampCOM.CurrentSongTitle
end
events_obj = luacom.Connect(winampCOM, events_handler)

Now, the major issue here rests on how exactly such event management works in the specific case I need it. I am using a client called Mushclient -  //www.gammon.com.au/mushclient (http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4952 for the thread that announces the latest unofficial version. The last full version does not have Lua support) and the WinAmp COM plugin from - http://mysite.wanadoo-members.co.uk/johnadcock

Mushclient will execute functions in the script in various way, but since the script is running in the same thread as the client (do to syncronization issued with incoming text), it suspends the script when not in use. The complications involved are miriad and revolve around these questions:

1. How does events and connection points in Lua work actually?
2. Are these events passed through Mushclient's event system, then passed down to the script engine?
3. Does the script engine capture and handle them seperately, like a seperate application would, even though in this case it is running as a dll?
4. Does suspending the script so that the client can handle its own tasks also suspend the ability of the engine to handle events and wake up the script to execute the functions for them?
5. Is there any way to have the client itself capture the event and call the appropriate functions, if #4 above is true and suspending the script does also suspend event handling?
6. What about coprocedures? Are they also automatically suspended when the client suspends the main script?

Needless to say, answering these is a 'major' issue if those of us using the client don't want to spend almost all of our time trying to shoehorn existing ActiveX applications into dll wrappers that employ obscure work arounds, instead of just dealing with the events properly in the first place.

No one on the Mushclient forums has a clue how these things work, especially given this specific situation, so we are all guessing, including the guy that added Lua support to the client in the first place. It would be nice to have some answers to the above questions.
Title:
Post by: plop on 07 December, 2004, 01:14:39
best 2 ask these things from rabitwombat or sedules.
if they don't respond on this board you can find them in the dc-dev hub.

plop
Title:
Post by: Kagehi on 07 December, 2004, 01:25:49
Dang.... Guess when I start looking for solutions I need to take a closer look where they come from. LuaCOM is a seperate library, not part of the Windows Lua binaries themselves... So, basically everything I asked here is likely totally irrelevant to this forum anyway. Sigh.. I am now a less than happy camper, since it means I am now down over six scripting options that the client supports and still have no solution to the one pain in the rear problem I was hoping Lua had a built in way around to start with.

Sorry for wasting people's time on here. :(
Title:
Post by: plop on 10 December, 2004, 18:13:26
nearly all of us are just simple scripters, but for example sedules has added the lua api to dch++ and bcdc++.
wombat added mysql support 2 the lua api in a modded bcdc client.

plop
Title:
Post by: Kagehi on 10 December, 2004, 22:14:15
Hmm. Yeah. Most of the stuff people are likely to do with Mushclient is pretty simple too. However, some of us are not satified with just what the client supports. There have been people that makes plugins (XML containing triggers, timers, aliases and script) for it, which link to external applications, like one I made as an experiment to display fireworks in response to events from the game or another who made a map program for a Battletech based mud. Two things that Lua 'seemed' to solve, which always frustrated us, where external calls that 'hang' the client until finished and the inability to respond to events from any application we linked to.

For example, you could use some tricks in most of the supported script types to link to the Windows Inet API, this could let you read the html from a web page, then use the script to find something on it. The problem is that on a dial-up, just connecting to and reading the HTM could take almost a minute at the minimum, during which the client itself can't do anything (since the script is still active). CoProcedures 'may' solve this.

With events.. The one attempt I made was with WinAmp. The theory? Link to the COM interface plugin for it (not easy to find, but a 'complete' one does exist), then allow WinAmp to tell the script when the song title changes, by responding to the event, reading the new title, then placing it on an 'infobar' in the client. The problem is the VBSCript, JScript, et al either can't respond when the script was suspended or, in the case of the two I named, only allow special Web Controls to be linked in and responded to. I got around it by literally requesting the current songe title once every two seconds. LuaCOM 'appears' to provide a way to fix this and do it properly, though whether it will work...

Anyway. Believe me, the plugin I made for the client for handling potions for the Druid guild is 'complicated' (830 lines of code). The code to link in and use Winamp is probably less than 20 lines of code. Basically:

function OnPluginInstall()
   winampCOM = luacom.CreateObject("WinampCOM.Application")
   events_handler = {}
   events_obj = luacom.Connect(winampCOM, events_handler)
end

function events_handler:SongChange()
   world.info (winampCOM.CurrentSongTitle)
end

Plus a few lines tied to aliases to let you start and stop playing. Maybe some to set the volume... But not at all that complicated. ;) BTW: world. are client functions, in case you wondered where that came from.