ルアで困っています。
問題 1: 次のプログラムを実行するたびに、コンソールに次のように表示されます。
'end' が期待される (1 行目の 'function' を閉じるため) 'local' の近く
エラーに関するすべての大文字のコメントの詳細をマークした場所に注意してください
function m11()
local inst = mc.mcGetInstance() -- controller instance
local gcodeLineNbr = mc.mcCntlGetGcodeLineNbr(inst) -- get current Gcode line number
local gcodeLineStr = mc.mcCntlGetGcodeLine(inst, gcodeLineNbr) -- get current Gcode line
function valFromLine(string, axis)
local startPoint = string.find(string, axis) + 1
local outputVal = ""
local isNum = true
while isNum do
local num = string.sub(string, startPoint, startPoint)
startPoint = startPoint + 1
if num ~= " " then
outputVal = outputVal .. num
else
isNum = false
end
end
outputVal = tonumber(outputVal)
end
return outputVal
--COMPILER HIGHLIGHTS FOLLOWING LINE AS LOCATION OF ERROR
local gcodeLocX = valFromLine(gcodeLineStr, "X")
local curLocX = mc.mcAxisGetPos(inst, 0) -- get current X axis value
local curLocY = mc.mcAxisGetPos(inst, 1) -- get current Y axis value
local curLocZ = mc.mcAxisGetPos(inst, 2) -- get current Z axis value
local curAngB = mc.mcAxisGetPos(inst, 4) -- get current C axis value
local curAngC = mc.mcAxisGetPos(inst, 5) -- get current C axis value
local toolOffset = mc.mcCntlGetToolOffset(inst, 2) -- get tool offset for axis Z
function rotateToolB()
local comHypot = toolOffset * math.sin(angle) -- get XY planar dist from C pivot to tool centre point
local compDestinX = comHypot * math.sin(math.rad(90) - curAxisC + curLocX
end
end
--END OF M11() FUNCTION SHOULD BE HERE
if (mc.mcInEditor() == 1) then
m11()
end
m11() がこんなに早く閉じると予想される理由がわかりません。
問題 2: valFromLine() を完全に別のファイルに書き直したところ、次のようになりました。
'print' の近くに 'eof' が必要です
function valFromLine(string, axis)
local startPoint = string.find(string, axis) + 1
local outputVal = ""
local isNum = true
while isNum do
local num = string.sub(string, startPoint, startPoint)
startPoint = startPoint + 1
if num ~= " " then
outputVal = outputVal .. num
else
isNum = false
end
end
outputVal = tonumber(outputVal)
end
return outputVal
print(valFromLine("GO1 X254.348 Y1039.456 Z150.13 B90.23 C13 M11", "X"))
「end」ステートメントを数えましたが、どちらのコード例でも何が問題なのかわかりません。この時点でアイデアが完全に失われています。助けてください。ありがとう。