//-------------------------------------------------------------------------------------------------
// <copyright file="LWInvokeLuaInternalCmd.h" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
//	Declarations for LWInvokeLuaInternalCmd, a delegate class that carries a script
//	method invocation is queued up on the lua instance specific thread.  When it runs,
//	invokes the appropriate script method.
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#ifndef __LWInvokeLuaInternalCmd_h__
#define __LWInvokeLuaInternalCmd_h__

#include "LWConcreteCmd.h"

namespace LiquidRobotics {

namespace SMACFramework {
	class CmdLineParser;
	class Logger;
	class LuaInstance;
}

namespace LuaWrapper {

class LWAsynchScriptContext;

class SHARED_LIB_PUBLIC LWInvokeLuaInternalCmd : public LWConcreteCmd
{
public:

	typedef LWConcreteCmd::CmdBasePtr CmdPtr;
	typedef LiquidRobotics::SMACFramework::Logger Logger;
	typedef LiquidRobotics::SMACFramework::LuaInstance LuaInstance;
	typedef LWControllerBase0::ParsingContext ParsingContext;
	typedef std::vector<string> StringArray;

	LWInvokeLuaInternalCmd(TCon& _ctrl, const string& _cmd, const string& _instanceName, const string& _functionName,
			const StringArray& _args, LWAsynchScriptContextLua* _pContext = NULL);
	virtual ~LWInvokeLuaInternalCmd();

	// this method is called by the background thread to execute the command
	virtual void Execute();

	// get the output of the command
	virtual string GetResult();

private:

	string RunCommand(LuaInstance& L);
	void SetContext(LuaInstance& L);

	LWControllerBase0& ctrl;
	string cmd;
	string instanceName;
	string functionName;
	StringArray args;
	string cmdResponse;
	LWAsynchScriptContextLua* pContext;
	bool contextInstalled;
};

}
}

#endif
