Inside the "send to script" the entire contents is sent to the script engine to be compiled and run.
Thus something like "Note (2+2)" will work.
However when you call the function you are simply displaying the string "2+2".
You can rework the function a bit to use loadstring (which is effectively what the "send to script" does). Here is an example:
function evaluate (n,o,wc)
-- compile it
local f, e = loadstring (wc [1])
-- error? show it
if not f then
ColourNote ("brown", "", e)
return
end -- compile error
-- no errors, execute it
f ()
end
The function loadstring calls the Lua compiler, and returns a function, which is nil if an error occurs, and an error message, if there is an error.
Thus we can test for nil and show the error.
Afterwards, if no error, we can execute the function to cause it to run.
A simpler approach is to use assert, and let the built-in error handling kick in:
function evaluate (n,o,wc)
assert (loadstring ( wc [1])) ()
end
However in either case we have a problem - you are supposed to supply an entire Lua chunk, not just an expression. For example:
eval 2+2 --> unexpected symbol near '2'
This is because "2+2" is not valid, any more than it would be inside a "send to script". This works however:
I presume you are just playing here? What you end up doing depends on what you are really trying to do. For example, if you are always planning to evaluate a calculation, you could make it into an assignent:
function evaluate (n,o,wc)
local calculation = "i = " .. wc [1]
-- compile it
local f, e = loadstring (calculation)
-- error? show it
if not f then
ColourNote ("brown", "", e)
return
end -- compile error
-- no errors, execute it
f ()
-- print results
print (i)
end
Now I have put the results (2+2) into "i", which is then printed at the end.