类型 函数 库 (全局) 修订 版本 2024.3703 关键词 assert,错误 另请参阅 error()
当其第一个参数的值为 false
(nil
或 false
)时,发出错误并中止程序。
此函数对于捕获(并避免)意外情况和错误非常有用。
assert( v [, message] )
任意。 当此值为 false 时发出错误。
字符串。 错误消息。 缺省情况下,它默认为“断言失败!”。 错误消息将显示在 Corona Simulator 控制台中。
-- Abort the program if the image is not found (in the Resource directory) local img = display.newImage( "imageWithWrongName.png" ) assert( img, "Error: Image not found!" )