View Full Version : Simple Lua help

July 10th, 2006, 09:56 AM
I'm using the EXEtuner plugin (external tuner) for SageTV, together with a Lua script triggered on girder 3.3. Basically, the plugin triggers an event with an associated pld1 string which is the channel number I want to tune externally. Here's the piece of code that converts the pld1 to numbers and independent "number" events:

l = strlen(pld1);
for i = 1,l do
s = strsub(pld1,i,i)

I'd like to modify this a little bit. I'd like to add some conditionals for certain channels. Let's say that, when EXEtuner sends "235" as the pld1, I'd like that channel number to be converted to "101" and girder to send the "1", "0", "1" events.

Something like this:

if pld1==235 then

Now, since I know next to nothing about Lua programming, I can't find the correct sintax for this. I'm guessing pld1 is a string, not an integer and I have to do some kind of conversion. Can anyone give me a hand on this? Should be very simple for experienced users.


July 10th, 2006, 05:59 PM
Yuou probably want to use a table to do the conversion. This way you avoid having long if/else statements:

First declare the table:

conversion_table =
[235] = "channel_101",

then use it:

l = strlen(pld1);
for i = 1,l do
s = strsub(pld1,i,i)
replace_s = conversion_table[s]
if replace_s then