From 43e45b145279946f01876efe36e0e7acad4ce8c3 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 11 Jan 2019 15:27:11 -0800 Subject: Tweaked code to use both _ENV and _G for better compatibility of precompiled Lua between Lua 5.2+ and LuaJIT --- bootstrap.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'bootstrap.lua') diff --git a/bootstrap.lua b/bootstrap.lua index 844bcca..10d6f3b 100644 --- a/bootstrap.lua +++ b/bootstrap.lua @@ -38,7 +38,6 @@ compile_error = function(source, err_msg, hint) return error(err_str, 0) end local MAX_LINE = 80 -local ENVNAME = jit and "_G" or "_ENV" local compile_actions = { [""] = function(self, fn, ...) local lua = LuaCode() @@ -118,16 +117,16 @@ local compile_actions = { })) end, ["1 as lua"] = function(self, code) - return LuaCode(tostring(ENVNAME) .. ":compile(", self:compile(code), ")") + return LuaCode("_ENV:compile(", self:compile(code), ")") end, ["use"] = function(self, path) - return LuaCode(tostring(ENVNAME) .. ":use(" .. tostring(self:compile(path)) .. ")") + return LuaCode("_ENV:use(" .. tostring(self:compile(path)) .. ")") end, ["export"] = function(self, path) - return LuaCode(tostring(ENVNAME) .. ":export(" .. tostring(self:compile(path)) .. ")") + return LuaCode("_ENV:export(" .. tostring(self:compile(path)) .. ")") end, ["run"] = function(self, path) - return LuaCode(tostring(ENVNAME) .. ":run(" .. tostring(self:compile(path)) .. ")") + return LuaCode("_ENV:run(" .. tostring(self:compile(path)) .. ")") end, ["test"] = function(self, body) if not (body.type == 'Block') then @@ -154,10 +153,10 @@ local compile_actions = { return LuaCode("_VERSION") end, ["nomsu environment"] = function(self) - return LuaCode(ENVNAME) + return LuaCode("_ENV") end, ["nomsu environment name"] = function(self) - return LuaCode(ENVNAME:as_lua()) + return LuaCode('"_ENV"') end } return compile_actions -- cgit v1.2.3