だからここに私が書いたいくつかのコードがあります:
local fileFunc = {createFolder, openObj, deleteObj, createTxt, theMenu}
setmetatable(fileFunc, mt)
function fileSys()
local fileAction, code
print("The File System")
print("You are currently at "..current_window)
while true do
print("1 Create a new Folder\n2 Open an object\n3 Delete an Object\n4 Create a new text file\n5 Other options")
fileAction = userInInt()
code = fileFunc[fileAction]()
if code > 3 then invRet("fileSys()", code) end
if code == 1 then return 0
else return code end
end
end
メタメソッドを使えばエラーにはならないと思っていたの__index
ですが、それでもattempt to call field ?
エラーが発生します。それでもエラーがスローされると推測しているので、使用してキャッチできる方法はありますかpcall()
mt
次のようになります。
local mt = { __index = invalid }
そして無効:
function invalid()
print("Invalid operand, please try again.")
end
このエラーは、表に記載されていないオペランドをユーザーが入力した場合にのみスローされます ( input > #fileFunc
) 。