Jump to content
  • Advertisement
Sign in to follow this  
Elspin

Lua debugging?

This topic is 3917 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

Been searching for a while to find a way to debug lua, but coming up blank. At the moment, this is my debugging.
void RunErrorLua(lua_State* luaVM, const char* filelocation)
{
	int ret = luaL_dofile(luaVM, filelocation);
	
	
	if (ret != 0)
	{
		MessageBox(NULL, (LPCSTR) filelocation, (LPCSTR) "Lua System Error, File:",
        MB_ICONERROR | MB_OK);
	}
	
}

As you can probably guess, it's about as useless as debugging can get. Knowing that there's something wrong with a lua file doesn't tell me what's wrong, even worse it could be on the lua end or the C++ end, who knows. I'd appreciate it if anyone could tell me how I can run lua files with some form of debugging.

Share this post


Link to post
Share on other sites
Advertisement
I'm sure there are even better methods, but:

Lua calls a function on a error, in the last version i use it's call _ALERT. The function gets passed a string describing that error.

Simply override the Lua function _ALERT and output the string somewhere useful.

I think the name of that function has been changed in the latests versions, you may need to consult the manual if it has.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
I'm sure there are even better methods, but:

Lua calls a function on a error, in the last version i use it's call _ALERT. The function gets passed a string describing that error.

Simply override the Lua function _ALERT and output the string somewhere useful.

I think the name of that function has been changed in the latests versions, you may need to consult the manual if it has.


Hmm, I can't seem to find any mention of it in lua 5.1, no mention of a replacement function or such.

Share this post


Link to post
Share on other sites
Hi,

the documentation of lua5.1 says that luaL_dofile is defined as
 (luaL_loadfile(L, filename) || lua_pcall(L, 0, LUA_MULTRET, 0)) 


And lua_pcall pushes an error string on top of the stack. It can be easily retrieved with lua_tostring(luaVM,-1). This you can incorporate into your MsgBox.

And just check out the documentation on lua_pcall because you can push a error function on the stack which gets called if an error occured. It's useful to e.g. dump the current stack or whatever you want.

Hope I could help you :)

Share this post


Link to post
Share on other sites
Quote:
Original post by kohma
Hi,

the documentation of lua5.1 says that luaL_dofile is defined as
*** Source Snippet Removed ***

And lua_pcall pushes an error string on top of the stack. It can be easily retrieved with lua_tostring(luaVM,-1). This you can incorporate into your MsgBox.

And just check out the documentation on lua_pcall because you can push a error function on the stack which gets called if an error occured. It's useful to e.g. dump the current stack or whatever you want.

Hope I could help you :)


Thank you, I appreciate the help :)

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!