简体   繁体   中英

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.
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. Otherwise, use lua_call and let the error move up the call chain. No need to get paranoid using lua_pcall everywhere.

lua_call is faster than lua_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.

Use lua_pcall in all situation unless you have some specific performance issues . Then use lua_call . But again, only if you have profiled your application and discovered a specific performance issue that lua_call will alleviate.

If a Lua error is thrown by Lua during a lua_call , your application is pretty much hosed. So you need to make sure that lua_pcall is used where possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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