Implement apply as a NScripter subroutine.
Fix a bug (issue #6).