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.moon | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'bootstrap.moon') diff --git a/bootstrap.moon b/bootstrap.moon index 66c8553..f5b5900 100644 --- a/bootstrap.moon +++ b/bootstrap.moon @@ -24,8 +24,6 @@ compile_error = (source, err_msg, hint=nil)-> error(err_str, 0) MAX_LINE = 80 -- For beautification purposes, try not to make lines much longer than this value ---ENVNAME = jit and "getfenv(1)" or "_ENV" -ENVNAME = jit and "_G" or "_ENV" compile_actions = { [""]: (fn, ...)=> lua = LuaCode! @@ -96,16 +94,16 @@ compile_actions = { @compile(SyntaxTree{type:"Action", "lua", ">", code}) ["1 as lua"]: (code)=> - LuaCode("#{ENVNAME}:compile(", @compile(code), ")") + LuaCode("_ENV:compile(", @compile(code), ")") ["use"]: (path)=> - LuaCode("#{ENVNAME}:use(#{@compile(path)})") + LuaCode("_ENV:use(#{@compile(path)})") ["export"]: (path)=> - LuaCode("#{ENVNAME}:export(#{@compile(path)})") + LuaCode("_ENV:export(#{@compile(path)})") ["run"]: (path)=> - LuaCode("#{ENVNAME}:run(#{@compile(path)})") + LuaCode("_ENV:run(#{@compile(path)})") ["test"]: (body)=> unless body.type == 'Block' @@ -118,8 +116,8 @@ compile_actions = { ["is jit"]: (code)=> LuaCode("jit") ["Lua version"]: (code)=> LuaCode("_VERSION") - ["nomsu environment"]: ()=> LuaCode(ENVNAME) - ["nomsu environment name"]: ()=> LuaCode(ENVNAME\as_lua!) + ["nomsu environment"]: ()=> LuaCode("_ENV") + ["nomsu environment name"]: ()=> LuaCode('"_ENV"') } return compile_actions -- cgit v1.2.3