Questions & best practice

Hi Brett,

I've been wondering about the scripts and have a couple of questions for you, hope you don't mind, I've just chucked em into a list:

1. Why lots of scripts (per function), is this necessary?

I suspect this is down to efficiency, having observed the plugboard, it only has to run a small script if an event is triggered....am I close?  How many function would you suggest to run in one script?

2. Is it possible to pass variables accross scripts

Member for

17 years

derek

16 years 2 months ago

I was new to Lua scripting before Brett rolled it into the HAH. It's a fine scripting language. I can recommend this book http://www.amazon.co.uk/Programming-Lua-Second-Roberto-Ierusalimschy/dp…

Of course, the coolest piece about the Plugboard is the way that Brett has implemented xAP message caching and access to the cache via Lua.

Re your Qs. ... (Brett will correct me if I'm not getting this right)

1. You could just lump all the code into one big script. However, I reckon that having things broken down by function makes for an easier life.

2. I don't think that there is a way to declare a Lua variable that can be seen across all scripts. However, you could send an xAP message containing the variable value and then use the cache access to find this in other scripts.

3. 'local' declares the variable as having a scope of just that function or 'chunk' of Lua code. See http://www.lua.org/pil/4.2.html

4. I don't think so. I reckon that each script runs in its own Lua interpreter 'environment'

5. 'Class' is an xAP protocol thing. Description is here http://www.xapautomation.org/index.php?title=Protocol_definition#Messag…

In practice, I reckon that most plugboard scripts are going to be looking for specific sources and targets.

Member for

16 years 10 months

brett

16 years 2 months ago

1. As Derek said its more a management feature.. There is no reason why you need a script (per function).  However if you want to share snippet of code mosty you'd share just a "BIT" which happens to be at the FILE level.

2. Yes via the CACHE only.   If you want to share variables then you have to place BOTH functions in the same script.

3. LOCAL is a scope thing.  It limits variable scope in the SCRIPT to JUST where its used otherwise the variable is availably GLOBALLY inside that script.

4. Each SCRIPT file runs in its own interpreter which is why 2. isn't possible.  In terms of memory efficiency each FILE incurs some additional memory overhead to establish this interpretter context but its minimal.  It also means if a SCRIPT crashes it won't take out the other file based scripts!

5. Class is simply there for orthoganality.  If it wasn't there somebody would find a need for it.  Mosty TARGET/SOURCE would be used.

Brett

Member for

16 years 5 months

BodgeIT

16 years 2 months ago

Thanks Guys, that sorts out a lot.

2. I don't think that there is a way to declare a Lua variable that can be seen across all scripts. However, you could send an xAP message containing the variable value and then use the cache access to find this in other scripts.

Genius, that's my work around.