Stencil test bug fix and lua bindings

Fixed bug where wrong RenderState variable was set for stencil write.  … 
Added missing Lua bindings.

__Note__: I don't have any Apple products in my possession and have no way to add the new Lua files to the Xcode project for OS X and iOS development.

Also, you can probably close #1081 since this completes his/her request.