OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ScriptHost Class Reference

#include <C4ScriptHost.h>

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

Public Member Functions

virtual ~C4ScriptHost ()
 
virtual bool Delete ()
 
void Clear ()
 
virtual bool Load (C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)
 
virtual bool LoadData (const char *szFilename, const char *szData, class C4LangStringTable *pLocalTable)
 
void Reg2List (C4AulScriptEngine *pEngine)
 
virtual C4PropListStaticGetPropList ()
 
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 Load (C4Group &hGroup, const char *szFilename, const char *szLanguage=nullptr)
 
bool Load (C4GroupSet &hGroupSet, const char *szFilename, const char *szLanguage=nullptr)
 
bool GetLanguageString (const char *szLanguage, StdStrBuf &rTarget)
 

Public Attributes

std::list< C4ScriptHost * > SourceScripts
 
StdCopyStrBuf ScriptName
 

Protected Member Functions

 C4ScriptHost ()
 
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
 
C4ScriptHostPrev
 
C4ScriptHostNext
 
std::list< StdCopyStrBufIncludes
 
std::list< StdCopyStrBufAppends
 
bool Resolving
 
bool IncludesResolved
 
StdStrBuf Script
 
C4LangStringTablestringTable
 
C4Set< C4PropertyLocalValues
 
C4AulScriptState State
 
std::vector< C4ValueownedFunctions
 
std::vector< C4ValueownedPropLists
 
StdCopyStrBuf Data
 
StdCopyStrBuf Filename
 
StdCopyStrBuf FilePath
 

Friends

class C4AulParse
 
class C4AulProfiler
 
class C4AulScriptEngine
 
class C4AulDebug
 
class C4AulCompiler
 
class C4AulScriptFunc
 

Detailed Description

Definition at line 39 of file C4ScriptHost.h.

Constructor & Destructor Documentation

C4ScriptHost::~C4ScriptHost ( )
virtual

Definition at line 48 of file C4ScriptHost.cpp.

References Clear(), and Unreg().

49 {
50  Unreg();
51  Clear();
52 }

Here is the call graph for this function:

C4ScriptHost::C4ScriptHost ( )
protected

Definition at line 33 of file C4ScriptHost.cpp.

References Appends, Includes, IncludesResolved, Resolving, Script, SourceScripts, and stringTable.

33  :
34  // prepare lists
35  Prev(nullptr), Next(nullptr),
36  Engine(nullptr),
37  State(ASS_NONE) // not compiled
38 {
39  Script = nullptr;
40  stringTable = 0;
41  SourceScripts.push_back(this);
42  // prepare include list
43  IncludesResolved = false;
44  Resolving=false;
45  Includes.clear();
46  Appends.clear();
47 }
bool IncludesResolved
Definition: C4ScriptHost.h:88
std::list< StdCopyStrBuf > Appends
Definition: C4ScriptHost.h:80
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:79
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
C4AulScriptState State
Definition: C4ScriptHost.h:93
C4ScriptHost * Next
Definition: C4ScriptHost.h:77
C4ScriptHost * Prev
Definition: C4ScriptHost.h:77
StdStrBuf Script
Definition: C4ScriptHost.h:90

Member Function Documentation

virtual void C4ScriptHost::AddEngineFunctions ( )
inlineprotectedvirtual

Reimplemented in C4MapScriptHost.

Definition at line 82 of file C4ScriptHost.h.

Referenced by Preparse().

82 {}; // add any engine functions specific to this script host

Here is the caller graph for this function:

void C4ScriptHost::Clear ( )

Definition at line 54 of file C4ScriptHost.cpp.

References Appends, ASS_NONE, C4ComponentHost::Clear(), C4Set< T >::Clear(), StdStrBuf::Clear(), DeleteOwnedPropLists(), C4LangStringTable::DelRef(), Includes, LocalValues, Script, SourceScripts, State, stringTable, and UnlinkOwnedFunctions().

Referenced by C4Def::C4Def(), C4ExtraScriptHost::Clear(), C4GameScriptHost::Clear(), C4Def::Clear(), C4MapScriptHost::Clear(), C4Def::Default(), C4Def::~C4Def(), and ~C4ScriptHost().

55 {
58  ast.reset();
59  Script.Clear();
62  SourceScripts.clear();
63  SourceScripts.push_back(this);
64  if (stringTable)
65  {
67  stringTable = nullptr;
68  }
69  // remove includes
70  Includes.clear();
71  Appends.clear();
72  // reset flags
73  State = ASS_NONE;
74  enabledWarnings.clear();
75 }
void Clear()
Definition: StdBuf.h:474
std::list< StdCopyStrBuf > Appends
Definition: C4ScriptHost.h:80
void Clear()
void UnlinkOwnedFunctions()
void DeleteOwnedPropLists()
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:79
C4Set< C4Property > LocalValues
Definition: C4ScriptHost.h:92
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
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:

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 }
const char * getData() const
Definition: StdBuf.h:450
C4Config Config
Definition: C4Config.cpp:837
StdCopyStrBuf FilePath
void AppendBackslash()
Definition: StdBuf.cpp:255
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2078
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:527
StdCopyStrBuf Filename
const char * AtRelativePath(const char *szFilename)
Definition: C4Config.cpp:660
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1690 of file C4AulParse.cpp.

References C4Value::_getPropList(), 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 Parse().

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

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool C4ScriptHost::Delete ( )
inlinevirtual

Reimplemented in C4ExtraScriptHost.

Definition at line 43 of file C4ScriptHost.h.

43 { return false; } // do NOT delete this - it's just a class member!
void C4ScriptHost::DeleteOwnedPropLists ( )
protected

Definition at line 123 of file C4ScriptHost.cpp.

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

Referenced by Clear(), and UnLink().

124 {
125  // delete all static proplists associated to this script host.
126  // Note that just clearing the vector is not enough in case of
127  // cyclic references.
128  for (C4Value& value: ownedPropLists)
129  {
130  C4PropList* plist = value.getPropList();
131  if (plist)
132  {
133  if (plist->Delete()) delete plist;
134  else plist->Clear();
135  }
136  }
137  ownedPropLists.clear();
138 }
void Clear()
Definition: C4PropList.h:68
virtual bool Delete()
Definition: C4PropList.h:92
std::vector< C4Value > ownedPropLists
Definition: C4ScriptHost.h:101

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ScriptHost::DoAppend ( C4Def def)
protected

Definition at line 28 of file C4AulLink.cpp.

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

Referenced by 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:132
C4DefScriptHost Script
Definition: C4Def.h:184
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1776 of file C4AulParse.cpp.

1777 {
1778  auto entry = enabledWarnings.emplace(pos, decltype(enabledWarnings)::mapped_type{});
1779  if (entry.second)
1780  {
1781  // If there was no earlier entry for this position, copy the previous
1782  // warning state
1783  assert(entry.first != enabledWarnings.begin());
1784  auto previous = entry.first;
1785  --previous;
1786  entry.first->second = previous->second;
1787  }
1788  entry.first->second.set(static_cast<size_t>(warning), enable);
1789 }
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 }
const char * getData() const
Definition: StdBuf.h:450
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()
size_t getSize() const
Definition: StdBuf.h:452
bool EnsureUnicode()
Definition: StdBuf.cpp:428
void Shrink(size_t iShrink)
Definition: StdBuf.h:511
StdCopyStrBuf Filename
void Move(size_t iFrom, size_t inSize, size_t iTo=0)
Definition: StdBuf.h:479
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4ComponentHost::GetData ( ) const
inlineinherited

Definition at line 30 of file C4ComponentHost.h.

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

Referenced by C4Game::CompileRuntimeData(), C4Game::InitGame(), C4RankSystem::Load(), C4ScenarioListLoader::Entry::Load(), C4Player::LoadRuntimeData(), C4ObjectInfoList::New(), and C4Game::OpenScenario().

30 { return Data.getData(); }
const char * getData() const
Definition: StdBuf.h:450
StdCopyStrBuf Data

Here is the call graph for this function:

Here is the caller graph for this function:

const StdStrBuf& C4ComponentHost::GetDataBuf ( ) const
inlineinherited

Definition at line 31 of file C4ComponentHost.h.

References C4ComponentHost::Data.

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

31 { return Data; }
StdCopyStrBuf Data

Here is the caller graph for this function:

size_t C4ComponentHost::GetDataSize ( ) const
inlineinherited

Definition at line 32 of file C4ComponentHost.h.

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

Referenced by C4RankSystem::Load().

32 { return Data.getLength(); }
StdCopyStrBuf Data
size_t getLength() const
Definition: StdBuf.h:453

Here is the call graph for this function:

Here is the caller graph for this function:

const char* C4ComponentHost::GetFilePath ( ) const
inlineinherited

Definition at line 28 of file C4ComponentHost.h.

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

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

28 { return FilePath.getData(); }
const char * getData() const
Definition: StdBuf.h:450
StdCopyStrBuf FilePath

Here is the call graph for this function:

Here is the caller graph for this function:

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 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 }
const char * getData() const
Definition: StdBuf.h:450
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:227
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:333
StdCopyStrBuf Data
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:203
void Copy()
Definition: StdBuf.h:475

Here is the call graph for this function:

Here is the caller graph for this function:

virtual C4PropListStatic* C4ScriptHost::GetPropList ( )
inlinevirtual

Reimplemented in C4MapScriptHost, C4GameScriptHost, C4DefScriptHost, and C4ExtraScriptHost.

Definition at line 50 of file C4ScriptHost.h.

Referenced by Parse(), C4AulParse::Parse_Script(), Preparse(), ResolveAppends(), C4AulProfiler::StartProfiling(), C4AulProfiler::StopProfiling(), UnLink(), UnlinkOwnedFunctions(), C4AulCompiler::PreparseAstVisitor::visit(), C4AulCompiler::CodegenAstVisitor::visit(), C4AulCompiler::ConstexprEvaluator::visit(), and C4AulCompiler::ConstantResolver::visit().

50 { return 0; }

Here is the caller graph for this function:

const C4PropListStatic* C4ScriptHost::GetPropList ( ) const
inline

Definition at line 51 of file C4ScriptHost.h.

References GetPropList().

Referenced by 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:

const char* C4ScriptHost::GetScript ( ) const
inline

Definition at line 52 of file C4ScriptHost.h.

References StdStrBuf::getData(), and Script.

Referenced by C4AulParseError::C4AulParseError(), C4AulScriptFunc::GetLineOfCode(), and C4AulScriptContext::ReturnDump().

52 { return Script.getData(); }
const char * getData() const
Definition: StdBuf.h:450
StdStrBuf Script
Definition: C4ScriptHost.h:90

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScriptHost::IsReady ( )
inline

Definition at line 53 of file C4ScriptHost.h.

References ASS_PARSED, and State.

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 caller graph for this function:

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

Definition at line 1791 of file C4AulParse.cpp.

1792 {
1793  assert(!enabledWarnings.empty());
1794  if (enabledWarnings.empty())
1795  return false;
1796 
1797  // find nearest set of warnings at or before the current position
1798  auto entry = enabledWarnings.upper_bound(pos);
1799  assert(entry != enabledWarnings.begin());
1800  if (entry != enabledWarnings.begin())
1801  {
1802  --entry;
1803  }
1804 
1805  return entry->second.test(static_cast<size_t>(warning));
1806 }
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(), C4Game::InitScriptEngine(), Load(), C4ScenarioListLoader::Entry::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 }
const char * getData() const
Definition: StdBuf.h:450
void FinishLoad(const StdStrBuf &, C4Group &hGroup)
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:333
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
void CopyFilePathFromGroup(const C4Group &hGroup)
char * getMData()
Definition: StdBuf.h:451
StdCopyStrBuf Data
#define _MAX_FNAME
bool LoadEntryString(const char *szEntryName, StdStrBuf *Buf)
Definition: C4Group.cpp:1932
StdCopyStrBuf Filename
void Copy()
Definition: StdBuf.h:475
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:318

Here is the call graph for this function:

Here is the caller graph for this function:

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 }
const char * getData() const
Definition: StdBuf.h:450
void FinishLoad(const StdStrBuf &, C4Group &hGroup)
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:243
const char * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:333
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
void CopyFilePathFromGroup(const C4Group &hGroup)
char * getMData()
Definition: StdBuf.h:451
StdCopyStrBuf Data
C4Group * FindEntry(const char *szWildcard, int32_t *pPriority=nullptr, int32_t *pID=nullptr)
Definition: C4GroupSet.cpp:177
#define _MAX_FNAME
bool LoadEntryString(const char *szEntryName, StdStrBuf *rBuf)
Definition: C4GroupSet.cpp:227
StdCopyStrBuf Filename
void Copy()
Definition: StdBuf.h:475
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:318
C4Group * GetGroup(int32_t iIndex)
Definition: C4GroupSet.cpp:261

Here is the call graph for this function:

bool C4ScriptHost::Load ( C4Group hGroup,
const char *  szFilename,
const char *  szLanguage,
C4LangStringTable pLocalTable 
)
virtual

Reimplemented in C4MapScriptHost, and C4GameScriptHost.

Definition at line 167 of file C4ScriptHost.cpp.

References C4LangStringTable::AddRef(), C4LangStringTable::DelRef(), C4ComponentHost::GetFilePath(), C4ComponentHost::Load(), MakeScript(), StdStrBuf::Ref(), ScriptName, and stringTable.

Referenced by C4Game::InitGame(), C4Game::InitScriptEngine(), C4GameScriptHost::Load(), C4Def::Load(), C4MapScriptHost::Load(), C4Game::LoadAdditionalSystemGroup(), ReloadScript(), and C4ScenarioSection::ScenarioLoad().

169 {
170  // Base load
171  bool fSuccess = C4ComponentHost::Load(hGroup,szFilename,szLanguage);
172  // String Table
173  if (stringTable != pLocalTable)
174  {
176  stringTable = pLocalTable;
178  }
179  // set name
181  // preparse script
182  MakeScript();
183  // Success
184  return fSuccess;
185 }
bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage=nullptr)
void Ref(const char *pnData)
Definition: StdBuf.h:463
const char * GetFilePath() const
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
StdCopyStrBuf ScriptName
Definition: C4ScriptHost.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScriptHost::LoadData ( const char *  szFilename,
const char *  szData,
class C4LangStringTable pLocalTable 
)
virtual

Reimplemented in C4MapScriptHost, and C4GameScriptHost.

Definition at line 187 of file C4ScriptHost.cpp.

References C4LangStringTable::AddRef(), StdStrBuf::Clear(), StdStrBuf::Copy(), C4LangStringTable::DelRef(), Preparse(), C4LangStringTable::ReplaceStrings(), Script, ScriptName, stringTable, and StdStrBuf::Take().

Referenced by C4GameScriptHost::LoadData(), and C4MapScriptHost::LoadData().

188 {
189  // String Table
190  if (stringTable != pLocalTable)
191  {
193  stringTable = pLocalTable;
195  }
196  ScriptName.Copy(szFilename);
197 
198  StdStrBuf tempScript;
199  tempScript.Copy(szData);
200 
201  Script.Clear();
202  if(stringTable)
203  stringTable->ReplaceStrings(tempScript, Script);
204  else
205  Script.Take(tempScript);
206 
207  Preparse();
208  return true;
209 }
void Clear()
Definition: StdBuf.h:474
void Take(char *pnData)
Definition: StdBuf.h:465
void ReplaceStrings(StdStrBuf &rBuf)
bool Preparse()
Definition: C4AulParse.cpp:688
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91
void Copy()
Definition: StdBuf.h:475
StdCopyStrBuf ScriptName
Definition: C4ScriptHost.h:57
StdStrBuf Script
Definition: C4ScriptHost.h:90

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ScriptHost::MakeScript ( )
protected

Definition at line 211 of file C4ScriptHost.cpp.

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

Referenced by Load().

212 {
213  // clear prev
214  Script.Clear();
215 
216  // create script
217  if (stringTable)
218  {
220  }
221  else
222  {
223  Script.Ref(GetDataBuf());
224  }
225 
226  // preparse script
227  Preparse();
228 }
void Clear()
Definition: StdBuf.h:474
const StdStrBuf & GetDataBuf() const
void ReplaceStrings(StdStrBuf &rBuf)
void Ref(const char *pnData)
Definition: StdBuf.h:463
bool Preparse()
Definition: C4AulParse.cpp:688
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:

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:

bool C4ScriptHost::Parse ( )
protectedvirtual

Reimplemented in C4DefScriptHost.

Definition at line 1739 of file C4AulParse.cpp.

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

Referenced by C4DefScriptHost::Parse().

1740 {
1741  // check state
1742  if (State != ASS_LINKED) return false;
1743 
1744  if (!Appends.empty())
1745  {
1746  // #appendto scripts are not allowed to contain global functions or belong to definitions
1747  // so their contents are not reachable
1748  return true;
1749  }
1750 
1751  C4PropListStatic * p = GetPropList();
1752 
1753  for (std::list<C4ScriptHost *>::iterator s = SourceScripts.begin(); s != SourceScripts.end(); ++s)
1754  {
1755  CopyPropList((*s)->LocalValues, p);
1756  if (*s == this)
1757  continue;
1758  // definition appends
1759  if (GetPropList() && GetPropList()->GetDef() && (*s)->GetPropList() && (*s)->GetPropList()->GetDef())
1760  GetPropList()->GetDef()->IncludeDefinition((*s)->GetPropList()->GetDef());
1761  }
1762 
1763  // generate bytecode
1764  for (auto &s : SourceScripts)
1765  C4AulCompiler::Compile(this, s, s->ast.get());
1766 
1767  // save line count
1769 
1770  // finished
1771  State = ASS_PARSED;
1772 
1773  return true;
1774 }
const char * getData() const
Definition: StdBuf.h:450
int SGetLine(const char *szText, const char *cpPosition)
Definition: Standard.cpp:443
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:635
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:662
void CopyPropList(C4Set< C4Property > &from, C4PropListStatic *to)
static void Compile(C4AulScriptFunc *out, const ::aul::ast::Function *f)
const char * getPtr(size_t i) const
Definition: StdBuf.h:456
size_t getLength() const
Definition: StdBuf.h:453
std::list< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:56
#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:

bool C4ScriptHost::Preparse ( )
protected

Definition at line 688 of file C4AulParse.cpp.

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

Referenced by LoadData(), and MakeScript().

689 {
690  // handle easiest case first
691  if (State < ASS_NONE) return false;
692 
693  // clear stuff
694  Includes.clear(); Appends.clear();
695 
696  GetPropList()->C4PropList::Clear();
698  LocalValues.Clear();
699 
700  // Add any engine functions specific to this script
702 
703  // Insert default warnings
704  assert(enabledWarnings.empty());
705  auto &warnings = enabledWarnings[Script.getData()];
706 #define DIAG(id, text, enabled) warnings.set(static_cast<size_t>(C4AulWarningId::id), enabled);
707 #include "C4AulWarnings.h"
708 #undef DIAG
709 
710  C4AulParse parser(this);
711  ast = parser.Parse_Script(this);
712 
713  C4AulCompiler::Preparse(this, this, ast.get());
714 
715  // #include will have to be resolved now...
716  IncludesResolved = false;
717 
718  // Parse will write the properties back after the ones from included scripts
719  GetPropList()->Properties.Swap(&LocalValues);
720 
721  // return success
722  this->State = ASS_PREPARSED;
723  return true;
724 }
const char * getData() const
Definition: StdBuf.h:450
bool IncludesResolved
Definition: C4ScriptHost.h:88
C4PropListStatic * GetPropList()
Definition: C4Aul.h:153
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:122
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
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:

void C4ScriptHost::Reg2List ( C4AulScriptEngine pEngine)

Definition at line 149 of file C4ScriptHost.cpp.

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

Referenced by C4MapScriptHost::InitFunctionMap(), C4Game::InitScriptEngine(), C4GameScriptHost::Load(), C4Def::Load(), C4Game::LoadAdditionalSystemGroup(), C4GameScriptHost::LoadData(), and C4ScenarioSection::ScenarioLoad().

150 {
151  // already regged? (def reloaded)
152  if (Engine) return;
153  // reg to list
154  if ((Engine = pEngine))
155  {
156  if ((Prev = Engine->ChildL))
157  Prev->Next = this;
158  else
159  Engine->Child0 = this;
160  Engine->ChildL = this;
161  }
162  else
163  Prev = nullptr;
164  Next = nullptr;
165 }
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
C4ScriptHost * ChildL
Definition: C4Aul.h:123
C4ScriptHost * Next
Definition: C4ScriptHost.h:77
C4ScriptHost * Prev
Definition: C4ScriptHost.h:77
C4ScriptHost * Child0
Definition: C4Aul.h:123

Here is the caller graph for this function:

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

Definition at line 230 of file C4ScriptHost.cpp.

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

Referenced by C4AulScriptEngine::ReloadScript().

231 {
232  // this?
233  if (SEqualNoCase(szPath, GetFilePath()) || (stringTable && SEqualNoCase(szPath, stringTable->GetFilePath())))
234  {
235  // try reload
236  char szParentPath[_MAX_PATH + 1]; C4Group ParentGrp;
237  if (GetParentPath(szPath, szParentPath))
238  if (ParentGrp.Open(szParentPath))
239  if (Load(ParentGrp, nullptr, szLanguage, stringTable))
240  return true;
241  }
242  return false;
243 }
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:177
#define _MAX_PATH
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:199
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)
const char * GetFilePath() const
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4ScriptHost::ResolveAppends ( C4DefList rDefs)
protected

Definition at line 46 of file C4AulLink.cpp.

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

47 {
48  // resolve local appends
49  if (State != ASS_PREPARSED) return false;
50  for (std::list<StdCopyStrBuf>::iterator a = Appends.begin(); a != Appends.end(); ++a)
51  {
52  if (*a != "*" || !rDefs)
53  {
54  C4Def *Def = rDefs ? rDefs->GetByName(*a) : 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", a->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
#define a
void DoAppend(C4Def *def)
Definition: C4AulLink.cpp:28
Definition: C4Def.h:100
C4Def * GetByName(const StdStrBuf &)
void Warn(const char *pMsg,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: C4AulParse.cpp:132
C4AulScriptState State
Definition: C4ScriptHost.h:93

Here is the call graph for this function:

bool C4ScriptHost::ResolveIncludes ( C4DefList rDefs)
protected

Definition at line 83 of file C4AulLink.cpp.

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

Referenced by 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
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:175
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:79
Definition: C4Def.h:100
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:132
C4DefScriptHost Script
Definition: C4Def.h:184
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:

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

Definition at line 245 of file C4ScriptHost.cpp.

References stringTable, and C4LangStringTable::Translate().

246 {
247  if (stringTable)
248  return stringTable->Translate(text);
250 }
const std::string & Translate(const std::string &text) const
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:91

Here is the call graph for this function:

void C4ScriptHost::UnLink ( )
protectedvirtual

Definition at line 130 of file C4AulLink.cpp.

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

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:153
void SetProperty(C4PropertyName k, const C4Value &to)
Definition: C4PropList.h:122
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:

void C4ScriptHost::UnlinkOwnedFunctions ( )
protected

Definition at line 77 of file C4ScriptHost.cpp.

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

Referenced by Clear().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4ScriptHost::Unreg ( )
protected

Definition at line 140 of file C4ScriptHost.cpp.

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

Referenced by ~C4ScriptHost().

141 {
142  // remove from list
143  if (Prev) Prev->Next = Next; else if (Engine) Engine->Child0 = Next;
144  if (Next) Next->Prev = Prev; else if (Engine) Engine->ChildL = Prev;
145  Prev = Next = nullptr;
146  Engine = nullptr;
147 }
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
C4ScriptHost * ChildL
Definition: C4Aul.h:123
C4ScriptHost * Next
Definition: C4ScriptHost.h:77
C4ScriptHost * Prev
Definition: C4ScriptHost.h:77
C4ScriptHost * Child0
Definition: C4Aul.h:123

Here is the caller graph for this function:

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

Definition at line 132 of file C4AulParse.cpp.

References StdStrBuf::AppendFormat(), Engine, FormatStringV(), StdStrBuf::getData(), C4AulScriptEngine::GetErrorHandler(), C4AulErrorHandler::OnWarning(), and ScriptName.

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

133 {
134  va_list args; va_start(args, pMsg);
135  StdStrBuf Buf = FormatStringV(pMsg, args);
136  Buf.AppendFormat(" (%s)", ScriptName.getData());
138  va_end(args);
139 }
const char * getData() const
Definition: StdBuf.h:450
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:175
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:76
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:197
StdStrBuf FormatStringV(const char *szFmt, va_list args)
Definition: StdBuf.cpp:283
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:

Friends And Related Function Documentation

friend class C4AulCompiler
friend

Definition at line 109 of file C4ScriptHost.h.

friend class C4AulDebug
friend

Definition at line 108 of file C4ScriptHost.h.

friend class C4AulParse
friend

Definition at line 105 of file C4ScriptHost.h.

friend class C4AulProfiler
friend

Definition at line 106 of file C4ScriptHost.h.

friend class C4AulScriptEngine
friend

Definition at line 107 of file C4ScriptHost.h.

friend class C4AulScriptFunc
friend

Definition at line 110 of file C4ScriptHost.h.

Referenced by CopyPropList().

Member Data Documentation

std::list<StdCopyStrBuf> C4ScriptHost::Appends
protected
StdCopyStrBuf C4ComponentHost::Filename
protectedinherited
StdCopyStrBuf C4ComponentHost::FilePath
protectedinherited
std::list<StdCopyStrBuf> C4ScriptHost::Includes
protected
bool C4ScriptHost::IncludesResolved
protected

Definition at line 88 of file C4ScriptHost.h.

Referenced by C4ScriptHost(), Preparse(), ResolveIncludes(), and UnLink().

C4Set<C4Property> C4ScriptHost::LocalValues
protected

Definition at line 92 of file C4ScriptHost.h.

Referenced by Clear(), and Preparse().

C4ScriptHost * C4ScriptHost::Next
protected

Definition at line 77 of file C4ScriptHost.h.

Referenced by Reg2List(), C4AulScriptEngine::ReloadScript(), and Unreg().

std::vector<C4Value> C4ScriptHost::ownedFunctions
protected
std::vector<C4Value> C4ScriptHost::ownedPropLists
protected

Definition at line 101 of file C4ScriptHost.h.

Referenced by DeleteOwnedPropLists().

C4ScriptHost* C4ScriptHost::Prev
protected

Definition at line 77 of file C4ScriptHost.h.

Referenced by Reg2List(), and Unreg().

bool C4ScriptHost::Resolving
protected

Definition at line 87 of file C4ScriptHost.h.

Referenced by C4ScriptHost(), and ResolveIncludes().

StdStrBuf C4ScriptHost::Script
protected
StdCopyStrBuf C4ScriptHost::ScriptName
std::list<C4ScriptHost *> C4ScriptHost::SourceScripts

Definition at line 56 of file C4ScriptHost.h.

Referenced by C4ScriptHost(), Clear(), DoAppend(), Parse(), and ResolveIncludes().

C4AulScriptState C4ScriptHost::State
protected

Definition at line 93 of file C4ScriptHost.h.

Referenced by Clear(), IsReady(), Parse(), Preparse(), ResolveAppends(), ResolveIncludes(), and UnLink().

C4LangStringTable* C4ScriptHost::stringTable
protected

Definition at line 91 of file C4ScriptHost.h.

Referenced by C4ScriptHost(), Clear(), Load(), LoadData(), MakeScript(), ReloadScript(), and Translate().


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