/** @file stackcheck.h
*	Header file for a lua stack verification utility
*	@author Nick Beatty (nbeatty@ea.com), Chris Burns (cburns@ea.com)
*
*	UX
*	(c) 2012 Electronic Arts Inc.
*/

#ifndef EABASETYPESLUA_STACKCHECK_H
#define EABASETYPESLUA_STACKCHECK_H

extern "C" 
{
	struct lua_State;
}

namespace EA
{
	namespace Lua
	{
		/*! @class StackCheck stackcheck.h	"ux_lua/stackcheck.h"
		*	@brief helper util for lua stack verification. Caches the state of the lua stack on creation
		*	and verifies that the stack has the appropriate size on destruction.
		*/
		class StackCheck
		{
		public:
			/*!
			*	Constructor for StackCheck object
			*	@param[in]	L			lua state you want to track
			*	@param[optional]	exitStackDelta		expected delta of lua stack size, default is 0
			*/
			StackCheck(lua_State* L, int exitStackDelta = 0);
			~StackCheck();

			/*!
			*	Allows the user to change the expected stack delta after creation of this object. 
			*	Useful for functions with conditions that change the stacks expected exit state 
			*	@param[in]	exitStackDelta		expected delta of lua stack size
			*/
			void SetExitStackDelta(int exitStackDelta);

			/*!
			*	Check the current stack state, fails if the current stack size does not equal the expected size.
			*	This function is automatically called during destruction of the object however users can choose to call at anytime for debugging purposes.
			*	@return	bool true if the stack is the correct size, false otherwise
			*/
			bool CheckStack();
		private:
			lua_State*	mL;
			int			mEntryStackCount;
			int			mExitStackDelta;
		};
	}
}

#endif /* EABASETYPESLUA_STACKCHECK_H */
