hishamhm/lua-compat-5.2 — pull request #7 by JohnHind (2013-09-24 10:23:27+00:00)
Title: Alternative get/set user value implementation

How about this guys?

The idea is to use a specific empty table, stored in the registry under a light userdata key for guaranteed uniqueness, as the marker for 'nil' value. This allows `lua_setuservalue` and `lua_getuservalue` to handle `nil` correctly and is pretty efficient since the registry only needs to be consulted when `lua_getfenv` returns an empty table.

I also overlay `lua_newuserdata` using a macro so it does `lua_setuservalue` to `nil` after creating the userdata with the standard environment table, mimicking the 5.2 behavior automatically. Not sure if all compilers will handle this potentially recursive macro correctly though - it works fine in VS2010.