How to decide to use lua_call () or lua_pcall ()?

I know the main difference between lua_call() or lua_pcall() , and later is more error details.
Is there any other difference? How to decide what to use?

+6
source share
2 answers

Use lua_pcall when you need to handle potential errors at this 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 faster than lua_pcall .

Just make sure there is at least one lua_pcall at the top, or your application will panic and exit if any Lua errors are detected.

+5
source

Use lua_pcall in all situations if you have some specific performance issues . Then use lua_call . But then again, only if you have profiled your application and found a specific performance problem that lua_call will facilitate.

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

+5
source

Source: https://habr.com/ru/post/945582/


All Articles