【问题标题】:ZeroBrane with Lua 5.4ZeroBrane 与 Lua 5.4
【发布时间】:2020-11-30 00:21:09
【问题描述】:

ZeroBrane Studio 最新版本 1.9 中,如果我们选择菜单选项“项目”,“Lua 解释器”,则只有 1.3 以上的版本。

如何添加 5.4 ?另外,安装 lua 5.4 和 5.4 库 iuplua 的步骤是什么? luarocks 不包括它。

提前致谢,

罗杰

【问题讨论】:

    标签: lua zerobrane


    【解决方案1】:

    文档表明已经安装了 5.4,但对于最近的 Windows 版本似乎并非如此。

    查看 ZeroBrane 目录。有一个文件夹解释器,其中包含一些 Lua 文件。添加另一个解释器看起来很简单。

    只需从 5.3 解释器配置中派生它并尝试一下。看起来它完成了所有路径的事情。

    luadeb53.lua:

    dofile 'interpreters/luabase.lua'
    local interpreter = MakeLuaInterpreter(5.3, ' 5.3')
    interpreter.skipcompile = true
    return interpreter
    

    所以我会添加一个 luadeb54.lua 并将版本号更改为 5.4。

    由于文件引用了interpreters/luabase.lua,打开它看看:

    function MakeLuaInterpreter(version, name)
    
    local function exePath(self, version)
      local version = tostring(version or ""):gsub('%.','')
      local mainpath = ide:GetRootPath()
      local macExe = mainpath..([[bin/lua.app/Contents/MacOS/lua%s]]):format(version)
      return (ide.config.path['lua'..version]
        or (ide.osname == "Windows" and mainpath..([[bin\lua%s.exe]]):format(version))
        or (ide.osname == "Unix" and mainpath..([[bin/linux/%s/lua%s]]):format(ide.osarch, version))
        or (wx.wxFileExists(macExe) and macExe or mainpath..([[bin/lua%s]]):format(version))),
      ide.config.path['lua'..version] ~= nil
    end
    
    return {
      name = ("Lua%s"):format(name or version or ""),
      description = ("Lua%s interpreter with debugger"):format(name or version or ""),
      api = {"baselib"},
      luaversion = version or '5.1',
      fexepath = exePath,
      frun = function(self,wfilename,rundebug)
        local exe, iscustom = self:fexepath(version or "")
        local filepath = ide:GetShortFilePath(wfilename:GetFullPath())
    
        if rundebug then
          ide:GetDebugger():SetOptions({runstart = ide.config.debugger.runonstart == true})
    
          -- update arg to point to the proper file
          rundebug = ('if arg then arg[0] = [[%s]] end '):format(wfilename:GetFullPath())..rundebug
    
          local tmpfile = wx.wxFileName()
          tmpfile:AssignTempFileName(".")
          filepath = ide:GetShortFilePath(tmpfile:GetFullPath())
    
          local ok, err = FileWrite(filepath, rundebug)
          if not ok then
            ide:Print(("Can't open temporary file '%s' for writing: %s."):format(filepath, err))
            return
          end
        end
        local params = self:GetCommandLineArg("lua")
        local code = ([[-e "io.stdout:setvbuf('no')" "%s"]]):format(filepath)
        local cmd = '"'..exe..'" '..code..(params and " "..params or "")
    
        -- modify LUA_CPATH and LUA_PATH to work with other Lua versions
        local envcpath = "LUA_CPATH"
        local envlpath = "LUA_PATH"
        if version then
          local env = "PATH_"..string.gsub(version, '%.', '_')
          if os.getenv("LUA_C"..env) then envcpath = "LUA_C"..env end
          if os.getenv("LUA_"..env) then envlpath = "LUA_"..env end
        end
    
        local cpath = os.getenv(envcpath)
        if rundebug and cpath and not iscustom then
          -- prepend osclibs as the libraries may be needed for debugging,
          -- but only if no path.lua is set as it may conflict with system libs
          wx.wxSetEnv(envcpath, ide.osclibs..';'..cpath)
        end
        if version and cpath then
          -- adjust references to /clibs/ folders to point to version-specific ones
          local cpath = os.getenv(envcpath)
          local clibs = string.format('/clibs%s/', version):gsub('%.','')
          if not cpath:find(clibs, 1, true) then cpath = cpath:gsub('/clibs/', clibs) end
          wx.wxSetEnv(envcpath, cpath)
        end
    
        local lpath = version and (not iscustom) and os.getenv(envlpath)
        if lpath then
          -- add oslibs libraries when LUA_PATH_5_x variables are set to allow debugging to work
          wx.wxSetEnv(envlpath, lpath..';'..ide.oslibs)
        end
    
        -- CommandLineRun(cmd,wdir,tooutput,nohide,stringcallback,uid,endcallback)
        local pid = CommandLineRun(cmd,self:fworkdir(wfilename),true,false,nil,nil,
          function() if rundebug then wx.wxRemoveFile(filepath) end end)
    
        if (rundebug or version) and cpath then wx.wxSetEnv(envcpath, cpath) end
        if lpath then wx.wxSetEnv(envlpath, lpath) end
        return pid
      end,
      hasdebugger = true,
      scratchextloop = false,
      unhideanywindow = true,
      takeparameters = true,
    }
    
    end
    
    return nil -- as this is not a real interpreter
    

    检查 /bin 文件夹,您会找到 Lua 可执行文件。添加 5.4 东西

    【讨论】:

    • 这是正确的;您可以按照@Piglet 的建议添加一个新的解释器,但您必须为 5.4 生成二进制文件和 luasocket 库。我已经在处理这个问题了,如果你想查看何时推送更改,可以关注 opened a ticket
    • @Piglet 非常感谢,我会尽快尝试。
    猜你喜欢
    • 2021-09-04
    • 2020-12-27
    • 2021-03-25
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 2021-08-17
    • 1970-01-01
    相关资源
    最近更新 更多