Lua错误处理如何通过长尾词优化?

2026-04-01 19:321阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计206个文字,预计阅读时间需要1分钟。

Lua错误处理如何通过长尾词优化?

我尝试了使用Lua的新手教程,访问了http://keplerproject.github.io/luafilesystem/examples.,但遇到了无法访问的目录并引发了开发错误。这似乎是由于luaL_error导致的。

我是lua的新手.

我试过用
keplerproject.github.io/luafilesystem/examples.html
并且它在无法访问的目录上引发错误.

这似乎是由luaL_error github.com/keplerproject/luafilesystem/blob/master/src/lfs.c#L563引起的

我怎么能抓到这个错误?
www.tutorialspoint.com/lua/lua_error_handling.htm
建议pcall,但这不会阻止脚本死亡:

pcall(lfs.dir('/etc/passwd')) #this fails to handle the not a directory error pcall(lfs.dir(‘/ etc / passwd’))失败,因为错误是在pcall之外触发的(当计算pcall的参数时).你需要使用

local ok, res = pcall(lfs.dir, '/etc/passwd')

请注意,传递给lfs.dir的参数是给pcall的,而不是lfs.dir.

Lua错误处理如何通过长尾词优化?

本文共计206个文字,预计阅读时间需要1分钟。

Lua错误处理如何通过长尾词优化?

我尝试了使用Lua的新手教程,访问了http://keplerproject.github.io/luafilesystem/examples.,但遇到了无法访问的目录并引发了开发错误。这似乎是由于luaL_error导致的。

我是lua的新手.

我试过用
keplerproject.github.io/luafilesystem/examples.html
并且它在无法访问的目录上引发错误.

这似乎是由luaL_error github.com/keplerproject/luafilesystem/blob/master/src/lfs.c#L563引起的

我怎么能抓到这个错误?
www.tutorialspoint.com/lua/lua_error_handling.htm
建议pcall,但这不会阻止脚本死亡:

pcall(lfs.dir('/etc/passwd')) #this fails to handle the not a directory error pcall(lfs.dir(‘/ etc / passwd’))失败,因为错误是在pcall之外触发的(当计算pcall的参数时).你需要使用

local ok, res = pcall(lfs.dir, '/etc/passwd')

请注意,传递给lfs.dir的参数是给pcall的,而不是lfs.dir.

Lua错误处理如何通过长尾词优化?