From 742b89b1895a091385dc47d410687bbb70f76dbd Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 19 Dec 2011 09:48:37 -0500 Subject: Added more LuaJIT compatibility functions; core/compat.lua --- core/compat.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'core/compat.lua') diff --git a/core/compat.lua b/core/compat.lua index 1bbf4a3b..953e06b4 100644 --- a/core/compat.lua +++ b/core/compat.lua @@ -17,3 +17,23 @@ function load(ld, source, mode, env) if f and env then return setfenv(f, env) end return f, err end + +-- In Lua 5.1, `loadfile` did not take mode and environment parameters. +local loadfile51 = loadfile +function loadfile(filename, mode, env) + local f, err = loadfile51(filename) + if f and env then return setfenv(f, env) end + return f, err +end + +-- TODO: string.rep +-- In Lua 5.1, `string.rep` did not take separation string parameter. + +-- In Lua 5.1, `os.execute` returned an integer depending on shell availability. +-- It also returned just a status code. +local os_execute51 = os.execute +function os.execute(command) + if not command then return os_execute51() ~= 0 end + local code = os_execute51(command) + return code == 0, 'exit', code +end -- cgit v1.2.3