#include "luanavtester.h"

#include "EABaseTypesLua/stackcheck.h"
#include "EABaseTypesLua/datautillua.h"
#include "EABaseTypesLua/EABaseTypesLua.h"
#include "EABaseTypes/datatypes.h"
#include "eaassert/eaassert.h"

extern "C" 
{
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
}    

namespace UX
{
	namespace LuaNavTester
	{
		void Run(lua_State* L,
				 EA::Types::FunctionIn callback,
				 const char* navTesterFileName,
				 const char* navDataFileName,
				 const char* navTestFileName)
		{
			EA::Lua::StackCheck s(L);

			if(0 != luaL_loadstring(L,
				"local callback, navTesterFileName, navDataFileName, navTestFileName = ...\n"
				"\n"
				"requireasync(\n"
				"	function(navtester, error)\n"
				"		assert(navtester, error)\n"
				"		local n = navtester:new()\n"
				"		n:run(callback, navDataFileName, navTestFileName)\n"
				"	end,\n"
				"	navTesterFileName)\n"
				))
			{
				EA_FAIL_MESSAGE(lua_tostring(L, -1));
			}

			EA::Lua::PushBaseType(L, callback);
			lua_pushstring(L, navTesterFileName);
			lua_pushstring(L, navDataFileName);
			lua_pushstring(L, navTestFileName);

			EA::Lua::Call(L, 4, 0);
		}
	}
}
