bug 474817: Allow it to attempt to run with unsupported Lua versions
diff --git a/libraries/luadbgpclient/debugger/context.lua b/libraries/luadbgpclient/debugger/context.lua
index d345c92..e1506ae 100644
--- a/libraries/luadbgpclient/debugger/context.lua
+++ b/libraries/luadbgpclient/debugger/context.lua
@@ -20,9 +20,9 @@
 local LOCAL, UPVAL, GLOBAL, EVAL, STORE, HANDLE = {}, {}, {}, {}, {}, {}
 
 local getglobals
-if _VERSION == "Lua 5.1" then
+if DBGP_CLIENT_LUA_VERSION == "Lua 5.1" then
   getglobals = function(f) return getfenv(f) end
-elseif _VERSION == "Lua 5.2" then
+elseif DBGP_CLIENT_LUA_VERSION == "Lua 5.2" then
   getglobals = function(f, cxt)
     -- 'global' environment: this is either the local _ENV or upvalue _ENV. A special case happen when a
     -- function does not reference any global variable: the upvalue _ENV may not exist at all. In this case,
diff --git a/libraries/luadbgpclient/debugger/init.lua b/libraries/luadbgpclient/debugger/init.lua
index 284d5e7..259d5e3 100644
--- a/libraries/luadbgpclient/debugger/init.lua
+++ b/libraries/luadbgpclient/debugger/init.lua
@@ -10,6 +10,11 @@
 -------------------------------------------------------------------------------
 
 local DBGP_CLIENT_VERSION = "1.4.0"
+DBGP_CLIENT_LUA_VERSION = os.getenv "LUA_VERSION" or _VERSION
+if DBGP_CLIENT_LUA_VERSION ~= "Lua 5.1" and DBGP_CLIENT_LUA_VERSION ~= "Lua 5.2" then
+  print(DBGP_CLIENT_LUA_VERSION .. " is not supported. As fallback, debugger will behave as if it runs on Lua 5.2 vm. You could also try to force it to behave as a Lua 5.1 vm by setting the LUA_VERSION environment variable to 'Lua 5.1'")
+  DBGP_CLIENT_LUA_VERSION = "Lua 5.2"
+end
 
 local debug = require "debug"
 
@@ -45,14 +50,14 @@
 
 -- "BEGIN VERSION DEPENDENT CODE"
 local setbpenv     -- set environment of a breakpoint (compiled function)
-if _VERSION == "Lua 5.1" then
+if DBGP_CLIENT_LUA_VERSION == "Lua 5.1" then
   local setfenv = setfenv
   setbpenv = setfenv
-elseif _VERSION == "Lua 5.2" then
+elseif DBGP_CLIENT_LUA_VERSION == "Lua 5.2" then
   local setupvalue = debug.setupvalue
   -- _ENV is the first upvalue
   setbpenv = function(f, t) return setupvalue(f, 1, t) end
-else error(_VERSION .. "is not supported.") end
+end
 -- "END VERSION DEPENDENT CODE"
 
 -------------------------------------------------------------------------------
diff --git a/libraries/luadbgpclient/debugger/transport/luasocket.lua b/libraries/luadbgpclient/debugger/transport/luasocket.lua
index cd589fa..6f23504 100644
--- a/libraries/luadbgpclient/debugger/transport/luasocket.lua
+++ b/libraries/luadbgpclient/debugger/transport/luasocket.lua
@@ -15,7 +15,7 @@
 -- directly (to no add yet another layer)
 
 --FIXME: remove this hack as soon as luasocket officially support 5.2
-if _VERSION == "Lua 5.2" then
+if DBGP_CLIENT_LUA_VERSION == "Lua 5.2" then
   table.getn = function(t) return t and #t end
 end
 
diff --git a/libraries/luadbgpclient/debugger/util.lua b/libraries/luadbgpclient/debugger/util.lua
index 09d3056..21f0c55 100644
--- a/libraries/luadbgpclient/debugger/util.lua
+++ b/libraries/luadbgpclient/debugger/util.lua
@@ -89,7 +89,7 @@
 
 
 -- Some version dependant functions
-if _VERSION == "Lua 5.1" then
+if DBGP_CLIENT_LUA_VERSION == "Lua 5.1" then
   local loadstring, getfenv, setfenv, debug_getinfo, MainThread =
     loadstring, getfenv, setfenv, debug.getinfo, nil
 
@@ -153,7 +153,7 @@
     __index = function(self, func) return getfenv(func) end,
     __newindex = function(self, func, env) return setfenv(func, env) end,
   })
-elseif _VERSION == "Lua 5.2" then
+elseif DBGP_CLIENT_LUA_VERSION == "Lua 5.2" then
   local load, debug_getinfo = load, debug.getinfo
   function M.getinfo(coro, level, what)
     if coro then return debug_getinfo(coro, level, what)