c++ - Safely reading string from Lua stack -


How is it possible to read string values ​​safely from Lua Stack? Both the function lua_tostring and lua_tolstring can both increase a Lua error (longjmp / exception of a strange type). Therefore the function should probably be called in protected mode using lua_pcall , but I can not find a good solution how to do this and get string value from Lava stack to C ++. Really need to call lua_tolstring in safe mode using lua_pcall ? In fact it is bad to use lua_pcall because the string I want to read from the Lua Stack is an error message stored by lua_pcall .

Use lua_tostring before lua_type : If lua_type returns LUA_TSTRING , then you will not be allocated any more memory to get the lua_tostring string securely.

lua_tostring allocates only memory when it has to convert a number to a string.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -