Misc fixes in the script engine.

- Made the thread pointers be removed at file closure, to let
lua handle them properly.
- Fixed a potential crash in a table data type lookup.
- Properly test whether a file is open before writing in it.
- Properly check the number types as it couldn't do it before,
and this could be useful for floats, for instance.
- Added the foundation permitting to get rid of the content
of a global table, thus making it safer to place new data in it.

I'll use that in the next commits.