/* * * * * * * * * * * * * * * * 
 * 	 ______     __  __     ______     __  __     ______     ______     __  __    
 *	/\  __ \   /\ \/\ \   /\  == \   /\ \_\ \   /\  __ \   /\  ___\   /\ \/ /    
 *	\ \ \/\ \  \ \ \_\ \  \ \  __<   \ \  __ \  \ \  __ \  \ \ \____  \ \  _"-.  
 *	 \ \_____\  \ \_____\  \ \_____\  \ \_\ \_\  \ \_\ \_\  \ \_____\  \ \_\ \_\ 
 *	  \/_____/   \/_____/   \/_____/   \/_/\/_/   \/_/\/_/   \/_____/   \/_/\/_/ 
 *
 *  - Version : 3L
 *  - By Oubliette
 * * * * * * * * * * * * * * * */

#include "oubhack.h"
#include "oubhack_menu_hook.h"

IMHook::IMHook( ){

	ILuaInterface* mLua = oubhack->GetLuaInterface( LUA_STATE_MENU );

	mLua->CreateTable();
	this->m_pMenuHooks = mLua->IGetObject();

	delete mLua;

}

void IMHook::Close(){

	this->m_pMenuHooks->UnReference();

}

void IMHook::SetHook( const char* ccName, ILuaObject* objFunc ){

	this->m_pMenuHooks->SetMember( ccName, objFunc );

}

ILuaObject* IMHook::GetHook( const char* ccName ){

	return this->m_pMenuHooks->GetMember( ccName );

}

bool IMHook::CallOnCCAdded( const char* ccName ){

	if ( !this->GetHook( "OnConsoleCommandAdded" )->isFunction() ) return false;

	this->GetHook( "OnConsoleCommandAdded" )->Push();

	oubhack->GetLuaInterface( LUA_STATE_MENU )->PushString( ccName );
	oubhack->GetLuaInterface( LUA_STATE_MENU )->Call( 1, 1 );

	bool bRes = oubhack->GetLuaInterface( LUA_STATE_MENU )->GetBool();
	oubhack->GetLuaInterface( LUA_STATE_MENU )->Pop();

	return bRes;

}