Author Topic: xLights scripts  (Read 2610 times)

Offline dowdybrown

  • Moderator
  • Sr. Member
  • *****
  • Posts: 358
    • Gleannloch Christmas
xLights scripts
« on: November 29, 2010, »
Minibasic is archaic. However, it is important to me that non-programmers be able to modify the basic playlist script if they want to. For example, to add RDS output. Or play sequences in a random order. Or play songs during the day, then play sequences when it gets dark. Yes it does require line numbers, but my hope is that just about anyone who wanted their playlist modified in any of the ways listed above could do so.

That being said, I am open to the will of the group. What would you like to see as the scripting language for xLights? Post your preference here. Potential choices would include:

  • Keep minibasic
  • Javascript
  • Python
  • Lua, a quote from You are not allowed to view links. Register or Login
    Quote
    "I just wanted to thank you for this great scripting language! We were previously trying to embed Python but this introduced a lot of problems. After some research I found Lua which is exactly what we were looking for. The library compiled without any modifications and it took me only a few hours to write a Lua-wrapper for our data structure. Everything worked with the first try and no debugging was necessary because it behaved exactly as expected (and as described in the documentation) - amazing!"


As a reference, here is the code generated by the playlist wizard in the latest version of xLights (unreleased):

10 REM *
20 REM * Created: 11/29/10 10:46:39
30 REM *
40 ONPLAYBACKEND 1000
50 LET LastItemPlayed=999
1000 REM *
1001 REM * Jump here at end of song or sequence
1002 REM *
1005 IF SECONDSREMAINING <= 0 THEN 9000
1008 LET NextItem=-1
1010 REM Find next checked item in playlist
1020 FOR Item=LastItemPlayed+1 TO PLAYLISTSIZE
1030 IF ITEMCHECKED(Item)=0 THEN 1040
1032 LET NextItem=Item
1034 EXITFOR
1040 NEXT Item
1045 IF NextItem<>-1 THEN 1100
1050 REM Start over at beginning of list
1060 FOR Item=1 TO PLAYLISTSIZE
1070 IF ITEMCHECKED(Item)=0 THEN 1080
1072 LET NextItem=Item
1074 EXITFOR
1080 NEXT Item
1090 IF NextItem=-1 THEN 9000
1100 REM *
1101 REM * Play item NextItem
1102 REM *
1110 LET LastItemPlayed=NextItem
1115 PRINT "At:", FORMATDATETIME$(NOW,5)
1120 PRINT "Playing:",ITEMNAME$(NextItem)
1130 PLAYITEM NextItem
1140 WAIT
9000 REM DONE

Matt Brown
You are not allowed to view links. Register or Login

Offline rrowan

  • Administrator
  • Sr. Member
  • *****
  • Posts: 5899
  • 08096
Re: xLights scripts
« Reply #1 on: November 29, 2010, »
Hi Matt,

I was just checking out Lua for the first time. It seems to have a very small footprint compared to python.

Which one do you prefer? How difficult or time consuming will it be to change out mini basic with something else? I really don't know how many end users will bother with scripting. Does it make a lot of sense to change it out?

I came across these examples for a "Hello World" type program but changed to "Hello You"

Basic

10 REM Sinclair BASIC
20 INPUT "What is your name? "; LINE a$
30 PRINT "Hello ";

Javascript

<script language="javascript">
var a = prompt('your name:' ,'');
document.write('Hello ' + a);
</script>

Python

# python implementation
name = raw_input("What is your name? ")
print " Hello %s, how are you?" % (name)

Lua 5.0

-- Luna 5.0
io.write ( "What's your name?\n" );
io.write ( "Hello ", io.read(), ".\n" );

They all make sense to me, but picking one out as the best???

Cheers

Rick R.
Light Animation Hobby - Having fun and Learning at the same time. (21st member of DLA)
You are not allowed to view links. Register or Login
Warning SOME assembly required

Offline csf

  • Moderator
  • Sr. Member
  • *****
  • Posts: 118
Re: xLights scripts
« Reply #2 on: November 29, 2010, »
We may also want to take a look at squirrel scripting language

You are not allowed to view links. Register or Login

Quote
"Squirrel is a high level imperative,  object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games."

I actually read about an older version of it in a book on game design. If its fast enough for games it should be fast enough for lights.

Offline ptone

  • Sr. Member
  • ****
  • Posts: 107
Re: xLights scripts
« Reply #3 on: November 29, 2010, »
See my other thread on API.  Basically basic is fine for what its doing, and I agree with Rick it probably isn't worth the time to integrate something else.

Instead, come up with a API in C, and then bindings to that C code can be writtein for scripting languages.

Instead of embedding the interpreter, just expose the features that make sense to expose.

-Preston
--
budding channel wrangler

Offline tng5737

  • Sr. Member
  • ****
  • Posts: 480
Re: xLights scripts
« Reply #4 on: June 13, 2011, »
Was it ever decided which scripting language would be supported?

Offline csf

  • Moderator
  • Sr. Member
  • *****
  • Posts: 118
Re: xLights scripts
« Reply #5 on: June 14, 2011, »
It's going to be Matt's call as to what the schedular will use. It does not make sense for the schedule to have such a robust scripting platform as the sequencer, since the sequencer will end up being like 70% script based, wile the schedular is maybe 2% script based.