简体   繁体   English

如何决定使用lua_call()还是lua_pcall()?

[英]How to decide using lua_call() or lua_pcall()?

I know the basic difference between lua_call() or lua_pcall() , the later one provides more error details. 我知道lua_call()lua_pcall()之间的基本区别, lua_call()提供了更多的错误细节。
Is there any other difference? 还有其他区别吗? How to decide which to use? 如何决定使用哪个?

Use lua_pcall when you need to handle potential errors at that point in the code. 当您需要在代码中处理潜在错误时,请使用lua_pcall Otherwise, use lua_call and let the error move up the call chain. 否则,使用lua_call并让错误向上移动调用链。 No need to get paranoid using lua_pcall everywhere. 无需在任何地方使用lua_pcall变得偏执狂。

lua_call is faster than lua_pcall . lua_calllua_pcall快。

Just make sure there is at least one lua_pcall at the top or your app will panic and exit when finding any Lua errors. 只需确保顶部至少有一个lua_pcall ,否则您的应用会发现任何Lua错误时会发生恐慌并退出。

Use lua_pcall in all situation unless you have some specific performance issues . 除非您遇到一些特定的性能问题,否则请在所有情况下使用lua_pcall Then use lua_call . 然后使用lua_call But again, only if you have profiled your application and discovered a specific performance issue that lua_call will alleviate. 但同样,只有您已经分析了您的应用程序并发现了lua_call将减轻的特定性能问题。

If a Lua error is thrown by Lua during a lua_call , your application is pretty much hosed. 如果Lua在lua_call期间抛出了Lua错误,那么你的应用程序几乎已被lua_call So you need to make sure that lua_pcall is used where possible. 所以你需要确保尽可能使用lua_pcall

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM