Jump to content
  • Advertisement
Sign in to follow this  
Exponent

Problems regarding catching lua errors

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I'm having some troubles catching lua syntax errors. When I call lua_dofile, I check if it's zero, if not then the error should be put on the stack. So I try something like:
AddLog((char*)lua_tostring(vm,-1)
lua_pop(vm,1)
However my log files always have (null) So I then try using the lua_getinfo function, however, what ever characters I put in for the "what" paramater, the debug table always gets filled with bogus values (null, some rubbish about tail_call, etc.) So, my question is, how do you catch syntax errors and report the message+line? Also, how do you catch errors related to calling functions or using variables which don't exist? Are line hooks the way to go? If so, what is the overhead for having some function being called on every line of execution? Sorry about the lengthy post, I appreciate the help!

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
look in the lua src file lauxlib.c

You will see that ultimately when do_file encounters an error it first checks to see if you have defined a global function called "_ALERT" within the lua_State. If so it calls that function with the error string as an arg, otherwise it prints the error string to stderr, in both cases it pops the error string from the stack.

For your example, I think your best bet is to not use lua_dofile, examine the src and you will see it is a very simple wrapper function anyways.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!