Sign in to follow this  
Elspin

Lua debugging?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this