Return values from a function?

Sorry to be so dense about Squirrel but…

I have some code that calls a function:

foo (variable);
server.log("write " + variable);
local othervariable = variable * (some numbers); etc.

which looks like:

function foo (temp) {
local a = i2c.read(some stuff);
temp = a[0] * (some numbers);
return temp;

but the IDE complains that variable is undefined. What is the correct way to have a function return a “global” integer for use by the “main” program?

OK, figured it out. I need to use the <- assignment!

Or you can put

local someVariable;

at the top of your program, ie. what is essentially (though not written in Squirrel as such) the program’s main() function.

PS. The reason for doing it this way is that it’s slightly quicker (index look-up vs string-matching look-up). See ‘Writing Efficient Squirrel’

Also see Peter’s excellent blog post on the subject: http://pdh11.blogspot.co.uk/2014/12/optimising-squirrel-for-speed.html