Fix bug in cast graph cache

This patch fixes a bug in the cast graph cache in Luabind 0.9.1. The
problem did not manifest itself in earlier versions, but only became
apparent with Luabind commit 8e9bb9c7, which fixed a different cast
cache bug.

When a cast from a Lua value to a C++ object fails due to mismatching
types, e.g. upon function overload resolution, or explicit object_cast,
Luabind stores a bogus entry in the cast graph cache. A second cast to
the same C++ type will then erroneously yield a successful cast despite
the mismatching types. This results in e.g. ambiguous overload errors
for overloaded functions despite non-ambiguity, or segmentation faults
due to access of a C++ object through a pointer with the wrong type.

The bug has first been discovered and fixed by Eduard Mueller:

http://old.nabble.com/inheritance-cast_graph-cache-bug-fix-p29936577.html

The above patch switches the arguments to store a correct cache entry
with offset equal to cache::invalid. The distance value is irrelevant,
as it is discarded in cast_graph::impl::cast(). Presumably the above
patch changes it from -1 to 0 to account for the std::size_t type used
in the signature of cache::put.

The patch below takes a different approach, as already suggested by the
author of the above patch. We swap the offset and distance arguments of
cache::put to match the order of the cache entry pair. Further, we
change the distance type in the cache::put signature from std::size_t
to int, to be consistent with the cache entry type. This inconsistency
stems from the changes in Luabind commit cf37774.

Note that under GNU/Linux, the cast graph cache bug manifests itself
on the x86 platform, but does not seem to affect Luabind on x86_64.
Lua 5.2: replace lua_equal and lua_lessthan with lua_compare

http://www.lua.org/manual/5.2/manual.html#8.3

http://www.lua.org/manual/5.2/manual.html#lua_compare
Lua 5.2: replace occurrences of deprecated LUA_GLOBALSINDEX

Use lua_getglobal and lua_setglobal to retrieve and set globals.

Use lua_rawgeti with LUA_RIDX_GLOBALS to retrieve table of globals.

http://www.lua.org/manual/5.2/manual.html#8.3

http://www.lua.org/manual/5.2/manual.html#4.5

This commit drops support for Lua 5.0, since Luabind is incompatible
with Lua 5.0 anyway, e.g. commit 7dc37f9 requires lua_Integer added
in Lua 5.1.
Lua 5.2: replace lua_strlen with lua_rawlen

lua_strlen was a macro for lua_objlen, which is superseded by lua_rawlen.

http://www.lua.org/manual/5.2/manual.html#8.3

This commit drops support for Lua 5.0, since Luabind is incompatible
with Lua 5.0 anyway, e.g. commit 7dc37f9 requires lua_Integer added
in Lua 5.1.
Lua 5.2: replace lua_[gs]etfenv with lua_[gs]etuservalue

http://www.lua.org/manual/5.2/manual.html#8.1
Lua 5.2: pass extra parameter NULL to lua_resume

http://www.lua.org/manual/5.2/manual.html#8.3

This commit drops support for Lua 5.0, since Luabind is incompatible
with Lua 5.0 anyway, e.g. commit 7dc37f9 requires lua_Integer added
in Lua 5.1.
Lua 5.2: replace lua_open with luaL_newstate

This commit drops support for Lua 5.0, since Luabind is incompatible
with Lua 5.0 anyway, e.g. commit 7dc37f9 requires lua_Integer added
in Lua 5.1.
Lua 5.2: fix test_free_functions unit test

The line triggering the error is truncated at a different position.
Lua 5.2: use new macro lua_pushglobaltable

This macro is not mentioned in the Lua 5.2 manual.
Merge branch '0.9' of https://github.com/luabind/luabind