c++ - Descriptive Error Messages for Lua Syntax Errors -


i have lua interpreter whenever make syntax error in code, error message returned attempted call string value, instead of meaningful error message. example if run lua code:

for a= 1,10    print(a) end 

instead of returning meaningful 'do' expected near 'print' , line number return error attempted call string value.

my c++ code following:

void luainterpreter::run(std::string script) {     lual_openlibs(m_mainstate);      // adds functions calling in lua code     addfunctions(m_mainstate);      // loading script string lua     lual_loadstring(m_mainstate, script.c_str());      // calls script     int error =lua_pcall(m_mainstate, 0, 0, 0);     if (error) {         std::cout << lua_tostring(m_mainstate, -1) << std::endl;         lua_pop(m_mainstate, 1);     } } 

thanks in advance!

your problem lual_loadstring fails load string, since not valid lua code. never bother check return value find out. , therefore, wind trying execute compile error pushed onto stack though valid lua function.

the correct way use function follows:

auto error = lual_loadstring(m_mainstate, script.c_str()); if(error) {     std::cout << lua_tostring(m_mainstate, -1) << std::endl;     lua_pop(m_mainstate, 1);     return; //perhaps throw or signal error? } 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -