


--===================================================
--								GHI Script Enviroment
--									ghi_scriptEnv.lua
--
--		Limited enviroment for execution of scripts
--	
-- 						(c)2011 The Gryphonheart Team
--								All rights reservated
--===================================================	

function GHI_ScriptEnviroment()
	local class = GHClass("GHI_ScriptEnviroment"); -- a class object
	
	-- create special objects
	local GHUIParent = CreateFrame("Frame",UIParent);
	GHUIParent:SetAllPoints(UIParent);
	GHUIParent:ClearAllPoints()
	GHUIParent.GetParent = nil;
	GHUIParent.GetPoint = nil;
		
	
		
	-- set up the allowed functions
	local enviroment = {
	-- Standard lua functions
		assert=assert,
		collectgarbage=collectgarbage,
		date=date,
		error=error,
		gcinfo=gcinfo,
		getfenv=getfenv,
		getmetatable=getmetatable,
		loadstring=loadstring,
		next=next,
		newproxy=newproxy,
		pcall=pcall,
		select=select,
		setmetatable=setmetatable,
		time=time,
		type=type,
		unpack=unpack,
		xpcall=xpcall,
		
	-- Math functions
		abs=abs,
		acos=acos,
		asin=asin,
		atan=atan,
		atan2=atan2,
		ceil=ceil,
		cos=cos,
		deg=deg,
		exp=exp,
		floor=floor,
		frexp=frexp,
		ldexp=ldexp,
		log=log,
		log10=log10,
		max=max,
		min=min,
		mod=mod,
		rad=rad,
		random=random,
		sin=sin,
		sqrt=sqrt,
		tan=tan,		
		math=math,
		
	-- string functions
		format=format,
		gsub=gsub,
		strbyte=strbyte,
		strchar=strchar,
		strfind=strfind,
		strlen=strlen,
		strlower=strlower,
		strmatch=strmatch,
		strrep=strrep,
		strrev=strrev,
		strsub=strsub,
		strupper=strupper,
		tonumber=tonumber,
		tostring=tostring,		
		strlenutf8=strlenutf8,
		strtrim=strtrim,
		strsplit=strsplit,
		strjoin=strjoin,
		strconcat=strconcat,
		tostringall=tostringall,
		string=string,
	
	-- table functions
		foreach=foreach,
		foreachi=foreachi,
		getn=getn,
		ipairs=ipairs,
		pairs=pairs,
		sort=sort,
		tContains=tContains,
		tinsert=tinsert,
		tremove=tremove,
		wipe=wipe,
		["#"]=table.getn,
		
	-- bit functions	
		bit=bit,
		coroutine=coroutine,

	
-- ===========  WoW API ===============
	-- Achievement
		AddTrackedAchievement=AddTrackedAchievement,
		CanShowAchievementUI=CanShowAchievementUI,
		ClearAchievementComparisonUnit=ClearAchievementComparisonUnit,
		GetAchievementCategory=GetAchievementCategory,
		GetAchievementComparisonInfo=GetAchievementComparisonInfo,
		GetAchievementComparisonUnitInfo=GetAchievementComparisonUnitInfo,
		GetAchievementCriteriaInfo=GetAchievementCriteriaInfo,
		GetAchievementInfo=GetAchievementInfo,
		GetAchievementInfoFromCriteria=GetAchievementInfoFromCriteria,
		GetAchievementLink=GetAchievementLink,
		GetAchievementNumCriteria=GetAchievementNumCriteria,
		GetAchievementNumRewards=GetAchievementNumRewards,
		GetCategoryInfo=GetCategoryInfo,
		GetCategoryList=GetCategoryList,
		GetCategoryNumAchievements=GetCategoryNumAchievements,
		GetComparisonStatistic=GetComparisonStatistic,
		GetLatestCompletedAchievements=GetLatestCompletedAchievements,
		GetLatestCompletedComparisonAchievements=GetLatestCompletedComparisonAchievements,
		GetLatestUpdatedComparisonStats=GetLatestUpdatedComparisonStats,
		GetLatestUpdatedStats=GetLatestUpdatedStats,
		GetNextAchievement=GetNextAchievement,
		GetNumComparisonCompletedAchievements=GetNumComparisonCompletedAchievements,
		GetNumCompletedAchievements=GetNumCompletedAchievements,
		GetPreviousAchievement=GetPreviousAchievement,
		GetStatistic=GetStatistic,
		GetStatisticsCategoryList=GetStatisticsCategoryList,
		GetTotalAchievementPoints=GetTotalAchievementPoints,
		GetTrackedAchievement=GetTrackedAchievement,
		GetNumTrackedAchievements=GetNumTrackedAchievements,
		RemoveTrackedAchievement=RemoveTrackedAchievement,
		SetAchievementComparisonUnit=SetAchievementComparisonUnit,
	
	-- Action functions
		ActionHasRange=ActionHasRange,
		GetActionBarPage=GetActionBarPage,
		GetActionBarToggles=GetActionBarToggles,
		GetActionCooldown=GetActionCooldown,
		GetActionCount=GetActionCount,
		GetActionInfo=GetActionInfo,
		GetActionText=GetActionText,
		GetActionTexture=GetActionTexture,
		GetBonusBarOffset=GetBonusBarOffset,
		GetMouseButtonClicked=GetMouseButtonClicked,
		GetMultiCastBarOffset=GetMultiCastBarOffset,
		GetPossessInfo=GetPossessInfo,
		HasAction=HasAction,
	
	-- Selected functions
		Dismount=Dismount,
		GetPVPTimer=GetPVPTimer,
		RandomRoll=RandomRoll,
		random=random,
		GetAddOnInfo=GetAddOnInfo,
		GetAddOnDependencies=GetAddOnDependencies,
		GetAddOnMetadata=GetAddOnMetadata,
		GetNumAddOns=GetNumAddOns,
		LoadAddOn=LoadAddOn,
		
		GetBinding=GetBinding,
		GetBindingAction=GetBindingAction,
		GetBindingKey=GetBindingKey,
		GetBindingText=GetBindingText,
		GetCurrentBindingSet=GetCurrentBindingSet,
		GetNumBindings=GetNumBindings,
	
		IsModifierKeyDown=IsModifierKeyDown,
		IsModifiedClick=IsModifiedClick,
		IsMouseButtonDown=IsMouseButtonDown,
		
		-- Camera
		CameraZoomIn = CameraZoomIn,
		CameraZoomOut = CameraZoomOut,
		FlipCameraYaw = FlipCameraYaw,
		IsMouselooking = IsMouselooking,
		MouselookStart = MouselookStart,
		MouselookStop = MouselookStop,
		MoveViewDownStart = MoveViewDownStart,
		MoveViewDownStop = MoveViewDownStop,
		MoveViewUpStart = MoveViewUpStart,
		MoveViewUpStop = MoveViewUpStop,
		MoveViewInStart = MoveViewInStart,
		MoveViewInStop = MoveViewInStop,
		MoveViewOutStart = MoveViewOutStart,
		MoveViewOutStop = MoveViewOutStop,
		MoveViewLeftStart = MoveViewLeftStart,
		MoveViewLeftStop = MoveViewLeftStop,
		MoveViewRightStart = MoveViewRightStart,
		MoveViewRightStop = MoveViewRightStop,
		NextView = NextView,
		PrevView = PrevView,
		ResetView = ResetView,
		SaveView = SaveView,
		SetView = SetView,
		
		GetChannelList = GetChannelList,
		GetChannelName = GetChannelName,
		GetChatWindowChannels = GetChatWindowChannels,
		JoinChannelByName = JoinChannelByName,
		LeaveChannelByName = LeaveChannelByName,
		ListChannels = ListChannels,
		SendChatMessage = GHI_DoSendChatMessage, -- send chat message with spam filter
		
		GetMoney = GetMoney,
		GetCurrentTitle = GetCurrentTitle,
		GetNumTitles = GetNumTitles,
		GetPlayerFacing = GetplayerFacing,
		GetTitleName = GetTitleName,
		GetUnitPitch = GetUnitPitch,
		
		HasFullControl = HasFullControl,
		IsFalling = IsFalling,
		IsFlying = IsFlying,
		IsFlyableArea = IsFlyableArea,
		IsIndoors = IsIndoors,
		IsMounted = IsMounted,
		IsOutdoors = IsOutdoors,
		IsOutOfBounds = IsOutOfBounds,
		IsResting = IsResting,
		IsStealthed = IsStealthed,
		IsSwimming = IsSwimming,
		IsTitleKnown = IsTitleKnown,
		NotWhileDeadError = NotWhileDeadError,
		SetCurrentTitle = SetCurrentTitle,
		
		GetAutoCompleteResults = GetAutoCompleteResults,
		GetChatTypeIndex = GetChatTypeIndex,
		GetChatWindowChannels = GetChatWindowChannels,
		GetChatWindowInfo = GetChatWindowInfo,
		GetChatWindowMessages = GetChatWindowMessages,
		JoinChannelByName = JoinChannelByName,
		LoggingChat = LoggingChat,
		LoggingCombat = LoggingCombat,
		
		GetDefaultLanguage = GetDefaultLanguage,
		GetLanguageByIndex = GetLanguageByIndex,
		GetNumLaguages = GetNumLanguages,
		SendAddonMessage = SendAddonMessage,
		DoEmote = GHI_DoEmote;
		
		CallCompanion = CallCompanion,
		DismissCompanion = DismissCompanion,
		GetCompanionInfo = GetCompanionInfo,
		GetNumCompanions = GetNumCompanions,
		GetCompanionCooldown = GetCompanionCooldown,
		PickupCompanion = PickupCompanion,
		SummonRandomCritter = SummonRandomCritter,
		
		-- Container 
		ContainerIDToInventoryID = ContainerIDToInventoryID,
		GetBagName = GetBagName,
		GetContainerItemCooldown = GetContainerItemCooldown,
		GetContainerItemDurability = GetContainerItemDurability,
		GetContainerItemInfo = GetContainerItemInfo,
		GetContainerItemLink = GetContainerItemLink,
		GetContainerNumFreeSlots = GetContainerNumFreeSlots,
		GetContainerNumSlots = GetContainerNumSlots,
		HasKey = HasKey,
		OpenAllBags = OpenAllBags,
		CloseAllBags = CloseAllBags,
		PickupContainerItem = PickupContainerItem,
		PutItemInBackpack = PutItemInBackpack,
		PutItemInBag = PutItemInBag,
		ToggleBackpack = ToggleBackpack,
		ToggleBag = ToggleBag,
		
		AutoEquipCursorItem = AutoEquipCursorItem,
		ClearCursor = ClearCursor,
		CursorCanGoInSlot = CursorCanGoInSlot,
		CursorHasItem = CursorHasItem,
		CursorHasMoney = CursorHasMacro,
		CursorHasSpell = CursorHasSpell,
		DropCursorMoney = DropCursorMoney,
		EquipCursorItem = EquipCursorItem,
		GetCursorInfo = GetCursorInfo,
		GetCursorMoney = GetCursorMoney,
		GetCursorPosition = GetCursorPosition,
		HideRepairCursor = HideRepairCursor,
		InRepairMode = InRepairMode,
		PickupContainerItem = PickupContainerItem,
		PickupInventoryItem = PickupInventoryItem,
		PickupMacro = PickupMacro,
		PickupItem = PickupItem,
		PutItemInBackpack = PutItemInBackpack,
		PutItemInBag = PutItemInBag,
		ResetCursor = ResetCursor,
		SetCursor = SetCursor,
		ShowInspectCursor = ShowInspectCursor,
		SplitContainerItem = SplitContainerItem,
		
		
		ConsoleAddMessage = ConsoleAddMessage,
		debugprofilestart = debugprofilestart,
		debugprofilestop = debugprofilestop,
		debugstack = debugstack,
		FrameXML_Debug = FrameXML_Debug,
		GetDebugStats = GetDebugStats,
		getprinthandler = getprinthandler,
		print = print,
		setprinthandler = setprinthandler,
		tostringall = tostringall,
		wipe = wipe,
		
		DressUpItemLink = DressUpItemLink,
		DressUpItem = DressUpItem,
		
		GetNumEquipmentSets = GetNumEquipmentSets,
		GetEquipmentSetInfo = GetEquipmentSetInfo,
		GetEquipmentSetInfoByName = GetEquipmentSetInfoByName,
		GetEquipmentSetItemIDs = GetEquipmentSetItemIDs,
		GetEquipmentSetLocations = GetEquipmentSetLocations,
		EquipmentManager_UnpackLocation = EquipmentManager_UnpackLocation,
		PickupEquipmentSet = PickupEquipmentSet,
		PickupEquipmentSetByName = PickupEquipmentSetByName,
		EquipmentSetContainsLockedItems = EquipmentSetContainsLockedItems,
		UseEquipmentSet = UseEquipmentSet,
		EquipmentManagerIgnoreSlotForsave = EquipmentManagerIgnoreSlotForsave,
		EquipmentManagerUnignoreSlotForSave = EquipmentManagerUnignoreSlotForSave,
		EquipmentManagerClearIgnoredSlotsForSave = EquipmentManagerClearIgnoredSlotsForSave,
		SaveEquipmentSet = SaveEquipmentSet,
		RenameEquipmentSet = RenameEquipmentSet,
		DeleteEquipmentSet = DeleteEquipmentSet,
		GetEquipmentSetIconInfo = GetEquipmentSetIconInfo,
		
		CreateFrame = CreateFrame,
		CreateFont = CreateFont,
		MouseIsOver = MouseIsOver,
		ToggleDropDownMenu = ToggleDropDownMenu,
		UIFrameFadeIn = UIFrameFadeIn,
		UIFrameFadeOut=UIFrameFadeOut,
		UIFrameFlash = UIFrameFlash,
		
		AddFriend = AddFriend,
		GetFriendInfo = GetFriendInfo,
		SetFriendNotes = SetFriendNotes,
		ShowFriends = ShowFriends,
		ToggleFriendsFrame = ToggleFriendsFrame,
		
		InviteUnit = InviteUnit,
		IsPartyLeader = IsPartyLeader,
		
		CanEditGuildEvent = CanEditGuildEvent,
		CanEditGuildInfo = CanEditGuildInfo,
		CanEditMOTD = CanEditMOTD,
		CanEditOfficerNote = CanEditOfficerNote,
		CanEditPublicNote = CanEditPublicNote,
		CanGuildDemote = CanGuildDemote,
		CanGuildInvite = CanGuildInvite,
		CanGuildPromote = CanGuildPromote,
		CanGuildRemove = CanGuildRemove,
		CanViewOfficerNote = CanViewOfficerNote,
		
		GetGuildEventInfo  = GetGuildEventInfo,
		GetGuildInfo = GetGuildInfo,
		GetGuildInfoText = GetGuildInfoText,
		GetGuildRosterInfo = GetGuildRosterInfo,
		GetGuildRosterLastOnline = GetGuildRosterLastOnline,
		GetGuildRosterMOTD = GetGuildRosterMOTD,
		GetGuildRosterSelection = GetGuildRosterSelection,
		GetGuildRosterShowOffline = GetGuildRosterShowOffline,
		GetNumGuildEvents = GetNumGuildEvents,
		GetNumGuildMembers = GetNumGuildMembers,
		GetTabardInfo = GetTabardInfo,
		GuildInfo = GuildInfo,
		GuildRoster = GuildRoster,
		GuildRosterSetOfficerNote = GuildRosterSetOfficerNote,
		GuildRosterSetPublicNote = GuildRosterSetPublicNote,
		
		GuildSetMOTD = GuildSetMOTD,
		IsGuildLeader = IsGuildLeader,
		IsInGuild = IsInGuild,
		QueryGuildEventLog = QueryGuildEventLog,
		SetGuildInfoText = SetGuildInfoText,
		SetGuildRosterSelection = SetGuildRosterSelection,
		SetGuildRosterShowOffline = SetGuildRosterShowOffline,
		SortGuildRoster = SortGuildRoster,
		
		-- guild Bank 
		AutoStoreGuildBankItem = AutoStoreGuildBankItem,
		CanWithdrawGuildBankMoney = CanWithdrawGuildBankMoney,
		CloseGuildBankFrame = CloseGuildBankFrame,
		DepositGuildBankMoney = DepositGuildBankMoney,
		GetCurrentGuildBankTab = GetCurrentGuildBankTab,
		GetGuildBankItemInfo = GetGuildBankItemInfo,
		GetGuildBankItemLink = GetGuildBankItemLink,
		GetGuildBankMoney = GetGuildBankMoney,
		GetGuildBankMoneyTransaction = GetGuildBankMoneyTransaction,
		GetGuildBankTabInfo = GetGuildBankTabInfo,
		GetGuildBankTabPermissions = GetGuildBankTabPermissions,
		GetGuildBankTransaction = GetGuildBankTransaction,
		GetGuildTabardFileNames = GetGuildTabardFileNames,
		GetNumGuildBankMoneyTransactions = GetNumGuildBankMoneyTransactions,
		GetNumGuildBankTabs = GetNumGuildBankTabs,
		GetNumGuildBankTransactions = GetNumGuildBankTransactions,
		PickupGuildBankItem = PickupGuildBankItem,
		QueryGuildBankLog = QueryGuildBankLog,
		QueryGuildBankTab = QueryGuildBankTab,
		SetCurrentGuildBankTab = SetCurrentGuildBankTab,
		SetGuildBankTabInfo = SetGuildBankTabInfo,
		SetGuildBankTabPermissions = SetGuildBankTabPermissions,
		SplitGuildBankItem = SplitGuildBankItem,
		
		AddIgnore = AddIgnore,
		GetIgnoreName = GetIgnoreName,
		GetNumIgnores = GetNumIgnores,
		GetSelectedIgnore = GetSelectedIgnore,
		SetSelectedIgnore = SetSelectedIgnore,
		
		
		CanInspect = CanInspect,
		NotifyInspect = NotifyInspect,
		InspectUnit = InspectUnit,
		
		IsInInstance = IsInInstance,
		
		AutoEquipCursorItem = AutoEquipCursorItem,
		EquipCursorItem = EquipCursorItem,
		GetInventoryItemID = GetInventoryItemID,
		GetInventoryItemCount = GetInventoryItemCount,
		GetInventoryItemTexture = GetInventoryItemTexture,
		GetInventorySlotInfo = GetInventorySlotInfo,
		HasWandEquipped = HasWandEquipped,
		IsInventoryItemLocked = IsInventoryItemLocked,
		PickupInventoryItem = PickupInventoryItem,
		
		EquipItemByName = EquipItemByName,
		GetItemCount = GetItemCount,
		GetItemFamily = GetItemFamily,
		GetItemIcon = GetItemIcon,
		GetItemInfo = GetItemInfo,
		GetItemQualityColor = GetItemQualityColor,
		IsEquippedItem = IsEquippedItem,
		IsItemInRange = IsItemInRange,
		ItemHasRange = ItemHasRange,
		OffhandHasWeapon = OffhandHasWeapon,
		SplitContainerItem = SplitContainerItem,
		SetItemRef = SetItemRef,
		
		CloseItemText = CloseItemText,
		ItemTextGetCreator = ItemTextGetCreator,
		ItemTextGetItem = ItemTextGetItem,
		ItemTextGetMaterial = ItemTextGetMaterial,
		ItemTextGetPage = ItemTextGetPage,
		ItemTextGetText = ItemTextGetText,
		ItemTextHasNextPage = ItemTextHasNextPage,
		ItemTextNextPage = ItemTextNextPage,
		ItemTextPrevPage = ItemTextPrevPage,
		
		-- location
		GetMinimapZoneText = GetMinimapZoneText,
		GetRealZoneText = GetRealZoneText,
		GetSubZoneText = GetSubZoneText,
		GetZonePVPInfo = GetZonePVPInfo,
		GetZoneText = GetZoneText,
		
		-- map		
		GetCurrentMapContinent = GetCurrentMapContinent,
		GetCurrentMapDungeonLevel = GetCurrentMapDungeonLevel,
		GetNumDungeonMapLevels = GetNumDungeonMapLevels,
		GetCurrentMapAreaID = GetCurrentMapAreaID,
		GetCurrentMapZone = GetCurrentMapZone,
		GetMapContinents = GetMapContinents,
		GetMapInfo = GetMapInfo,
		GetMapLandmarkInfo = GetMapLandmarkInfo,
		GetMapOverlayInfo = GetMapOverlayInfo,
		GetMapZones = GetMapZones,
		GetNumMapLandmarks = GetNumMapLandmarks,
		GetNumMapOverlays = GetNumMapOverlays,
		GetPlayerMapPosition = GetPlayerMapPosition,
		ProcessMapClick = ProcessMapClick,
		RequestBattlefieldPositions  = RequestBattlefieldPositions,
		SetDungeonMapLevel = SetDungeonMapLevel,
		SetMapByID = SetMapByID,
		SetMapToCurrentZone = SetMapToCurrentZone,
		SetMapZoom = SetMapZoom,
		SetupFullscreenScale = SetupFullscreenScale,
		UpdateMapHighlight = UpdateMapHighlight,
		ZoomOut = ZoomOut,
		
		FollowUnit = FollowUnit,
		
		GetAddOnCPUUsage = GetAddOnCPUUsage,
		GetAddOnMemoryUsage = GetAddOnMemoryUsage,
		GetEventCPUUsage = GetEventCPUUsage,
		GetFrameCPUUsage = GetFrameCPUUsage,
		GetFunctionCPUUsage = GetFunctionCPUUsage,
		GetScriptCPUUsage = GetScriptCPUUsage,
		ResetCPUUsage = ResetCPUUsage,
		UpdateAddOnCPUUsage = UpdateAddOnCPUUsage,
		UpdateAddOnMemoryUsage = UpdateAddOnMemoryUsage,
		
		InCombatLockdown = InCombatLockdown,
		
		GetCVar = GetCVar,
		GetCVarDefault = GetCVarDefault,
		GetCurrentResolution = GetCurrentResolution,
		GetGamma = GetGamma,
		GetScreenResolutions = GetScreenResolutions,
		SetScreenResolution = SetScreenResolution,
		
		ShowCloak = ShowCloak,
		ShowHelm = ShowHelm,
		ShowingCloak = ShowingCloak,
		ShowingHelm = ShowingHelm,
		ShowNumericThreat = ShowNumericThreat,
		
		GetBuildInfo = GetBuildInfo,
		GetExistingLocales = GetExistingLocales,
		GetFramerate = GetFramerate,
		GetGameTime = GetGameTime,
		GetLocale = GetLocale,
		GetCursorPosition = GetCursorPosition,
		GetNetStats = GetNetStats,
		GetRealmName = GetRealmName,
		GetScreenHeight = GetScreenHeight,
		GetScreenWidth = GetScreenWidth,
		GetText = GetText,
		GetTime = GetTime,
		IsAltKeyDown = IsAltKeyDown,
		IsControlKeyDown = IsControlKeyDown,
		IsDebugBuild = IsDebugBuild,
		IsLeftAltKeyDown = IsLeftAltKeyDown,
		IsLeftControlKeyDown = IsLeftControlKeyDown,
		IsLeftShiftKeyDown = IsLeftShiftKeyDown,
		IsLinuxClient = IsLinuxClient,
		IsLoggedIn = IsLoggedIn,
		IsMacClient = IsMacClient,
		IsRightAltKeyDown = IsRightAltKeyDown,
		IsRightControlKeyDown = IsRightControlKeyDown,
		IsRightShiftKeyDown = IsRightShiftKeyDown,
		IsShiftKeyDown = IsShiftKeyDown,
		IsWindowsClient = IsWindowsClient,
		PlayMusic = PlayMusic,
		PlaySound = PlaySound,
		PlaySoundFile = PlaySoundFile,
		ReloadUI = ReloadUI,
		Screenshot = Screenshot,
		SecondsToTime = SecondsToTime,
		SecondsToTimeAbbrev = SecondsToTimeAbbrev,
		StopMusic = StopMusic,
		TakeScreenshot = TakeScreenshot,
		message = message,
		
		ToggleMinimap = ToggleMinimap,
		ToggleFramerate = ToggleFramerate,
		ToggleFriendsFrame = ToggleFriendsFrame,
		
		GetNumTrackingTypes = GetNumTrackingTypes,
		GetTrackingTexture = GetTrackingTexture,
		GetTrackingInfo = GetTrackingInfo,
		SetTracking = SetTracking,
		
		-- unit functions 
		CheckInteractDistance = CheckInteractDistance,
		GetUnitName = GetUnitName,
		GetUnitSpeed = GetUnitSpeed,
		IsUnitOnQuest = IsUnitOnQuest,
		UnitAura = UnitAura,
		UnitBuff = UnitBuff,
		UnitClass = UnitClass,
		UnitClassification = UnitClassification,
		UnitCreatureFamily = UnitCreatureFamily,
		UnitCreatureType = UnitCreatureType,
		UnitDebuff = UnitDebuff,
		UnitExists = UnitExists,
		UnitFactionGroup = UnitFactionGroup,
		UnitGUID = UnitGUID,
		GetPlayerInfoByGUID = GetPlayerInfoByGUID,
		UnitInParty = UnitInParty,
		UnitInRange = UnitInRange,
		UnitIsAFK = UnitIsAFK,
		UnitIsConnected = UnitIsConnected,
		UnitIsCorpse = UnitIsCorpse,
		UnitIsDead = UnitIsDead,
		UnitIsDeadOrGhost = UnitIsDeadOrGhost,
		UnitIsDND = UnitIsDND,
		UnitIsEnemy = UnitIsEnemy,
		UnitIsFeignDeath = UnitIsFeignDeath,
		UnitIsFriend = UnitIsFriend,
		UnitIsGhost = UnitIsGhost,
		UnitIsPlayer = UnitIsPlayer,
		UnitIsSameServer = UnitIsSameServer,
		UnitIsTrivial = UnitIsTrivial,
		UnitIsUnit = UnitIsUnit,
		UnitIsVisible = UnitIsVisible,
		UnitLevel = UnitLevel,
		UnitMana = UnitMana,
		UnitName = UnitName,
		UnitPlayerControlled = UnitPlayerControlled,
		UnitPlayerOrPetInParty = UnitPlayerOrPetInParty,
		UnitPlayerOrPetInRaid = UnitPlayerOrPetInRaid,
		UnitPVPName = UnitPVPName,
		UnitPVPRank = UnitPVPRank,
		UnitRace = UnitRace,
		UnitReaction = UnitReaction,
		UnitSex = UnitSex,
		SetPortraitTexture = SetPortraitTexture,
		SetPortraitToTexture = SetPortraitToTexture,
		
		-- who
		GetNumWhoResults = GetNumWhoResults,
		GetWhoInfo = GetWhoInfo,
		SendWho = SendWho,
		SetWhoToUI = SetWhoToUI,
		SortWho = SortWho,
		
		
-- ===========  GHI API ===============		
	-- General
		GHI_Message = GHI_Message,
		GHI_ReloadUI = GHI_ReloadUI,
		GHI_ColorStrings = GHI_ColorStrings,
		GHI_PrintArray = GHI_PrintArray,
	
	-- Actionbar 
		GHI_GetActionBarData = GHI_GetActionBarData,
		GHI_SetActionBarData = GHI_SetActionBarData,
		GHI_ShowAllActionbars = GHI_ShowAllActionbars,
		GHI_HideUnusedActionbars = GHI_HideUnusedActionbars,
		
	-- Book
		GHI_BookNextPage = GHI_BookNextPage,
		GHI_BookPrevPage = GHI_BookPrevPage,
		GHI_ShowBook = GHI_ShowBook,
		GHI_TranscribeTextItem = GHI_TranscribeTextItem,
		GHI_TranscribeMailboxLetter = GHI_TranscribeMailboxLetter,
	
	-- Buff
		ApplyGHIBuff = ApplyGHIBuff,
		RemoveGHIBuff = RemoveGHIBuff,
		RemoveAllGHIBuffs = RemoveAllGHIBuffs,
		CountGHIBuff = CountGHIBuff,
	
	-- Communication
		GHI_SendLink = GHI_SendLink,
		GHI_SendAreaEffect = GHI_SendAreaEffect,
		GHI_SendAreaBuff = GHI_SendAreaBuff,
		GHI_SendItemData = GHI_SendItemData,
		GHI_SendPing = GHI_SendPing,
		
	-- Container
		GHI_GetContainerInfo = GHI_GetContainerInfo,
		GHI_GetNumContainers = GHI_GetNumContainers,
		GHI_GetContainerList = GHI_GetContainerList,
		GHI_GetContainerSize = GHI_GetContainerSize,
		GHI_GetSlotList = GHI_GetSlotList,
		GHI_ToggleBackpack = GHI_ToggleBackpack,
		GHI_updateContainerFrameAnchors = GHI_updateContainerFrameAnchors,
		GHI_UpdateContainers = GHI_UpdateContainers,
		GHI_NextMainBagPage = GHI_NextMainBagPage,
		GHI_PrevMainBagPage = GHI_PrevMainBagPage,
		GHI_SelectSecBag = GHI_SelectSecBag,
		GHI_MaintainMainBags = GHI_MaintainMainBags,
		GHI_IsBagEmpty = GHI_IsBagEmpty,
		GHI_GetBagID = GHI_GetBagID,
		GHI_GetFreeSpace = GHI_GetFreeSpace,
		GHI_FindItem = GHI_FindItem,
		GHI_CountItem = GHI_CountItem,
		GHI_ProduceItem = GHI_ProduceItem,
		GHI_InsertItem = GHI_InsertItem,

	-- create item	
		GHI_CreateItem = GHI_CreateItem,
		GHI_GetItemInfo = GHI_GetItemInfo,
		GHI_GetRightClickInfo = GHI_GetRightClickInfo,
		GHI_IsOfficialItem = GHI_IsOfficialItem,
		GHI_GetVersions = GHI_GetVersions,
		GHI_IsCopyable = GHI_IsCopyable,
		GHI_IsEditable = GHI_IsEditable,
		GHI_ClearItemCatche = GHI_ClearItemCatche,
		GHI_GenerateID = GHI_GenerateID,
		GHI_ExportItem = GHI_ExportItem,
		GHI_ImportItem = GHI_ImportItem,
		
		
	-- cursor	
		GHI_SetCursor = GHI_SetCursor,
		GHI_ResetCursor = GHI_ResetCursor,
		GHI_GetCursor = GHI_GetCursor,
		GHI_GetCursorPreDetails = GHI_GetCursorPreDetails,
		GHI_AddExternalPreDetails = GHI_AddExternalPreDetails,
		
		
		
	-- display	
		GHI_SetCustomSlotInfo = GHI_SetCustomSlotInfo,
		GHI_GetPlayerEquipmentDisplay = GHI_GetPlayerEquipmentDisplay,
		GHI_ShowPlayerEquipmentDisplay = GHI_ShowPlayerEquipmentDisplay,
		GHI_SetTargetEqDisplay = GHI_SetTargetEqDisplay,
		GHI_CopyTargetEqDisplay = GHI_CopyTargetEqDisplay,
		GHI_ToggleTargetEqDisplay = GHI_ToggleTargetEqDisplay,
		
		
	-- links	
		GHI_GenerateLink = GHI_GenerateLink,
		
	-- use item
		GHI_UseItem = GHI_UseItem,
		GHI_GetCurrentItem = GHI_GetCurrentItem,
		GHI_DoEmote = GHI_DoEmote,
		GHI_DoSay = GHI_DoSay,
		GHI_IsStdEmote = GHI_IsStdEmote,
		GHI_DoScript = GHI_DoScript,
		GHI_GetItemUseInfo = GHI_GetItemUseInfo,
		GHI_CheckReq = GHI_CheckReq,		
		
		--GHI_ItemData = GHI_ItemData,
		--GHI_ContainerData = GHI_ContainerData,
		--GHI_TradeItemsRecipient = GHI_TradeItemsRecipient,
		UIParent = GHUIParent,
		GHI_ColorString = GHI_ColorString,
		GHI_MiscData = GHI_MiscData,
				
		-- add message
		DEFAULT_CHAT_FRAME = {AddMessage = function(self,...) DEFAULT_CHAT_FRAME:AddMessage(...); end},
		SELECTED_CHAT_FRAME = {AddMessage = function(self,...) SELECTED_CHAT_FRAME:AddMessage(...); end},
		ChatFrame1 = {AddMessage = function(self,...) ChatFrame1:AddMessage(...); end},
		ChatFrame2 = {AddMessage = function(self,...) ChatFrame2:AddMessage(...); end},
		ChatFrame3 = {AddMessage = function(self,...) ChatFrame3:AddMessage(...); end},
		ChatFrame4 = {AddMessage = function(self,...) ChatFrame4:AddMessage(...); end},
		ChatFrame5 = {AddMessage = function(self,...) ChatFrame5:AddMessage(...); end},
		ChatFrame6 = {AddMessage = function(self,...) ChatFrame6:AddMessage(...); end},
		UIErrorsFrame = {AddMessage = function(self,...) UIErrorsFrame:AddMessage(...); end},
		
		EquipItem = EquipItem,
		UpdateItemInfo = function(id,info) 
			local v1,v2 = GHI_GetVersions(id); 
			if type(info) == "table" then 
				local own1 = (info.version or 0); 
				local own2 = 0; 
				if type(info.rc) == "table" then 
					own2 = info.rc.version or 0; 
				end
				if own1 > v1 or own2 > v2 then 
					GHI_ItemData[id] = info; 
				end
			end
		end,
		GHI_GET_LOOT = GHI_GET_LOOT,
	}

	
	class.ExecuteScript = function(self,code)		
		-- execute the code in the enviroment
		local codeFunc = loadstring(code);
		setfenv(codeFunc, enviroment);
		return codeFunc();
	end
	
	class.AddLocalFunction = function(self,functionName,func)
		allowedFunctions[functionName] = func;
	end
	
	class.AddGlobalFunction = function(self,functionName)
		allowedFunctions[functionName]= _G[functionName];
	end
	
	
	
	return class;
end


