I am in a pure Lua 5.2 environment and I need to execute Lua 5.1 code. This code is arbitrary code from the user, so I can't port to Lua 5.2 in advance. As far as I can see, this would entail reimplementing getfenv/setfenv, changing the _VERSION string, hiding the global _ENV and reimplementing the removed deprecated features. Have I missed anything, or is there a better way to go about doing this? (I can only write code in pure Lua, and I need to be able to execute 5.1 code as this is meant to be a backwards-compatibility thing.)
Asked
Active
Viewed 841 times
3
-
This cannot be done directly if you insist in complete compatibility. For instance, the Lua 5.1 code might include a call to `load` with Lua 5.1 byte code. If you can do with less, see http://lua-users.org/wiki/LuaVersionCompatibility ; in particular, https://github.com/davidm/lua-compat-env. – lhf Aug 19 '14 at 18:11
-
@lhf I just want as much compatibility as I can possibly get. Thankfully, I'm in an environment wheee bytecode has been disables anyways for security reasons. EDIT: Thanks for the links. Extremely helpful. – programmedpixel Aug 19 '14 at 18:13
-
@lhf You should post those as an answer, as there simply isn't anything better that someone could come up with. – Llamageddon Jun 01 '15 at 11:17
1 Answers
0
This may be a hard to do in full generality, but there are partial solutions that may work for you.
For a compatibility layer, see lua-compat-env.
For further discussion and other solutions, see Lua Version Compatibility.

lhf
- 70,581
- 9
- 108
- 149