# 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.

## 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 on other sites
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.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 19
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633380
• Total Posts
3011578
• ### Who's Online (See full list)

There are no registered users currently online

×