"I understand that button.action is assigned a value returned by buttonPressed(), but why wrap it into anonymous function like that?"
You got it wrong. The statement:
button.action = function() buttonPressed() end
assigns to button.action an anonymous function that, when called, will in turn perform the call buttonPressed(). Note that the anonymous function doesn't return anything, so it is called only for its side effects. This is a common idiom with callbacks. You use an anonymous function to delay the execution of some piece of code (in this case, only the call to buttonPressed) until you need to execute it.
Given the names of your snippet I guess that this code sets the action to be performed when some button is pressed. When the button is pressed, then the action is fired (somewhere in the bowel of the code there will be a call like button.action() that calls the anonymous function stored in button.action) and the call buttonPressed() is performed.
endfor closing a block scope but nothing starting it. Are you sure that's the full code?