aboutsummaryrefslogtreecommitdiff
path: root/compat53/module.lua
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-04-11 17:09:37 +0200
committerPhilipp Janda <siffiejoe@gmx.net>2015-04-11 17:09:37 +0200
commitddeb3f7a1e25667694eaf3c8bf639b66d6809cb4 (patch)
treea02b62ce9ad9135dd8dc6aab13940e96ea87dcfe /compat53/module.lua
parentba8686d6af119fc7ecf734a2d2b6e319c8d74df5 (diff)
downloadlua-compat-5.3-ddeb3f7a1e25667694eaf3c8bf639b66d6809cb4.tar.gz
lua-compat-5.3-ddeb3f7a1e25667694eaf3c8bf639b66d6809cb4.tar.bz2
lua-compat-5.3-ddeb3f7a1e25667694eaf3c8bf639b66d6809cb4.zip
split compat53 Lua module into separate modules that do/don't modify the global env
Diffstat (limited to 'compat53/module.lua')
-rw-r--r--compat53/module.lua37
1 files changed, 37 insertions, 0 deletions
diff --git a/compat53/module.lua b/compat53/module.lua
new file mode 100644
index 0000000..f6fd1f7
--- /dev/null
+++ b/compat53/module.lua
@@ -0,0 +1,37 @@
1local _G, _VERSION, debug, error, require, setfenv, setmetatable =
2 _G, _VERSION, debug, error, require, setfenv, setmetatable
3local lua_version = _VERSION:sub(-3)
4local M = require("compat53.base")
5
6local function findmain()
7 local i = 3
8 local info = debug.getinfo(i, "fS")
9 while info do
10 if info.what == "main" then
11 return info.func
12 end
13 i = i + 1
14 info = debug.getinfo(i, "fS")
15 end
16end
17
18local main = findmain()
19if not main then
20 error("must require 'compat53.module' from Lua")
21end
22local env = setmetatable({}, {
23 __index = M,
24 __newindex = _G,
25})
26if lua_version == "5.1" then
27 setfenv(main, env)
28elseif lua_version == "5.2" or lua_version == "5.3" then
29 debug.setupvalue(main, 1, env)
30else
31 error("unsupported Lua version")
32end
33
34-- return false to force reevaluation on next require
35return false
36
37-- vi: set expandtab softtabstop=3 shiftwidth=3 :