lua - LUA - ZeroBrane IDE:编译功能
问题描述
如果我在 ZeroBrane Studio 中使用“项目 - 编译 (F7)” - 究竟会发生什么?
是否会从我的 Lua 代码创建一个独立的 .exe?
如果是这样 - 在哪个目录中?我使用的是 Windows 10。(在文档中找不到任何信息)
解决方案
从我通过快速查看源代码看到的内容来看,它只是通过使用loadstring
编译文件来加载代码来检查代码是否有任何错误。没有输出文件,只有一些关于任何错误的文本输出。
但这只是一个假设。随意检查这是否实际上是单击该按钮时调用的函数。
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
推荐阅读
- c++ - 通过在 C++ 中重命名符号来减少二进制大小
- r - 从 sendCustomMessage() 在 htmlwidgets/plotly 对象中定义 hoverinfo
- rust - 是否有更简单的方法来获取 Actix-Web HTTP 标头的字符串值?
- javascript - 计时器未正常运行 - Javascript
- python - 有没有办法进行矩阵逐张量乘法?
- sql-server - SQL-计算一个项目使用多长时间的价格-每月价格、每周价格和每小时价格
- c - 由于 getchar 理解 c 循环
- visual-studio-code - 注释空行
- perl - 如何在有向图中找到从源到汇的所有路径?
- encryption - 在 JavaScript 中为 RSA 生成非常大的素数