What about creating the variables outside the OnUpdate function and then change the values?
As such:
Code:
local var
local foo
local crap
frame:SetScript('OnUpdate', function()
var = "var"
foo = "foo"
crap = "crap"
if dostuff then
dostuff
end
end)
It's what i did when i had performance issues and it helped loads, this is obviously not a working function and you would have to tweak it to your liking.
I'm nowhere near the others in terms of knowledge of LUA though, so this might not be the optimal solution.
EDIT: This also solves the issue where a global foo is not found.