PDA

View Full Version : VBscript to Luascript



gugi
May 6th, 2007, 01:25 PM
Hi there,

I tried to convert this VBscript excerpt of code to LUA (for Girder 3.3) without success - can please anyone help me?! Thanks much!

The whole file is attached for reference (this is a VBscript to switch to an iTunes playlist within a DOS prompt) and also the iTunes SDK with description of the object types. Thanks again.



Dim iTunes 'As iTunes
Dim ArgPlaylist 'As String
Dim ArgPlaylistLcase 'As String
Dim Playlist 'As IITPlaylist
Dim TempPlaylist 'As IITPlaylist

' Find the specified playlist
Set Playlist = Nothing
ArgPlaylistLcase = LCase(ArgPlaylist)
For Each TempPlaylist In iTunes.LibrarySource.Playlists
If LCase(TempPlaylist.Name) = ArgPlaylistLcase Then
' Match!
Set Playlist = TempPlaylist
Exit For
End If
Next 'TempPlaylist

' Start playing the playlist
Playlist.PlayFirstTrack

Promixis
May 6th, 2007, 06:51 PM
hi,

there are some itunes egs. in the download section. i haven't played with the g3.3 COM stuff in a long time...

see

http://promixis.com/download.php?ID=615

gugi
May 6th, 2007, 07:01 PM
I know all the iTunes downloads but they can't start playing a specific playlist which name has been passed in a payload string through a serial interface. I have done all other work in a very complex iTunes module (based on yours at http://promixis.com/download.php?ID=615), just need help in converting the playlist traversal from VBscript to Lua, as I am not very good with Lua - I know the Lua manual, have tried the conversion by myself, but can't convert the following statement:

For Each TempPlaylist In iTunes.LibrarySource.Playlists

I know the count and I can do
for i=1,count
but I can't do
TempPlaylist = Next(TempPlaylist)
in the for loop as I don't see a Next method in IITPlaylist which is the type for TempPlaylist
nor any other possibility in Lua?!

If anyone could help me I will much appreciate it. Thanks!

I have come up with this so far:



iTunes = luacom.CreateObject("iTunes.Application")
-- and other initializations...

local TempPlaylist = iTunes.LibrarySource.Playlists
local count = iTunes.LibrarySource.Playlists.Count

while TempPlaylist do
If TempPlaylist.Name == pld1 then -- is this ok to compare two strings maybe with upper/lower case?
break -- is this ok to break out of the while loop when matched?
else
TempPlaylist = -- how to get next in list?
end
end

TempPlaylist.PlayFirstTrack()

harleydude
May 6th, 2007, 08:32 PM
Been a while since I have done this, but it it something like this.

http://www.tecgraf.puc-rio.br/~rcerq/luacom/pub/1.3/luacom-browseable/node49.html

Mark F
May 7th, 2007, 09:11 AM
Looking at Rick's reference, does this work? I haven't tried it.



-- assume the iTunes object is already created

-- Get an enumerator for the playlist collection
local playlist_enum = luacom.GetEnumerator(iTunes.LibrarySource.Playlist s)

-- get the first playlist
local TempPlaylist = playlist_enum:Next()

-- while we have more playlists (and no matching name)
while TempPlaylist do
-- does the name match (upper each to remove case problems)
If strupper(TempPlaylist.Name) == strupper(pld1) then
-- play the first track in the list
TempPlaylist.PlayFirstTrack()
-- delete the playlist variable
TempPlaylist = nil
else
-- get the next playlist
TempPlaylist = playlist_enum:Next()
end
end
-- delete the enumerator
playlist_enum = nil

-- If I remember right, you should garbage collect after this as well :)

Rob H
May 7th, 2007, 09:27 AM
Although if this is Girder 3 then you need to use Lua 4 syntax so string.upper would be strupper.

gugi
May 8th, 2007, 05:25 PM
Thank you very much!

When I want to send the string (through the serial plugin)

COMMAND"/song:"Whip It""

how should I escape the inner "?

When I do not escape, the string gets truncated to
pld1 = /song:

but I want to have
pld1 = /song:"Whip It"

Is there anything like pld2, pld3? When I try to print I don't get them.

Thanks again!

gugi
May 13th, 2007, 11:26 AM
Any suggestion? Please

Rob H
May 13th, 2007, 12:06 PM
You'll have to consult the iTunes documentation about that - I'm afraid I have no idea what escape mechanism it supports.

I'd probably try a couple of things e.g. using single quotes ' or possibly preceding the inner quotes with a backslash or percent symbol.

gugi
May 13th, 2007, 05:13 PM
Rob, this is a serial plugin/Lua question and not related to iTunes. I am sending a string through a serial RS232 port to Girder's (3.3) serial plugin and it gets truncated there. The string coming in looks like

COMMAND"/song:"Whip It""

When I get into the COMMAND event in Girder and print the payload pld1 in the luascript portion of the event I get only

pld1 = /song:

i.e. the string is truncated at the second quote (pld2 and pld3 are obviously not used and empty). I have of course tried to use \ which is the lua escape sequence but without luck as this actually has nothing to do with Lua. I have debuged and know for sure that the string get sent as stated above, then girder gets into the COMMAND event and then pld1 contains only "/song:". This is something internal to the string processing of the serial plugin as it truncates the string there and puts only the first portion into pld1. Probably Mark F can jump in and say a word about that?

Thank you again!

Rob H
May 14th, 2007, 02:47 AM
Sorry, I misunderstood. I'll have to leave this to MarkF as he's the G3 serial plugin expert.

gugi
May 15th, 2007, 04:29 AM
Anyone who knows how the SERIAL PLUGIN process strings?

Mark F
May 15th, 2007, 09:53 AM
If the data comes across the serial link as COMMAND"/song:"Whip It"" then the rest is parsing (as you said). Do you have a LUA script as a receive (character) event handler doing the parsing or are you letting the serial plugin do default parsing? What receive settings are you using?

You mentioned you tried the \ escape character. You mean you sent this:

COMMAND"/song:\"Whip It\""

and it still didn't work? Could you try this:

COMMAND"/song:'Whip It'"

(notice Whip It is surrounded by single quotes)

The serial plugin takes the received data and gives it to Girder to place in a variable. All LUA string rules apply when the string is assigned to pld1 (a variable) so everything after the first matching " will be discarded unless you do special preparation.

By the way, Devo is now stuck in my head. :)