🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

gracefully handling lua foulness..

Started by
22 comments, last by nekoflux 20 years, 4 months ago
Borundin, the link you pasted has code that works great. Although proimarily what im after is being able to trap lua errors from within a non-static context, so that I can access class member variables. But I''ll keep this in mind as a last resort in the event that I cannot trap lua errors the way I want to.

Thanks again!

neko
nekoflux
Advertisement
quote: Original post by nekoflux
now, in the above code, why isnt it firing the catch block? init.lua clearly contains code that is not of proper syntax...

thanks for your patience!

neko

Once again: LuaBind raises exceptions for _RUNTIME ERRORS_. Not syntax errors from loading. You''ll need to actually check the return value of lua_load; simply try/catching won''t work.

"Sneftel is correct, if rather vulgar." --Flarelocke
The following code is based on something Sneftel (? I think) wrote a while ago in this forum, and on the code from lua_dofile. It gets rid of the need to use stderr or stdout at all by converting errors in loading the script file into exceptions you can catch with C++. AFAIK all the luabind exceptions inherit from std::runtime_error.

If this doesn't fix your problem, make sure that it's not something to do with a luabind object's destructor being called after you call lua_Close.

void ScriptEngine::doFile(const std::string& filename){    if(luaL_loadfile(L_, filename.c_str()) != 0)    {        std::string errmsg = "Unknown loading error";        if(lua_isstring(L_,-1))        {            errmsg = lua_tostring( L_, -1 );        }        throw std::runtime_error(errmsg);    }    if(lua_pcall(L_, 0, LUA_MULTRET, 0) != 0)    {        std::string errmsg = "Unknown call message";        if(lua_isstring(L_,-1))        {            errmsg = lua_tostring( L_, -1 );        }        throw std::runtime_error(errmsg);    }} 


[edit]fixed source tags[/edit]

[edited by - XXX_Andrew_XXX on March 3, 2004 2:11:23 AM]
Works great, thanks Andrew!

thanks again for the help guys, I''m back on track

neko
nekoflux

This topic is closed to new replies.

Advertisement