您能告诉我这段代码有什么问题吗?

以下是我在 SCIte 中编写的 Lua 代码,我不确定其中有什么问题,所以请问有人能解释一下我哪里出错以及如何修复吗?

t = setmetatable({},{
__newindex = function(t, key)
if key == false then
  return( "False cannot exist in table")
  key = nil
  end
if key == __string then
  table.concat[table, key]
else
  table[key] = nil
  end
if key == nil then
  return  "Tables in this file cannot contain false values."
end
}
)

function Error()
  _,cError = pcall(__index)
end
function Call1()
  error("error in metatable function, '__index'", 1)
end
function Call2()
  Call1()
end

Error()

Call2()
点赞
用户2303714
用户2303714

将下面翻译成中文并且保留原本的 markdown 格式

有很多问题,以至于几乎不可能进行修复。不过这些修复可能会帮到你,我已经根据你之前的函数进行了修复。在尝试使用元表创建类之前,建议你更多地学习该语言。

t = setmetatable({},{
    __newindex = function(t, key)
        if key == false then
          return( "False cannot exist in table") -- return values in this function don't make sense
          --key = nil THIS WILL NEVER BE REACHER
        end
        if type(key) == "string" then --check key is a string
          table[key] = {}
        else
          table[key] = nil
        end
        if key == nil then
          return  "Tables in this file cannot contain false values."
        end
    end
    }
)

此外,

function Call1()
  error("error in metatable function, '__index'", 1)
end

是毫无意义的,因为它总是会输出一个错误,即:

error("No error here")

会产生以下输出:

lua: ex.lua:26: No error here
2013-05-16 03:30:26