【问题标题】:LUA - ZeroBrane IDE: Compile featureLUA - ZeroBrane IDE:编译功能
【发布时间】:2020-12-27 17:07:34
【问题描述】:

如果我在 ZeroBrane Studio 中使用“项目 - 编译 (F7)” - 究竟会发生什么?
是否会从我的 Lua 代码创建一个独立的 .exe?
如果是这样 - 在哪个目录中? 我使用 Windows 10。 (在文档中找不到任何信息)

【问题讨论】:

  • 如果您在资源管理器中搜索项目的每个子目录,您会发现什么? “干净”项目与您构建的项目(使用“项目 - 编译”)有什么不同?
  • 我不确定我是否有一个项目的子目录....我有一个单独的 LUA 文件:...\ZeroBraneStudio\myprograms\test1.lua 如果我编译它它说:编译成功; 100% 成功率 (1/1)。所以编译成功了,但是结果呢?

标签: lua compilation zerobrane


【解决方案1】:

通过快速查看源代码,我看到它只是通过使用编译文件的loadstring 加载代码来检查代码是否有任何错误。 没有输出文件,只有一些关于任何错误的文本输出。

但这只是一个假设。请随意检查这是否真的是您单击该按钮时调用的函数。

https://github.com/pkulchenko/ZeroBraneStudio/blob/5daf55d79449431ca9794f6b8a65476dc203b780/src/editor

function CompileProgram(editor, params)
  local params = {
    jumponerror = (params or {}).jumponerror ~= false,
    reportstats = (params or {}).reportstats ~= false,
    keepoutput = (params or {}).keepoutput,
  }
  local doc = ide:GetDocument(editor)
  local filePath = doc:GetFilePath() or doc:GetFileName()
  local loadstring = loadstring or load
  local func, err = loadstring(StripShebang(editor:GetTextDyn()), '@'..filePath)
  local line = not func and tonumber(err:match(":(%d+)%s*:")) or nil

  if not params.keepoutput then ClearOutput() end

  compileTotal = compileTotal + 1
  if func then
    compileOk = compileOk + 1
    if params.reportstats then
      ide:Print(TR("Compilation successful; %.0f%% success rate (%d/%d).")
        :format(compileOk/compileTotal*100, compileOk, compileTotal))
    end
  else
    ide:GetOutput():Activate()
    ide:Print(TR("Compilation error").." "..TR("on line %d"):format(line)..":")
    ide:Print((err:gsub("\n$", "")))
    -- check for escapes invalid in LuaJIT/Lua 5.2 that are allowed in Lua 5.1
    if err:find('invalid escape sequence') then
      local s = editor:GetLineDyn(line-1)
      local cleaned = s
        :gsub('\\[abfnrtv\\"\']', '  ')
        :gsub('(\\x[0-9a-fA-F][0-9a-fA-F])', function(s) return string.rep(' ', #s) end)
        :gsub('(\\%d%d?%d?)', function(s) return string.rep(' ', #s) end)
        :gsub('(\\z%s*)', function(s) return string.rep(' ', #s) end)
      local invalid = cleaned:find("\\")
      if invalid then
        ide:Print(TR("Consider removing backslash from escape sequence '%s'.")
          :format(s:sub(invalid,invalid+1)))
      end
    end
    if line and params.jumponerror and line-1 ~= editor:GetCurrentLine() then
      editor:GotoLine(line-1)
    end
  end

  return func ~= nil -- return true if it compiled ok
end

【讨论】:

猜你喜欢
  • 2018-04-26
  • 2018-06-25
  • 2020-11-30
  • 2021-08-17
  • 2021-09-04
  • 1970-01-01
  • 1970-01-01
  • 2018-12-18
  • 2021-03-25
相关资源
最近更新 更多