Advertisement Jump to content
Sign in to follow this  

Problems regarding catching lua errors

This topic is 4901 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:
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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!