hishamhm/lua-compat-5.2 — pull request #8 by siffiejoe (2013-09-25 08:41:56+00:00)
Title: Modular compat52.mstrict module

This is just an early prototype and a request for comments!

The current `compat52.strict` module removes functions from the global table, and thus affects all Lua code in the same Lua state, even modules that handle compatibility themselves, and/or need access to Lua 5.1-only functions. That fact severely limits the opportunities where you can actually use `compat52.strict`.
This is an attempt to provide a strict Lua 5.2 environment only for those files that explicitly requested it. The following is the output of a typical test run:
```
mod	pcall(unpack,{1,2,3})	true	1	2	3
mod	pcall(math.log10,10)	true	1
main	pcall(unpack,{1,2,3})	false	This function is not available in Lua 5.2!
main	pcall(math.log10,10	false	This function is not available in Lua 5.2!
mod	pcall(unpack,{1,2,3})	true	1	2	3
mod	pcall(math.log10,10)	true	1
main	pcall(unpack,{1,2,3})	false	This function is not available in Lua 5.2!
main	without pcall:
/usr/bin/lua5.1: ./stest.lua:12: This function is not available in Lua 5.2!
stack traceback:
[C]: in function 'error'
./compat52/mstrict.lua:31: in function 'unpack'
./stest.lua:12: in main chunk
[C]: ?
```
Currently there are the following issues:
* You have to call the result of `require("compat52.mstrict")` => `require("compat52.mstrict")()`
* ATM I only pass globals from the strict environment to the normal global environment, but not the other way around. Some tables are shared, but some modifications to the normal _G would not be visible in the strict environment. One could probably fix that by using `__index`-functions and dispatch on the fly ...

Thoughts?