lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I was asking for help on #lua today, and someone pointed out that my
stack debugging macro might be useful in the Lua Auxiliary API.

Here's the macro in case anyone is interested in using it.  It can be
called from any point in your code, providing you have access to the
lua_State*.

The macro shows you the value in the case of a string, number or boolean value.

#define showstack(lstack)	\
	for (int i=0;i<lua_gettop(lstack)+1;i+=1)\
	{\
		if (lua_isnumber(lstack,i))\
		{\
			cout << i << ": number : " << lua_tonumber(lstack,i) << endl;\
		}\
		else if (lua_isstring(lstack,i))\
		{\
			cout << i << ": string : " << lua_tostring(lstack,i) << endl;\
		}\
		else if (lua_istable(lstack,i))\
		{\
			cout << i << ": table" << endl;\
		}\
		else if (lua_iscfunction(lstack,i))\
		{\
			cout << i << ": cfunction" << endl;\
		}\
		else if (lua_isfunction(lstack,i))\
		{\
			cout << i << ": function" << endl;\
		}\
		else if (lua_isboolean(lstack,i))\
		{\
			if (lua_toboolean(lstack,i)==true)\
				cout << i << ": boolean : true" << endl;\
			else\
				cout << i << ": boolean : false" << endl;\
		}\
		else if (lua_isuserdata(lstack,i))\
		{\
			cout << i << ": userdata" << endl;\
		}\
		else if (lua_isnil(lstack,i))\
		{\
			cout << i << ": nil" << endl;\
		}\
		else if (lua_islightuserdata(lstack,i))\
		{\
			cout << i << ": light userdata" << endl;\
		}\
	}

Regards, James.