/** @file datautillua.cpp
 *  Some functionality to allow EA::Types values to be converted to and from LUA tables/values
 * 	@headerfile datautillua.h "EABaseTypesLua/datautillua.h"
 *	@author Chris Burns (cburns@ea.com)
 *
 *	UX
 *	(c) 2012 Electronic Arts Inc. 
 */

#include "EABaseTypes/basetypeencoder.h"
#include "EABaseTypesLua/luaencoder.h"

namespace EA
{
	namespace Lua
	{
		void PushBaseType(lua_State* L, EA::Types::BaseTypeIn baseType)
		{
			LuaEncoder encoder(L);

			EA::Types::BaseTypeDecoder<LuaEncoder>::Decode(&encoder, baseType.GetUnsafePointer());
		}

		EA::Types::BaseTypeReturn ToBaseType(lua_State* L, int index)
		{
			EA::Types::BaseTypeEncoder encoder(Lua::GetFactory(L));

			lua_pushvalue(L, index);

			LuaDecoderParams decoderParams(L, 1);
			LuaDecoder<EA::Types::BaseTypeEncoder>::Decode(&encoder, &decoderParams);

			lua_pop(L, 1);

			return encoder.AcquireRoot();
		}
	}
}
