OpenClonk
C4GameScriptHost Class Reference

#include <C4ScriptHost.h>

Inheritance diagram for C4GameScriptHost:
[legend]
Collaboration diagram for C4GameScriptHost:
[legend]

Public Member Functions

 C4GameScriptHost ()
 
 ~C4GameScriptHost () override
 
bool Load (C4Group &, const char *, const char *, C4LangStringTable *) override
 
bool LoadData (const char *, const char *, C4LangStringTable *) override
 
void Clear ()
 
C4PropListStaticGetPropList () override
 
void Denumerate (C4ValueNumbers *numbers)
 
C4Value Call (const char *szFunction, C4AulParSet *pPars=nullptr, bool fPassError=false)
 
virtual bool Delete ()
 
bool Load (C4Group &hGroup, const char *szFilename, const char *szLanguage=nullptr)
 
bool Load (C4GroupSet &hGroupSet, const char *szFilename, const char *szLanguage=nullptr)
 
void Reg2List (C4AulScriptEngine *pEngine)
 
const C4PropListStaticGetPropList () const
 
const char * GetScript () const
 
bool IsReady ()
 
std::string Translate (const std::string &text) const
 
bool IsWarningEnabled (const char *pos, C4AulWarningId warning) const
 
const char * GetFilePath () const
 
const char * GetData () const
 
const StdStrBufGetDataBuf () const
 
size_t GetDataSize () const
 
bool GetLanguageString (const char *szLanguage, StdStrBuf &rTarget)
 

Public Attributes

C4Value ScenPropList
 
C4Value ScenPrototype
 
C4EffectpScenarioEffects = nullptr
 
std::list< C4ScriptHost * > SourceScripts
 
StdCopyStrBuf ScriptName
 

Protected Member Functions

void Unreg ()
 
void MakeScript ()
 
virtual bool ReloadScript (const char *szPath, const char *szLanguage)
 
bool Preparse ()
 
virtual bool Parse ()
 
virtual void UnLink ()
 
void UnlinkOwnedFunctions ()
 
void DeleteOwnedPropLists ()
 
void Warn (const char *pMsg,...) GNUC_FORMAT_ATTRIBUTE_O
 
virtual void AddEngineFunctions ()
 
void CopyPropList (C4Set< C4Property > &from, C4PropListStatic *to)
 
bool ResolveIncludes (C4DefList *rDefs)
 
bool ResolveAppends (C4DefList *rDefs)
 
void DoAppend (C4Def *def)
 
void EnableWarning (const char *pos, C4AulWarningId warning, bool enable=true)
 
virtual void OnLoad ()
 
void CopyFilePathFromGroup (const C4Group &hGroup)
 
void FinishLoad (const StdStrBuf &, C4Group &hGroup)
 

Protected Attributes

C4AulScriptEngineEngine {nullptr}
 
C4ScriptHostPrev {nullptr}
 
C4ScriptHostNext {nullptr}
 
std::list< StdCopyStrBufIncludes
 
std::list< StdCopyStrBufAppends
 
bool Resolving
 
bool IncludesResolved
 
StdStrBuf Script
 
C4LangStringTablestringTable
 
C4Set< C4PropertyLocalValues
 
C4AulScriptState State {ASS_NONE}
 
std::vector< C4ValueownedFunctions
 
std::vector< C4ValueownedPropLists
 
StdCopyStrBuf Data
 
StdCopyStrBuf Filename
 
StdCopyStrBuf FilePath
 

Detailed Description

Definition at line 152 of file C4ScriptHost.h.

Constructor & Destructor Documentation

◆ C4GameScriptHost()

C4GameScriptHost::C4GameScriptHost ( )

Definition at line 345 of file C4ScriptHost.cpp.

References ~C4GameScriptHost().

345 : ScenPrototype(0), ScenPropList(0) { }
C4Value ScenPropList
Definition: C4ScriptHost.h:163
C4Value ScenPrototype
Definition: C4ScriptHost.h:164
Here is the call graph for this function:

◆ ~C4GameScriptHost()

C4GameScriptHost::~C4GameScriptHost ( )
overridedefault

Referenced by C4GameScriptHost().

Here is the caller graph for this function:

Member Function Documentation

◆ AddEngineFunctions()

virtual void C4ScriptHost::AddEngineFunctions ( )
inlineprotectedvirtualinherited

Reimplemented in C4MapScriptHost.

Definition at line 82 of file C4ScriptHost.h.

References C4ScriptHost::CopyPropList(), C4ScriptHost::DoAppend(), C4ScriptHost::ResolveAppends(), and C4ScriptHost::ResolveIncludes().

Referenced by C4ScriptHost::Preparse().

82 {}; // add any engine functions specific to this script host
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Call()

C4Value C4GameScriptHost::Call ( const char *  szFunction,
C4AulParSet pPars = nullptr,
bool  fPassError = false 
)

Definition at line 390 of file C4ScriptHost.cpp.

References C4Value::_getPropList(), C4PropList::Call(), and ScenPropList.

Referenced by AlgoScript(), C4Control::CompileFunc(), C4Game::GRBroadcast(), C4Game::InitGameFinal(), C4MapScriptHost::InitializeMap(), C4ObjectMenu::IsCloseDenied(), and C4ObjectMenu::OnSelectionChanged().

391 {
392  return ScenPropList._getPropList()->Call(szFunction, Pars, fPassError);
393 }
C4PropList * _getPropList() const
Definition: C4Value.h:129
C4Value ScenPropList
Definition: C4ScriptHost.h:163
C4Value Call(C4PropertyName k, C4AulParSet *pPars=nullptr, bool fPassErrors=false)
Definition: C4PropList.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4GameScriptHost::Clear ( )

Definition at line 370 of file C4ScriptHost.cpp.

References C4ScriptHost::Clear(), pScenarioEffects, ScenPropList, ScenPrototype, and C4Value::Set0().

Referenced by c4_mapgen_handle_deinit_script_engine(), and C4Game::Clear().

371 {
373  ScenPropList.Set0();
375  delete pScenarioEffects; pScenarioEffects=nullptr;
376 }
void Set0()
Definition: C4Value.h:336
C4Value ScenPropList
Definition: C4ScriptHost.h:163
C4Value ScenPrototype
Definition: C4ScriptHost.h:164
C4Effect * pScenarioEffects
Definition: C4ScriptHost.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CopyFilePathFromGroup()

void C4ComponentHost::CopyFilePathFromGroup ( const C4Group hGroup)
protectedinherited

Definition at line 120 of file C4ComponentHost.cpp.

References StdStrBuf::Append(), StdStrBuf::AppendBackslash(), C4Config::AtRelativePath(), Config, StdStrBuf::Copy(), C4ComponentHost::Filename, C4ComponentHost::FilePath, StdStrBuf::getData(), and C4Group::GetFullName().

Referenced by C4ComponentHost::FinishLoad(), and C4ComponentHost::Load().

121 {
125 }
C4Config Config
Definition: C4Config.cpp:833
StdCopyStrBuf FilePath
void AppendBackslash()
Definition: StdBuf.cpp:248
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519
const char * getData() const
Definition: StdBuf.h:442
StdCopyStrBuf Filename
const char * AtRelativePath(const char *szFilename)
Definition: C4Config.cpp:656
void Copy()
Definition: StdBuf.h:467
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CopyPropList()

void C4ScriptHost::CopyPropList ( C4Set< C4Property > &  from,
C4PropListStatic to 
)
protectedinherited

Definition at line 1694 of file C4AulParse.cpp.

References C4Value::_getPropList(), C4ScriptHost::C4AulScriptFunc, C4V_Array, C4V_Function, C4V_PropList, C4VFunction(), C4VPropList(), C4Set< T >::First(), C4PropList::GetFunc(), C4Value::getFunction(), C4PropListStatic::GetParent(), C4Value::GetType(), C4PropList::IsStatic(), C4Property::Key, C4AulFunc::Name, C4PropList::NewStatic(), C4Set< T >::Next(), C4StringTable::P, P_Prototype, C4AulScriptFunc::pOrgScript, C4AulScriptFunc::SetOverloaded(), C4PropList::SetPropertyByS(), C4AulFunc::SFunc(), Strings, and C4Property::Value.

Referenced by C4ScriptHost::AddEngineFunctions(), and C4ScriptHost::Parse().

1695 {
1696  // append all funcs and local variable initializations
1697  const C4Property * prop = from.First();
1698  while (prop)
1699  {
1700  switch(prop->Value.GetType())
1701  {
1702  case C4V_Function:
1703  {
1704  C4AulScriptFunc * sf = prop->Value.getFunction()->SFunc();
1705  if (sf)
1706  {
1707  C4AulScriptFunc *sfc;
1708  if (sf->pOrgScript != this)
1709  sfc = new C4AulScriptFunc(to, *sf);
1710  else
1711  sfc = sf;
1712  sfc->SetOverloaded(to->GetFunc(sf->Name));
1713  to->SetPropertyByS(prop->Key, C4VFunction(sfc));
1714  }
1715  else
1716  {
1717  // engine function
1718  to->SetPropertyByS(prop->Key, prop->Value);
1719  }
1720  }
1721  break;
1722  case C4V_PropList:
1723  {
1724  C4PropListStatic * p = prop->Value._getPropList()->IsStatic();
1725  assert(p);
1726  if (prop->Key != &::Strings.P[P_Prototype])
1727  if (!p || p->GetParent() != to)
1728  {
1729  p = C4PropList::NewStatic(nullptr, to, prop->Key);
1730  CopyPropList(prop->Value._getPropList()->Properties, p);
1731  }
1732  to->SetPropertyByS(prop->Key, C4VPropList(p));
1733  }
1734  break;
1735  case C4V_Array: // FIXME: copy the array if necessary
1736  default:
1737  to->SetPropertyByS(prop->Key, prop->Value);
1738  }
1739  prop = from.Next(prop);
1740  }
1741 }
C4String P[P_LAST]
C4Value Value
Definition: C4PropList.h:55
T const * Next(T const *p) const
C4ScriptHost * pOrgScript
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
C4PropList * _getPropList() const
Definition: C4Value.h:129
C4V_Type GetType() const
Definition: C4Value.h:161
C4AulFunc * getFunction() const
Definition: C4Value.h:119
void CopyPropList(C4Set< C4Property > &from, C4PropListStatic *to)
C4StringTable Strings
Definition: C4Globals.cpp:42
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:245
friend class C4AulScriptFunc
Definition: C4ScriptHost.h:110
T const * First() const
static C4PropListStatic * NewStatic(C4PropList *prototype, const C4PropListStatic *parent, C4String *key)
Definition: C4PropList.cpp:70
C4String * Key
Definition: C4PropList.h:54
void SetOverloaded(C4AulFunc *)
C4AulFunc * GetFunc(C4PropertyName k) const
Definition: C4PropList.h:105
const C4PropListStatic * GetParent() const
Definition: C4PropList.h:270
C4Value C4VFunction(C4AulFunc *pFn)
Definition: C4Value.h:250
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:971
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
virtual C4AulScriptFunc * SFunc()
Definition: C4AulFunc.h:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Delete()

virtual bool C4ScriptHost::Delete ( )
inlinevirtualinherited

Reimplemented in C4ExtraScriptHost.

Definition at line 43 of file C4ScriptHost.h.

References C4ScriptHost::Clear(), C4ScriptHost::Load(), C4ScriptHost::LoadData(), and C4ScriptHost::Reg2List().

Referenced by C4AulScriptEngine::Clear().

43 { return false; } // do NOT delete this - it's just a class member!
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteOwnedPropLists()

void C4ScriptHost::DeleteOwnedPropLists ( )
protectedinherited

Definition at line 118 of file C4ScriptHost.cpp.

References C4PropList::Clear(), C4PropList::Delete(), and C4ScriptHost::ownedPropLists.

Referenced by C4ScriptHost::Clear(), and C4ScriptHost::UnLink().

119 {
120  // delete all static proplists associated to this script host.
121  // Note that just clearing the vector is not enough in case of
122  // cyclic references.
123  for (C4Value& value: ownedPropLists)
124  {
125  C4PropList* plist = value.getPropList();
126  if (plist)
127  {
128  if (plist->Delete()) delete plist;
129  else plist->Clear();
130  }
131  }
132  ownedPropLists.clear();
133 }
void Clear()
Definition: C4PropList.h:66
virtual bool Delete()
Definition: C4PropList.h:90
std::vector< C4Value > ownedPropLists
Definition: C4ScriptHost.h:101
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Denumerate()

void C4GameScriptHost::Denumerate ( C4ValueNumbers numbers)

Definition at line 384 of file C4ScriptHost.cpp.

References C4Effect::Denumerate(), C4Value::Denumerate(), pScenarioEffects, and ScenPropList.

Referenced by C4AulScriptEngine::Denumerate().

385 {
386  ScenPropList.Denumerate(numbers);
388 }
void Denumerate(C4ValueNumbers *) override
Definition: C4Effect.cpp:176
void Denumerate(C4ValueNumbers *)
Definition: C4Value.cpp:251
C4Value ScenPropList
Definition: C4ScriptHost.h:163
C4Effect * pScenarioEffects
Definition: C4ScriptHost.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoAppend()

void C4ScriptHost::DoAppend ( C4Def def)
protectedinherited

Definition at line 28 of file C4AulLink.cpp.

References C4ScriptHost::Includes, C4Def::Script, C4ScriptHost::SourceScripts, and C4ScriptHost::Warn().

Referenced by C4ScriptHost::AddEngineFunctions(), and C4ScriptHost::ResolveAppends().

29 {
30  if (std::find(def->Script.SourceScripts.begin(), def->Script.SourceScripts.end(), this) == def->Script.SourceScripts.end())
31  {
32  def->Script.SourceScripts.push_back(this);
33  if (!Includes.empty())
34  {
35  Warn("#appendto contains #include");
36  // Try to fullfil #include, but it won't work properly: #appendtos
37  // are always appended, but #includes are prepended to the script.
38  def->Script.Includes.insert(def->Script.Includes.end(), Includes.begin(), Includes.end());
39  }
40 
41  }
42 }
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:79
void Warn(const char *pMsg,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: C4AulParse.cpp:123
C4DefScriptHost Script
Definition: C4Def.h:181
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnableWarning()

void C4ScriptHost::EnableWarning ( const char *  pos,
C4AulWarningId  warning,
bool  enable = true 
)
protectedinherited

Definition at line 1780 of file C4AulParse.cpp.

1781 {
1782  auto entry = enabledWarnings.emplace(pos, decltype(enabledWarnings)::mapped_type{});
1783  if (entry.second)
1784  {
1785  // If there was no earlier entry for this position, copy the previous
1786  // warning state
1787  assert(entry.first != enabledWarnings.begin());
1788  auto previous = entry.first;
1789  --previous;
1790  entry.first->second = previous->second;
1791  }
1792  entry.first->second.set(static_cast<size_t>(warning), enable);
1793 }

◆ FinishLoad()

void C4ComponentHost::FinishLoad ( const StdStrBuf name,
C4Group hGroup 
)
protectedinherited

Definition at line 99 of file C4ComponentHost.cpp.

References C4ComponentHost::CopyFilePathFromGroup(), C4ComponentHost::Data, StdStrBuf::EnsureUnicode(), C4ComponentHost::Filename, C4ComponentHost::FilePath, C4Group::FindEntry(), StdStrBuf::getData(), StdStrBuf::getSize(), LogF(), StdStrBuf::Move(), C4ComponentHost::OnLoad(), and StdStrBuf::Shrink().

Referenced by C4ComponentHost::Load().

100 {
101  // Store actual filename
102  hGroup.FindEntry(name.getData(), &Filename);
103  CopyFilePathFromGroup(hGroup);
104 
105  if (Data.EnsureUnicode())
106  {
107  LogF("WARNING: File is not encoded as UTF-8 (%s)", FilePath.getData());
108  }
109  // Skip those stupid "zero width no-break spaces" (also known as Byte Order Marks)
110  if (Data[0] == '\xEF' && Data[1] == '\xBB' && Data[2] == '\xBF')
111  {
112  Data.Move(3,Data.getSize()-3);
113  Data.Shrink(3);
114  }
115  // Notify
116  OnLoad();
117 }
bool FindEntry(const char *szWildCard, StdStrBuf *sFileName=nullptr, size_t *iSize=nullptr)
Definition: C4Group.cpp:1774
StdCopyStrBuf FilePath
void CopyFilePathFromGroup(const C4Group &hGroup)
StdCopyStrBuf Data
virtual void OnLoad()
const char * getData() const
Definition: StdBuf.h:442
size_t getSize() const
Definition: StdBuf.h:444
bool EnsureUnicode()
Definition: StdBuf.cpp:421
void Shrink(size_t iShrink)
Definition: StdBuf.h:503
StdCopyStrBuf Filename
void Move(size_t iFrom, size_t inSize, size_t iTo=0)
Definition: StdBuf.h:471
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:260
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetData()

const char* C4ComponentHost::GetData ( ) const
inlineinherited

Definition at line 30 of file C4ComponentHost.h.

References C4ComponentHost::Data, and StdStrBuf::getData().

Referenced by C4Game::CompileRuntimeData(), C4RankSystem::Load(), C4ScenarioListLoader::Entry::Load(), C4Player::LoadRuntimeData(), C4ObjectInfoList::New(), C4Game::OpenScenario(), C4GameLobby::ScenDesc::ScenDesc(), and C4LangStringTable::Translate().

30 { return Data.getData(); }
StdCopyStrBuf Data
const char * getData() const
Definition: StdBuf.h:442
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDataBuf()

const StdStrBuf& C4ComponentHost::GetDataBuf ( ) const
inlineinherited

Definition at line 31 of file C4ComponentHost.h.

References C4ComponentHost::Data.

Referenced by C4Game::CompileRuntimeData(), C4Language::HasStringTable(), and C4ScriptHost::MakeScript().

31 { return Data; }
StdCopyStrBuf Data
Here is the caller graph for this function:

◆ GetDataSize()

size_t C4ComponentHost::GetDataSize ( ) const
inlineinherited

Definition at line 32 of file C4ComponentHost.h.

References C4ComponentHost::Data, C4ComponentHost::GetLanguageString(), StdStrBuf::getLength(), and C4ComponentHost::Load().

Referenced by C4RankSystem::Load().

32 { return Data.getLength(); }
StdCopyStrBuf Data
size_t getLength() const
Definition: StdBuf.h:445
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFilePath()

const char* C4ComponentHost::GetFilePath ( ) const
inlineinherited

Definition at line 28 of file C4ComponentHost.h.

References C4ComponentHost::FilePath, and StdStrBuf::getData().

Referenced by C4ScriptHost::Load(), C4Player::LoadRuntimeData(), C4ScriptHost::ReloadScript(), C4LangStringTable::ReplaceStrings(), and C4LangStringTable::Translate().

28 { return FilePath.getData(); }
StdCopyStrBuf FilePath
const char * getData() const
Definition: StdBuf.h:442
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLanguageString()

bool C4ComponentHost::GetLanguageString ( const char *  szLanguage,
StdStrBuf rTarget 
)
inherited

Definition at line 127 of file C4ComponentHost.cpp.

References StdStrBuf::Copy(), C4ComponentHost::Data, StdStrBuf::getData(), SAppend(), SCharPos(), SCopySegment(), and SSearch().

Referenced by C4ComponentHost::GetDataSize(), C4DefList::Load(), C4ScenarioListLoader::Entry::Load(), and C4Game::OpenScenario().

128 {
129  const char *cptr;
130  // No good parameters
131  if (!szLanguage || !Data) return false;
132  // Search for two-letter language identifier in text body, i.e. "DE:"
133  char langindex[4] = "";
134  for (int clseg=0; SCopySegment(szLanguage ? szLanguage : "", clseg, langindex, ',', 2); clseg++)
135  {
136  SAppend(":",langindex);
137  if ((cptr = SSearch(Data.getData(),langindex)))
138  {
139  // Return the according string
140  int iEndPos = SCharPos('\r', cptr);
141  if (iEndPos<0) iEndPos = SCharPos('\n', cptr);
142  if (iEndPos<0) iEndPos = strlen(cptr);
143  rTarget.Copy(cptr, iEndPos);
144  return true;
145  }
146  }
147  // Language string not found
148  return false;
149 }
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:257
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:273
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363
StdCopyStrBuf Data
const char * getData() const
Definition: StdBuf.h:442
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:233
void Copy()
Definition: StdBuf.h:467
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPropList() [1/2]

const C4PropListStatic* C4ScriptHost::GetPropList ( ) const
inlineinherited

Definition at line 51 of file C4ScriptHost.h.

References C4ScriptHost::GetPropList().

Referenced by C4ScriptHost::GetPropList().

51 { return const_cast<C4ScriptHost*>(this)->GetPropList(); }
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPropList() [2/2]

C4PropListStatic * C4GameScriptHost::GetPropList ( )
overridevirtual

Reimplemented from C4ScriptHost.

Definition at line 378 of file C4ScriptHost.cpp.

References C4Value::_getPropList(), C4PropList::IsStatic(), and ScenPrototype.

Referenced by C4AulExec::DirectExec().

379 {
381  return p ? p->IsStatic() : nullptr;
382 }
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:85
C4PropList * _getPropList() const
Definition: C4Value.h:129
C4Value ScenPrototype
Definition: C4ScriptHost.h:164
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetScript()

const char* C4ScriptHost::GetScript ( ) const
inlineinherited

Definition at line 52 of file C4ScriptHost.h.

References StdStrBuf::getData(), and C4ScriptHost::Script.

Referenced by C4AulParseError::C4AulParseError(), C4AulScriptFunc::GetLineOfCode(), and C4ScriptHost::Warn().

52 { return Script.getData(); }
const char * getData() const
Definition: StdBuf.h:442
StdStrBuf Script
Definition: C4ScriptHost.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsReady()

bool C4ScriptHost::IsReady ( )
inlineinherited

Definition at line 53 of file C4ScriptHost.h.

References ASS_PARSED, C4ScriptHost::State, C4ScriptGuiWindowPropertyName::text, and C4ScriptHost::Translate().

Referenced by C4GUI::FrameDecoration::SetByDef().

53 { return State == ASS_PARSED; } // whether script calls may be done
C4AulScriptState State
Definition: C4ScriptHost.h:93
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsWarningEnabled()

bool C4ScriptHost::IsWarningEnabled ( const char *  pos,
C4AulWarningId  warning 
) const
inherited

Definition at line 1795 of file C4AulParse.cpp.

References C4AulParse::Shift().

Referenced by C4ScriptHost::Warn().

1796 {
1797  assert(!enabledWarnings.empty());
1798  if (enabledWarnings.empty())
1799  return false;
1800 
1801  // find nearest set of warnings at or before the current position
1802  auto entry = enabledWarnings.upper_bound(pos);
1803  assert(entry != enabledWarnings.begin());
1804  if (entry != enabledWarnings.begin())
1805  {
1806  --entry;
1807  }
1808 
1809  return entry->second.test(static_cast<size_t>(warning));
1810 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Load() [1/3]

bool C4ComponentHost::Load ( C4Group hGroup,
const char *  szFilename,
const char *  szLanguage = nullptr 
)
inherited

Definition at line 23 of file C4ComponentHost.cpp.

References _MAX_FNAME, C4ComponentHost::Clear(), StdStrBuf::Copy(), C4ComponentHost::CopyFilePathFromGroup(), C4ComponentHost::Data, C4ComponentHost::Filename, C4ComponentHost::FinishLoad(), StdStrBuf::Format(), StdStrBuf::getData(), StdStrBuf::getMData(), C4Group::LoadEntryString(), SCopySegment(), SReplaceChar(), and SSearch().

Referenced by C4Game::CompileRuntimeData(), C4ComponentHost::GetDataSize(), C4Game::InitScriptEngine(), C4ScriptHost::Load(), C4Language::LoadComponentHost(), and C4Game::LoadScenarioComponents().

26 {
27  // Clear any old stuff
28  Clear();
29  // Store filename
30  if (fname)
31  Filename.Copy(fname);
32  // Load component - try all segmented filenames
33  char strEntry[_MAX_FNAME+1];
34  StdStrBuf strEntryWithLanguage;
35  for (int iFilename = 0; SCopySegment(Filename.getData(), iFilename, strEntry, '|'); iFilename++)
36  {
37  // Try to insert all language codes provided into the filename
38  char strCode[3] = "";
39  for (int iLang = 0; SCopySegment(szLanguage ? szLanguage : "", iLang, strCode, ',', 2); iLang++)
40  {
41  // Insert language code
42  strEntryWithLanguage.Format(strEntry, strCode);
43  if (hGroup.LoadEntryString(strEntryWithLanguage, &Data))
44  {
45  FinishLoad(strEntryWithLanguage, hGroup);
46  // Got it
47  return true;
48  }
49  // Couldn't insert language code anyway - no point in trying other languages
50  if (!SSearch(strEntry, "%s")) break;
51  }
52  }
53  // Truncate any additional segments from stored filename
54  SReplaceChar(Filename.getMData(), '|', 0);
55  CopyFilePathFromGroup(hGroup);
56  // Not loaded
57  return false;
58 }
void FinishLoad(const StdStrBuf &, C4Group &hGroup)
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:273
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
void CopyFilePathFromGroup(const C4Group &hGroup)
char * getMData()
Definition: StdBuf.h:443
StdCopyStrBuf Data
#define _MAX_FNAME
const char * getData() const
Definition: StdBuf.h:442
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
StdCopyStrBuf Filename
void Copy()
Definition: StdBuf.h:467
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:348
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Load() [2/3]

bool C4ComponentHost::Load ( C4GroupSet hGroupSet,
const char *  szFilename,
const char *  szLanguage = nullptr 
)
inherited

Definition at line 60 of file C4ComponentHost.cpp.

References _MAX_FNAME, C4ComponentHost::Clear(), StdStrBuf::Copy(), C4ComponentHost::CopyFilePathFromGroup(), C4ComponentHost::Data, C4ComponentHost::Filename, C4GroupSet::FindEntry(), C4ComponentHost::FinishLoad(), StdStrBuf::Format(), StdStrBuf::getData(), C4GroupSet::GetGroup(), StdStrBuf::getMData(), C4GroupSet::LoadEntryString(), SCopySegment(), SReplaceChar(), and SSearch().

63 {
64  // Clear any old stuff
65  Clear();
66  // Store filename
67  if (fname)
68  Filename.Copy(fname);
69  // Load component - try all segmented filenames
70  char strEntry[_MAX_FNAME+1];
71  StdStrBuf strEntryWithLanguage;
72  for (int iFilename = 0; SCopySegment(Filename.getData(), iFilename, strEntry, '|'); iFilename++)
73  {
74  // Try to insert all language codes provided into the filename
75  char strCode[3] = "";
76  for (int iLang = 0; SCopySegment(szLanguage ? szLanguage : "", iLang, strCode, ',', 2); iLang++)
77  {
78  // Insert language code
79  strEntryWithLanguage.Format(strEntry, strCode);
80  if (hGroupSet.LoadEntryString(strEntryWithLanguage, &Data))
81  {
82  C4Group *pGroup = hGroupSet.FindEntry(strEntryWithLanguage.getData());
83  FinishLoad(strEntryWithLanguage, *pGroup);
84  // Got it
85  return true;
86  }
87  // Couldn't insert language code anyway - no point in trying other languages
88  if (!SSearch(strEntry, "%s")) break;
89  }
90  }
91  // Truncate any additional segments from stored filename
92  SReplaceChar(Filename.getMData(), '|', 0);
93  // for error message purposes, the first group failed to provide the desired file
94  CopyFilePathFromGroup(*hGroupSet.GetGroup(0));
95  // Not loaded
96  return false;
97 }
void FinishLoad(const StdStrBuf &, C4Group &hGroup)
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:273
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:363
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174
void CopyFilePathFromGroup(const C4Group &hGroup)
char * getMData()
Definition: StdBuf.h:443
StdCopyStrBuf Data
C4Group * FindEntry(const char *szWildcard, int32_t *pPriority=nullptr, int32_t *pID=nullptr)
Definition: C4GroupSet.cpp:175
#define _MAX_FNAME
const char * getData() const
Definition: StdBuf.h:442
bool LoadEntryString(const char *szEntryName, StdStrBuf *rBuf)
Definition: C4GroupSet.cpp:225
StdCopyStrBuf Filename
void Copy()
Definition: StdBuf.h:467
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:348
C4Group * GetGroup(int32_t iIndex)
Definition: C4GroupSet.cpp:259
Here is the call graph for this function:

◆ Load() [3/3]

bool C4GameScriptHost::Load ( C4Group g,
const char *  f,
const char *  l,
C4LangStringTable t 
)
overridevirtual

Reimplemented from C4ScriptHost.

Definition at line 348 of file C4ScriptHost.cpp.

References C4AulScriptEngine::GetPropList(), C4ScriptHost::Load(), C4StringTable::P, P_Scenario, C4ScriptHost::Reg2List(), C4AulScriptEngine::RegisterGlobalConstant(), ScenPropList, ScenPrototype, ScriptEngine, C4Value::SetPropList(), and Strings.

Referenced by c4_mapgen_handle_new().

349 {
350  assert(ScriptEngine.GetPropList());
351  C4PropListStatic * pScen = new C4PropListScen(nullptr, &::Strings.P[P_Scenario]);
352  ScenPropList.SetPropList(pScen);
354  ScenPrototype.SetPropList(pScen->GetPrototype());
356  return C4ScriptHost::Load(g, f, l, t);
357 }
C4String P[P_LAST]
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
Definition: C4Aul.cpp:123
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
void Reg2List(C4AulScriptEngine *pEngine)
C4StringTable Strings
Definition: C4Globals.cpp:42
C4Value ScenPropList
Definition: C4ScriptHost.h:163
C4Value ScenPrototype
Definition: C4ScriptHost.h:164
void SetPropList(C4PropList *PropList)
Definition: C4Value.h:141
virtual bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadData()

bool C4GameScriptHost::LoadData ( const char *  f,
const char *  d,
C4LangStringTable t 
)
overridevirtual

Reimplemented from C4ScriptHost.

Definition at line 359 of file C4ScriptHost.cpp.

References C4AulScriptEngine::GetPropList(), C4ScriptHost::LoadData(), C4StringTable::P, P_Scenario, C4ScriptHost::Reg2List(), C4AulScriptEngine::RegisterGlobalConstant(), ScenPropList, ScenPrototype, ScriptEngine, C4Value::SetPropList(), and Strings.

Referenced by c4_mapgen_handle_new_script().

360 {
361  assert(ScriptEngine.GetPropList());
362  C4PropListStatic * pScen = new C4PropListScen(nullptr, &::Strings.P[P_Scenario]);
363  ScenPropList.SetPropList(pScen);
365  ScenPrototype.SetPropList(pScen->GetPrototype());
367  return C4ScriptHost::LoadData(f, d, t);
368 }
C4String P[P_LAST]
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
Definition: C4Aul.cpp:123
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
void Reg2List(C4AulScriptEngine *pEngine)
C4StringTable Strings
Definition: C4Globals.cpp:42
C4Value ScenPropList
Definition: C4ScriptHost.h:163
virtual bool LoadData(const char *szFilename, const char *szData, class C4LangStringTable *pLocalTable)
C4Value ScenPrototype
Definition: C4ScriptHost.h:164
void SetPropList(C4PropList *PropList)
Definition: C4Value.h:141
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeScript()

void C4ScriptHost::MakeScript ( )
protectedinherited

Definition at line 206 of file C4ScriptHost.cpp.

References StdStrBuf::Clear(), C4ComponentHost::GetDataBuf(), C4ScriptHost::Preparse(), StdStrBuf::Ref(), C4LangStringTable::ReplaceStrings(), C4ScriptHost::Script, and C4ScriptHost::stringTable.

Referenced by C4ScriptHost::Load().

207 {
208  // clear prev
209  Script.Clear();
210 
211  // create script
212  if (stringTable)
213  {
215  }
216  else
217  {
218  Script.Ref(GetDataBuf());
219  }
220 
221  // preparse script
222  Preparse();
223 }
void Clear()
Definition: StdBuf.h:466
void ReplaceStrings(StdStrBuf &rBuf)
void Ref(const char *pnData)
Definition: StdBuf.h:455
bool Preparse()
Definition: C4AulParse.cpp:692
const StdStrBuf & GetDataBuf() const
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
StdStrBuf Script
Definition: C4ScriptHost.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnLoad()

virtual void C4ComponentHost::OnLoad ( )
inlineprotectedvirtualinherited

Reimplemented in C4LangStringTable.

Definition at line 39 of file C4ComponentHost.h.

Referenced by C4ComponentHost::Clear(), and C4ComponentHost::FinishLoad().

39 {}
Here is the caller graph for this function:

◆ Parse()

bool C4ScriptHost::Parse ( )
protectedvirtualinherited

Reimplemented in C4DefScriptHost.

Definition at line 1743 of file C4AulParse.cpp.

References C4ScriptHost::Appends, ASS_LINKED, ASS_PARSED, C4AulCompiler::Compile(), C4ScriptHost::CopyPropList(), C4ScriptHost::Engine, StdStrBuf::getData(), C4PropList::GetDef(), StdStrBuf::getLength(), C4ScriptHost::GetPropList(), StdStrBuf::getPtr(), C4Def::IncludeDefinition(), C4AulScriptEngine::lineCnt, s, C4ScriptHost::Script, SGetLine(), C4ScriptHost::SourceScripts, and C4ScriptHost::State.

Referenced by C4DefScriptHost::Parse(), and C4DefScriptHost::SetDef().

1744 {
1745  // check state
1746  if (State != ASS_LINKED) return false;
1747 
1748  if (!Appends.empty())
1749  {
1750  // #appendto scripts are not allowed to contain global functions or belong to definitions
1751  // so their contents are not reachable
1752  return true;
1753  }
1754 
1755  C4PropListStatic * p = GetPropList();
1756 
1757  for (auto & SourceScript : SourceScripts)
1758  {
1759  CopyPropList(SourceScript->LocalValues, p);
1760  if (SourceScript == this)
1761  continue;
1762  // definition appends
1763  if (GetPropList() && GetPropList()->GetDef() && SourceScript->GetPropList() && SourceScript->GetPropList()->GetDef())
1764  GetPropList()->GetDef()->IncludeDefinition(SourceScript->GetPropList()->GetDef());
1765  }
1766 
1767  // generate bytecode
1768  for (auto &s : SourceScripts)
1769  C4AulCompiler::Compile(this, s, s->ast.get());
1770 
1771  // save line count
1773 
1774  // finished
1775  State = ASS_PARSED;
1776 
1777  return true;
1778 }
int SGetLine(const char *szText, const char *cpPosition)
Definition: Standard.cpp:473
std::list< StdCopyStrBuf > Appends
Definition: C4ScriptHost.h:80
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:50
void IncludeDefinition(C4Def *pIncludeDef)
Definition: C4Def.cpp:631
void CopyPropList(C4Set< C4Property > &from, C4PropListStatic *to)
static void Compile(C4AulScriptFunc *out, const ::aul::ast::Function *f)
const char * getData() const
Definition: StdBuf.h:442
const char * getPtr(size_t i) const
Definition: StdBuf.h:448
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:685
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56
size_t getLength() const
Definition: StdBuf.h:445
#define s
C4AulScriptState State
Definition: C4ScriptHost.h:93
StdStrBuf Script
Definition: C4ScriptHost.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Preparse()

bool C4ScriptHost::Preparse ( )
protectedinherited

Definition at line 692 of file C4AulParse.cpp.

References C4ScriptHost::AddEngineFunctions(), C4ScriptHost::Appends, ASS_NONE, ASS_PREPARSED, C4VPropList(), C4Set< T >::Clear(), C4ScriptHost::Engine, StdStrBuf::getData(), C4ScriptHost::GetPropList(), C4AulScriptEngine::GetPropList(), C4ScriptHost::Includes, C4ScriptHost::IncludesResolved, C4ScriptHost::LocalValues, P_Prototype, C4AulParse::Parse_Script(), C4AulCompiler::Preparse(), C4ScriptHost::Script, C4PropList::SetProperty(), and C4ScriptHost::State.

Referenced by C4ScriptHost::LoadData(), and C4ScriptHost::MakeScript().

693 {
694  // handle easiest case first
695  if (State < ASS_NONE) return false;
696 
697  // clear stuff
698  Includes.clear(); Appends.clear();
699 
700  GetPropList()->C4PropList::Clear();
702  LocalValues.Clear();
703 
704  // Add any engine functions specific to this script
706 
707  // Insert default warnings
708  assert(enabledWarnings.empty());
709  auto &warnings = enabledWarnings[Script.getData()];
710 #define DIAG(id, text, enabled) warnings.set(static_cast<size_t>(C4AulWarningId::id), enabled);
711 #include "C4AulWarnings.h"
712 #undef DIAG
713 
714  C4AulParse parser(this);
715  ast = parser.Parse_Script(this);
716 
717  C4AulCompiler::Preparse(this, this, ast.get());
718 
719  // #include will have to be resolved now...
720  IncludesResolved = false;
721 
722  // Parse will write the properties back after the ones from included scripts
723  GetPropList()->Properties.Swap(&LocalValues);
724 
725  // return success
726  this->State = ASS_PREPARSED;
727  return true;
728 }
bool IncludesResolved
Definition: C4ScriptHost.h:88
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
std::list< StdCopyStrBuf > Appends
Definition: C4ScriptHost.h:80
static void Preparse(C4ScriptHost *out, C4ScriptHost *source, const ::aul::ast::Script *s)
void SetProperty(C4PropertyName k, const C4Value &to)
Definition: C4PropList.h:120
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
void Clear()
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:50
virtual void AddEngineFunctions()
Definition: C4ScriptHost.h:82
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:245
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:79
const char * getData() const
Definition: StdBuf.h:442
C4Set< C4Property > LocalValues
Definition: C4ScriptHost.h:92
C4AulScriptState State
Definition: C4ScriptHost.h:93
StdStrBuf Script
Definition: C4ScriptHost.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reg2List()

void C4ScriptHost::Reg2List ( C4AulScriptEngine pEngine)
inherited

Definition at line 144 of file C4ScriptHost.cpp.

References C4AulScriptEngine::Child0, C4AulScriptEngine::ChildL, C4ScriptHost::Engine, C4ScriptHost::Next, and C4ScriptHost::Prev.

Referenced by C4ScriptHost::Delete(), C4Game::InitScriptEngine(), Load(), C4Def::Load(), C4Game::LoadAdditionalSystemGroup(), LoadData(), and C4ScenarioSection::ScenarioLoad().

145 {
146  // already regged? (def reloaded)
147  if (Engine) return;
148  // reg to list
149  if ((Engine = pEngine))
150  {
151  if ((Prev = Engine->ChildL))
152  Prev->Next = this;
153  else
154  Engine->Child0 = this;
155  Engine->ChildL = this;
156  }
157  else
158  Prev = nullptr;
159  Next = nullptr;
160 }
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
C4ScriptHost * ChildL
Definition: C4Aul.h:121
C4ScriptHost * Next
Definition: C4ScriptHost.h:77
C4ScriptHost * Prev
Definition: C4ScriptHost.h:77
C4ScriptHost * Child0
Definition: C4Aul.h:121
Here is the caller graph for this function:

◆ ReloadScript()

bool C4ScriptHost::ReloadScript ( const char *  szPath,
const char *  szLanguage 
)
protectedvirtualinherited

Definition at line 225 of file C4ScriptHost.cpp.

References _MAX_PATH, C4ComponentHost::GetFilePath(), GetParentPath(), C4ScriptHost::Load(), C4Group::Open(), SEqualNoCase(), and C4ScriptHost::stringTable.

Referenced by C4AulScriptEngine::ReloadScript().

226 {
227  // this?
228  if (SEqualNoCase(szPath, GetFilePath()) || (stringTable && SEqualNoCase(szPath, stringTable->GetFilePath())))
229  {
230  // try reload
231  char szParentPath[_MAX_PATH + 1]; C4Group ParentGrp;
232  if (GetParentPath(szPath, szParentPath))
233  if (ParentGrp.Open(szParentPath))
234  if (Load(ParentGrp, nullptr, szLanguage, stringTable))
235  return true;
236  }
237  return false;
238 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:207
#define _MAX_PATH
const char * GetFilePath() const
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:189
bool Open(const char *szGroupName, bool fCreate=false)
Definition: C4Group.cpp:514
virtual bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResolveAppends()

bool C4ScriptHost::ResolveAppends ( C4DefList rDefs)
protectedinherited

Definition at line 46 of file C4AulLink.cpp.

References C4ScriptHost::Appends, ASS_PREPARSED, C4ScriptHost::DoAppend(), C4DefList::GetByName(), C4DefList::GetDef(), C4DefList::GetDefCount(), C4ScriptHost::GetPropList(), C4ScriptHost::State, and C4ScriptHost::Warn().

Referenced by C4ScriptHost::AddEngineFunctions().

47 {
48  // resolve local appends
49  if (State != ASS_PREPARSED) return false;
50  for (auto & Append : Appends)
51  {
52  if (Append != "*" || !rDefs)
53  {
54  C4Def *Def = rDefs ? rDefs->GetByName(Append) : nullptr;
55  if (Def)
56  {
57  DoAppend(Def);
58  }
59  else
60  {
61  // save id in buffer because AulWarn will use the buffer of C4IdText
62  // to get the id of the object in which the error occurs...
63  // (stupid static buffers...)
64  Warn("#appendto %s not found", Append.getData());
65  }
66  }
67  else
68  {
69  // append to all defs
70  for (int i = 0; i < rDefs->GetDefCount(); i++)
71  {
72  C4Def *pDef = rDefs->GetDef(i);
73  if (!pDef) break;
74  if (pDef == GetPropList()) continue;
75  // append
76  DoAppend(pDef);
77  }
78  }
79  }
80  return true;
81 }
C4Def * GetDef(int32_t Index)
std::list< StdCopyStrBuf > Appends
Definition: C4ScriptHost.h:80
int32_t GetDefCount()
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:50
void DoAppend(C4Def *def)
Definition: C4AulLink.cpp:28
Definition: C4Def.h:98
C4Def * GetByName(const StdStrBuf &)
void Warn(const char *pMsg,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: C4AulParse.cpp:123
C4AulScriptState State
Definition: C4ScriptHost.h:93
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResolveIncludes()

bool C4ScriptHost::ResolveIncludes ( C4DefList rDefs)
protectedinherited

Definition at line 83 of file C4AulLink.cpp.

References ASS_LINKED, ASS_PREPARSED, C4ScriptHost::Engine, C4DefList::GetByName(), C4AulScriptEngine::GetErrorHandler(), C4ScriptHost::Includes, C4ScriptHost::IncludesResolved, C4AulErrorHandler::OnError(), C4ScriptHost::ResolveIncludes(), C4ScriptHost::Resolving, s, C4Def::Script, C4ScriptHost::SourceScripts, C4ScriptHost::State, and C4ScriptHost::Warn().

Referenced by C4ScriptHost::AddEngineFunctions(), and C4ScriptHost::ResolveIncludes().

84 {
85  // Had been preparsed?
86  if (State != ASS_PREPARSED) return false;
87  // has already been resolved?
88  if (IncludesResolved) return true;
89  // catch circular includes
90  if (Resolving)
91  {
92  Engine->GetErrorHandler()->OnError(C4AulParseError(this, "Circular include chain detected - ignoring all includes!").what());
93  IncludesResolved = true;
94  State = ASS_LINKED;
95  return false;
96  }
97  Resolving=true;
98  // append all includes to local script
99  for (std::list<StdCopyStrBuf>::reverse_iterator i = Includes.rbegin(); i != Includes.rend(); ++i)
100  {
101  C4Def *Def = rDefs ? rDefs->GetByName(*i) : nullptr;
102  if (Def)
103  {
104  // resolve #includes in included script first (#include-chains :( )
105  if (!Def->Script.IncludesResolved)
106  if (!Def->Script.ResolveIncludes(rDefs))
107  continue; // skip this #include
108 
109  for (std::list<C4ScriptHost *>::reverse_iterator s = Def->Script.SourceScripts.rbegin(); s != Def->Script.SourceScripts.rend(); ++s)
110  {
111  if (std::find(SourceScripts.begin(), SourceScripts.end(), *s) == SourceScripts.end())
112  SourceScripts.push_front(*s);
113  }
114  }
115  else
116  {
117  // save id in buffer because AulWarn will use the buffer of C4IdText
118  // to get the id of the object in which the error occurs...
119  // (stupid static buffers...)
120  Warn("#include %s not found", i->getData());
121  }
122  }
123  IncludesResolved = true;
124  // includes/appends are resolved now (for this script)
125  Resolving=false;
126  State = ASS_LINKED;
127  return true;
128 }
bool IncludesResolved
Definition: C4ScriptHost.h:88
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:79
Definition: C4Def.h:98
bool ResolveIncludes(C4DefList *rDefs)
Definition: C4AulLink.cpp:83
C4Def * GetByName(const StdStrBuf &)
virtual void OnError(const char *msg)=0
void Warn(const char *pMsg,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: C4AulParse.cpp:123
C4DefScriptHost Script
Definition: C4Def.h:181
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56
#define s
C4AulScriptState State
Definition: C4ScriptHost.h:93
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Translate()

std::string C4ScriptHost::Translate ( const std::string &  text) const
inherited

Definition at line 240 of file C4ScriptHost.cpp.

References C4ScriptHost::stringTable, and C4LangStringTable::Translate().

Referenced by C4ScriptHost::IsReady().

241 {
242  if (stringTable)
243  return stringTable->Translate(text);
245 }
const std::string & Translate(const std::string &text) const
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnLink()

void C4ScriptHost::UnLink ( )
protectedvirtualinherited

Definition at line 130 of file C4AulLink.cpp.

References ASS_PREPARSED, C4VPropList(), C4ScriptHost::DeleteOwnedPropLists(), C4ScriptHost::Engine, C4ScriptHost::GetPropList(), C4AulScriptEngine::GetPropList(), C4ScriptHost::IncludesResolved, P_Prototype, C4PropList::SetProperty(), and C4ScriptHost::State.

Referenced by C4AulScriptEngine::ReLink().

131 {
132  C4PropList * p = GetPropList();
133  if (p)
134  {
135  p->C4PropList::Clear();
137  }
138 
139  // Delete cyclic references of owned proplists
141 
142  // includes will have to be re-resolved now
143  IncludesResolved = false;
144 
146 }
bool IncludesResolved
Definition: C4ScriptHost.h:88
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
void SetProperty(C4PropertyName k, const C4Value &to)
Definition: C4PropList.h:120
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:50
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:245
void DeleteOwnedPropLists()
C4AulScriptState State
Definition: C4ScriptHost.h:93
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnlinkOwnedFunctions()

void C4ScriptHost::UnlinkOwnedFunctions ( )
protectedinherited

Definition at line 72 of file C4ScriptHost.cpp.

References C4V_Function, C4VFunction(), C4Value::getFunction(), C4PropList::GetPropertyByS(), C4ScriptHost::GetPropList(), C4ScriptHost::ownedFunctions, C4AulScriptFunc::OwnerOverloaded, C4PropList::ResetProperty(), ScriptEngine, C4PropList::SetPropertyByS(), C4AulFunc::SFunc(), C4AulScriptFunc::SFunc(), and C4PropList::Thaw().

Referenced by C4ScriptHost::Clear().

73 {
74  // Remove owned functions from their parents. This solves a problem
75  // where overloading a definition would unload the C4ScriptHost, but
76  // keep around global functions, which then contained dangling pointers.
77  for (const auto &box : ownedFunctions)
78  {
79  assert(box.GetType() == C4V_Function);
80  C4AulScriptFunc *func = box._getFunction()->SFunc();
81  C4PropList *parent = func->Parent;
82  if (parent == GetPropList())
83  continue;
84  assert(parent == &::ScriptEngine);
85  C4Value v;
86  parent->GetPropertyByS(func->Name, &v);
87  if (v.getFunction() == func)
88  {
89  // If the function we're deleting is the top-level function in
90  // the inheritance chain, promote the next one in its stead;
91  // if there is no overloaded function, remove the property.
92  parent->Thaw();
93  if (func->OwnerOverloaded)
94  parent->SetPropertyByS(func->Name, C4VFunction(func->OwnerOverloaded));
95  else
96  parent->ResetProperty(func->Name);
97  }
98  else
99  {
100  C4AulScriptFunc *func_chain = v.getFunction()->SFunc();
101  assert(func_chain != func);
102  while (func_chain)
103  {
104  // Unlink the removed function from the inheritance chain
105  if (func_chain->OwnerOverloaded == func)
106  {
107  func_chain->OwnerOverloaded = func->OwnerOverloaded;
108  break;
109  }
110  assert(func_chain->OwnerOverloaded && "Removed function not found in inheritance chain");
111  func_chain = func_chain->OwnerOverloaded->SFunc();
112  }
113  }
114  }
115  ownedFunctions.clear();
116 }
virtual void ResetProperty(C4String *k)
Definition: C4PropList.cpp:992
void Thaw()
Definition: C4PropList.h:129
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:50
C4AulFunc * OwnerOverloaded
C4AulFunc * getFunction() const
Definition: C4Value.h:119
C4AulScriptFunc * SFunc() override
C4Value C4VFunction(C4AulFunc *pFn)
Definition: C4Value.h:250
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:971
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:757
virtual C4AulScriptFunc * SFunc()
Definition: C4AulFunc.h:65
std::vector< C4Value > ownedFunctions
Definition: C4ScriptHost.h:96
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unreg()

void C4ScriptHost::Unreg ( )
protectedinherited

Definition at line 135 of file C4ScriptHost.cpp.

References C4AulScriptEngine::Child0, C4AulScriptEngine::ChildL, C4ScriptHost::Engine, C4ScriptHost::Next, and C4ScriptHost::Prev.

Referenced by C4AulScriptEngine::Clear(), and C4ScriptHost::~C4ScriptHost().

136 {
137  // remove from list
138  if (Prev) Prev->Next = Next; else if (Engine) Engine->Child0 = Next;
139  if (Next) Next->Prev = Prev; else if (Engine) Engine->ChildL = Prev;
140  Prev = Next = nullptr;
141  Engine = nullptr;
142 }
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
C4ScriptHost * ChildL
Definition: C4Aul.h:121
C4ScriptHost * Next
Definition: C4ScriptHost.h:77
C4ScriptHost * Prev
Definition: C4ScriptHost.h:77
C4ScriptHost * Child0
Definition: C4Aul.h:121
Here is the caller graph for this function:

◆ Warn()

void C4ScriptHost::Warn ( const char *  pMsg,
  ... 
)
protectedinherited

Definition at line 123 of file C4AulParse.cpp.

References StdStrBuf::AppendChar(), StdStrBuf::AppendFormat(), C4AulParse::C4AulParseError, C4AulWarningIDs, C4AulWarningMessages, C4ScriptHost::Engine, FormatStringV(), StdStrBuf::FormatV(), StdStrBuf::getData(), C4AulScriptEngine::GetErrorHandler(), C4AulFunc::GetName(), C4ScriptHost::GetScript(), C4ScriptHost::IsWarningEnabled(), C4AulErrorHandler::OnWarning(), C4AulScriptFunc::pOrgScript, C4ScriptHost::ScriptName, SGetLine(), and SLineGetCharacters().

Referenced by C4ScriptHost::DoAppend(), C4DefScriptHost::Parse(), C4AulParse::Parse_Array(), C4AulParse::Parse_Statement(), C4ScriptHost::ResolveAppends(), and C4ScriptHost::ResolveIncludes().

124 {
125  va_list args; va_start(args, pMsg);
126  StdStrBuf Buf = FormatStringV(pMsg, args);
127  Buf.AppendFormat(" (%s)", ScriptName.getData());
129  va_end(args);
130 }
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190
StdStrBuf FormatStringV(const char *szFmt, va_list args)
Definition: StdBuf.cpp:276
const char * getData() const
Definition: StdBuf.h:442
virtual void OnWarning(const char *msg)=0
StdCopyStrBuf ScriptName
Definition: C4ScriptHost.h:57
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Appends

◆ Data

◆ Engine

◆ Filename

StdCopyStrBuf C4ComponentHost::Filename
protectedinherited

◆ FilePath

StdCopyStrBuf C4ComponentHost::FilePath
protectedinherited

◆ Includes

◆ IncludesResolved

bool C4ScriptHost::IncludesResolved
protectedinherited

◆ LocalValues

C4Set<C4Property> C4ScriptHost::LocalValues
protectedinherited

Definition at line 92 of file C4ScriptHost.h.

Referenced by C4ScriptHost::Clear(), and C4ScriptHost::Preparse().

◆ Next

C4ScriptHost * C4ScriptHost::Next {nullptr}
protectedinherited

◆ ownedFunctions

std::vector<C4Value> C4ScriptHost::ownedFunctions
protectedinherited

◆ ownedPropLists

std::vector<C4Value> C4ScriptHost::ownedPropLists
protectedinherited

Definition at line 101 of file C4ScriptHost.h.

Referenced by C4ScriptHost::DeleteOwnedPropLists().

◆ Prev

C4ScriptHost* C4ScriptHost::Prev {nullptr}
protectedinherited

Definition at line 77 of file C4ScriptHost.h.

Referenced by C4ScriptHost::Reg2List(), and C4ScriptHost::Unreg().

◆ pScenarioEffects

◆ Resolving

bool C4ScriptHost::Resolving
protectedinherited

Definition at line 87 of file C4ScriptHost.h.

Referenced by C4ScriptHost::C4ScriptHost(), and C4ScriptHost::ResolveIncludes().

◆ ScenPropList

◆ ScenPrototype

C4Value C4GameScriptHost::ScenPrototype

Definition at line 164 of file C4ScriptHost.h.

Referenced by Clear(), C4Value::CompileFunc(), GetPropList(), Load(), and LoadData().

◆ Script

◆ ScriptName

◆ SourceScripts

std::list<C4ScriptHost *> C4ScriptHost::SourceScripts
inherited

◆ State

◆ stringTable


The documentation for this class was generated from the following files: