Add onWindowClose API

Signed-off-by: Kirill Enykeev <enykeev@gmail.com>
Fix for "attempt to call a nil value" (thanks to both tommo.zhou and xonglennao)

Signed-off-by: Kirill Enykeev <enykeev@gmail.com>