OpenClonk
C4MapScriptHost Class Reference

#include <C4MapScript.h>

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

Public Member Functions

 C4MapScriptHost ()
 
 ~C4MapScriptHost () override
 
void InitFunctionMap (C4AulScriptEngine *pEngine)
 
void AddEngineFunctions () override
 
bool Load (C4Group &, const char *, const char *, C4LangStringTable *) override
 
bool LoadData (const char *, const char *, C4LangStringTable *) override
 
void Clear ()
 
C4PropListStaticGetPropList () override
 
bool InitializeMap (C4SLandscape *pLandscape, C4TextureMap *pTexMap, C4MaterialMap *pMatMap, uint32_t iPlayerCount, std::unique_ptr< CSurface8 > *pmap_fg_surface, std::unique_ptr< CSurface8 > *pmap_bg_surface)
 
C4PropListStaticGetLayerPrototype ()
 
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

C4TextureMappTexMap {nullptr}
 
C4MaterialMappMatMap {nullptr}
 
std::deque< 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
 
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 347 of file C4MapScript.h.

Constructor & Destructor Documentation

◆ C4MapScriptHost()

C4MapScriptHost::C4MapScriptHost ( )
default

◆ ~C4MapScriptHost()

C4MapScriptHost::~C4MapScriptHost ( )
override

Definition at line 641 of file C4MapScript.cpp.

641 { Clear(); }

References Clear().

Here is the call graph for this function:

Member Function Documentation

◆ AddEngineFunctions()

void C4MapScriptHost::AddEngineFunctions ( )
overridevirtual

Reimplemented from C4ScriptHost.

Definition at line 675 of file C4MapScript.cpp.

676 {
677  // adds all engine functions to the MapLayer context
679  ::AddFunc(p, "Draw", FnLayerDraw);
680  ::AddFunc(p, "Blit", FnLayerBlit);
681  ::AddFunc(p, "CreateLayer", FnCreateLayer);
682  ::AddFunc(p, "Duplicate", FnLayerDuplicate);
683  ::AddFunc(p, "GetMaterialTextureIndex", FnLayerGetMaterialTextureIndex);
684  ::AddFunc(p, "GetDefaultBackgroundIndex", FnLayerGetDefaultBackgroundIndex);
685  ::AddFunc(p, "GetPixel", FnLayerGetPixel);
686  ::AddFunc(p, "GetBackPixel", FnLayerGetBackPixel);
687  ::AddFunc(p, "SetPixel", FnLayerSetPixel);
688  ::AddFunc(p, "GetPixelCount", FnLayerGetPixelCount);
689  ::AddFunc(p, "Resize", FnLayerResize);
690  ::AddFunc(p, "FindPosition", FnLayerFindPosition);
691  ::AddFunc(p, "CreateMatTexMask", FnLayerCreateMatTexMask);
692 }
void AddFunc(C4PropListStatic *Parent, const char *Name, RType(*pFunc)(ThisType *, ParTypes...), bool Public=true)
Definition: C4AulDefFunc.h:261
C4PropListStatic * GetPropList() override

References AddFunc(), and GetPropList().

Referenced by InitFunctionMap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4MapScriptHost::Clear ( )

Definition at line 706 of file C4MapScript.cpp.

707 {
709  delete LayerPrototype; delete MapPrototype;
710  LayerPrototype = MapPrototype = nullptr;
711 }

References C4ScriptHost::Clear().

Referenced by c4_mapgen_handle_deinit_script_engine(), C4Game::Clear(), InitFunctionMap(), and ~C4MapScriptHost().

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.

121 {
125 }
C4Config Config
Definition: C4Config.cpp:930
StdCopyStrBuf Filename
StdCopyStrBuf FilePath
const char * AtRelativePath(const char *filename)
Definition: C4Config.cpp:741
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2638
const char * getData() const
Definition: StdBuf.h:442
void AppendBackslash()
Definition: StdBuf.cpp:248
void Copy()
Definition: StdBuf.h:467
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

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().

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 1690 of file C4AulParse.cpp.

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 }
C4StringTable Strings
Definition: C4Globals.cpp:42
@ P_Prototype
C4Value C4VFunction(C4AulFunc *pFn)
Definition: C4Value.h:247
@ C4V_Function
Definition: C4Value.h:31
@ C4V_PropList
Definition: C4Value.h:28
@ C4V_Array
Definition: C4Value.h:30
C4Value C4VPropList(C4PropList *p)
Definition: C4Value.h:242
C4RefCntPointer< C4String > Name
Definition: C4AulFunc.h:60
virtual C4AulScriptFunc * SFunc()
Definition: C4AulFunc.h:65
void SetOverloaded(C4AulFunc *)
C4ScriptHost * pOrgScript
C4AulFunc * GetFunc(C4PropertyName k) const
Definition: C4PropList.h:109
virtual class C4PropListStatic * IsStatic()
Definition: C4PropList.h:89
virtual void SetPropertyByS(C4String *k, const C4Value &to)
Definition: C4PropList.cpp:940
static C4PropListStatic * NewStatic(C4PropList *prototype, const C4PropListStatic *parent, C4String *key)
Definition: C4PropList.cpp:46
const C4PropListStatic * GetParent() const
Definition: C4PropList.h:275
C4Value Value
Definition: C4PropList.h:54
C4String * Key
Definition: C4PropList.h:53
friend class C4AulScriptFunc
Definition: C4ScriptHost.h:111
void CopyPropList(C4Set< C4Property > &from, C4PropListStatic *to)
T const * Next(T const *p) const
T const * First() const
C4String P[P_LAST]
C4PropList * _getPropList() const
Definition: C4Value.h:129
C4V_Type GetType() const
Definition: C4Value.h:161
C4AulFunc * getFunction() const
Definition: C4Value.h:119

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::Parse().

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 44 of file C4ScriptHost.h.

44 { return false; } // do NOT delete this - it's just a class member!

Referenced by C4AulScriptEngine::Clear().

Here is the caller graph for this function:

◆ DeleteOwnedPropLists()

void C4ScriptHost::DeleteOwnedPropLists ( )
protectedinherited

Definition at line 120 of file C4ScriptHost.cpp.

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

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

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

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.

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 }
C4DefScriptHost Script
Definition: C4Def.h:181
std::list< StdCopyStrBuf > Includes
Definition: C4ScriptHost.h:80
std::deque< C4ScriptHost * > SourceScripts
Definition: C4ScriptHost.h:57
void Warn(const char *pMsg,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: C4AulParse.cpp:124

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

Referenced by C4ScriptHost::ResolveAppends().

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 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 }

◆ FinishLoad()

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

Definition at line 99 of file C4ComponentHost.cpp.

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 LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
void CopyFilePathFromGroup(const C4Group &hGroup)
virtual void OnLoad()
StdCopyStrBuf Data
bool FindEntry(const char *wildcard, StdStrBuf *filename=nullptr, size_t *size=nullptr)
Definition: C4Group.cpp:2211
size_t getSize() const
Definition: StdBuf.h:444
void Move(size_t iFrom, size_t inSize, size_t iTo=0)
Definition: StdBuf.h:471
void Shrink(size_t iShrink)
Definition: StdBuf.h:503
bool EnsureUnicode()
Definition: StdBuf.cpp:421

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().

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.

30 { return Data.getData(); }

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

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

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.

31 { return Data; }

References C4ComponentHost::Data.

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

Here is the caller graph for this function:

◆ GetDataSize()

size_t C4ComponentHost::GetDataSize ( ) const
inlineinherited

Definition at line 32 of file C4ComponentHost.h.

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

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

Referenced by C4RankSystem::Load().

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.

28 { return FilePath.getData(); }

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

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

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.

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 * SSearch(const char *szString, const char *szIndex)
Definition: Standard.cpp:369
int SCharPos(char cTarget, const char *szInStr, int iIndex)
Definition: Standard.cpp:239
bool SCopySegment(const char *szString, int iSegment, char *sTarget, char cSeparator, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:279
void SAppend(const char *szSource, char *szTarget, int iMaxL)
Definition: Standard.cpp:263

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLayerPrototype()

C4PropListStatic* C4MapScriptHost::GetLayerPrototype ( )
inline

Definition at line 363 of file C4MapScript.h.

363 { return LayerPrototype; }

Referenced by C4MapScriptMap::CreateLayer().

Here is the caller graph for this function:

◆ GetPropList() [1/2]

const C4PropListStatic* C4ScriptHost::GetPropList ( ) const
inlineinherited

Definition at line 52 of file C4ScriptHost.h.

52 { return const_cast<C4ScriptHost*>(this)->GetPropList(); }
virtual C4PropListStatic * GetPropList()
Definition: C4ScriptHost.h:51

References C4ScriptHost::GetPropList().

Referenced by C4ScriptHost::GetPropList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPropList() [2/2]

C4PropListStatic * C4MapScriptHost::GetPropList ( )
overridevirtual

Reimplemented from C4ScriptHost.

Definition at line 713 of file C4MapScript.cpp.

714 {
715  // Scripts are compiled in the MapLayer context so it's possible to use all map drawing functions directly without "map->" prefix
716  return LayerPrototype;
717 }

Referenced by AddEngineFunctions().

Here is the caller graph for this function:

◆ GetScript()

const char* C4ScriptHost::GetScript ( ) const
inlineinherited

Definition at line 53 of file C4ScriptHost.h.

53 { return Script.getData(); }
StdStrBuf Script
Definition: C4ScriptHost.h:91

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

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitFunctionMap()

void C4MapScriptHost::InitFunctionMap ( C4AulScriptEngine pEngine)

Definition at line 643 of file C4MapScript.cpp.

644 {
645  // Register script host. Add Map and MapLayer prototypes, related constants and engine functions
646  assert(pEngine && pEngine->GetPropList());
647  Clear();
648  LayerPrototype = new C4PropListStaticMember(nullptr, nullptr, ::Strings.RegString("MapLayer"));
649  MapPrototype = new C4PropListStaticMember(LayerPrototype, nullptr, ::Strings.RegString("Map"));
650  LayerPrototype->SetName("MapLayer");
651  MapPrototype->SetName("Map");
652  ::ScriptEngine.RegisterGlobalConstant("MapLayer", C4VPropList(LayerPrototype));
653  ::ScriptEngine.RegisterGlobalConstant("Map", C4VPropList(MapPrototype));
671  Reg2List(pEngine);
673 }
C4AulScriptEngine ScriptEngine
Definition: C4Globals.cpp:43
@ MAPALGO_Layer
Definition: C4MapScript.h:70
@ MAPALGO_Border
Definition: C4MapScript.h:90
@ MAPALGO_Ellipsis
Definition: C4MapScript.h:75
@ MAPALGO_Rect
Definition: C4MapScript.h:74
@ MAPALGO_Rotate
Definition: C4MapScript.h:87
@ MAPALGO_Turbulence
Definition: C4MapScript.h:88
@ MAPALGO_Or
Definition: C4MapScript.h:81
@ MAPALGO_Filter
Definition: C4MapScript.h:91
@ MAPALGO_Lines
Definition: C4MapScript.h:77
@ MAPALGO_Not
Definition: C4MapScript.h:82
@ MAPALGO_RndChecker
Definition: C4MapScript.h:72
@ MAPALGO_And
Definition: C4MapScript.h:80
@ MAPALGO_Scale
Definition: C4MapScript.h:86
@ MAPALGO_Xor
Definition: C4MapScript.h:83
@ MAPALGO_Polygon
Definition: C4MapScript.h:76
@ MAPALGO_Ellipse
Definition: C4MapScript.h:78
@ MAPALGO_Offset
Definition: C4MapScript.h:85
C4Value C4VInt(int32_t i)
Definition: C4Value.h:239
C4PropListStatic * GetPropList()
Definition: C4Aul.h:151
void RegisterGlobalConstant(const char *szName, const C4Value &rValue)
Definition: C4Aul.cpp:123
void AddEngineFunctions() override
virtual void SetName(const char *NewName=nullptr)
Definition: C4PropList.cpp:625
void Reg2List(C4AulScriptEngine *pEngine)
C4String * RegString(StdStrBuf String)

References AddEngineFunctions(), C4VInt(), C4VPropList(), Clear(), C4AulScriptEngine::GetPropList(), MAPALGO_And, MAPALGO_Border, MAPALGO_Ellipse, MAPALGO_Ellipsis, MAPALGO_Filter, MAPALGO_Layer, MAPALGO_Lines, MAPALGO_Not, MAPALGO_Offset, MAPALGO_Or, MAPALGO_Polygon, MAPALGO_Rect, MAPALGO_RndChecker, MAPALGO_Rotate, MAPALGO_Scale, MAPALGO_Turbulence, MAPALGO_Xor, C4ScriptHost::Reg2List(), C4AulScriptEngine::RegisterGlobalConstant(), C4StringTable::RegString(), ScriptEngine, C4PropList::SetName(), and Strings.

Referenced by c4_mapgen_handle_init_script_engine(), and C4Game::InitScriptEngine().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitializeMap()

bool C4MapScriptHost::InitializeMap ( C4SLandscape pLandscape,
C4TextureMap pTexMap,
C4MaterialMap pMatMap,
uint32_t  iPlayerCount,
std::unique_ptr< CSurface8 > *  pmap_fg_surface,
std::unique_ptr< CSurface8 > *  pmap_bg_surface 
)

Definition at line 724 of file C4MapScript.cpp.

725 {
726  // Init scripted map by calling InitializeMap in the proper scripts. If *pmap_surface is given, it will pass the existing map to be modified by script.
727  assert(pmap_fg_surface);
728  assert(pmap_bg_surface);
729 
730  this->pTexMap = pTexMap;
731  this->pMatMap = pMatMap;
732  // Don't bother creating surfaces if the functions aren't defined
733  if (!LayerPrototype->GetFunc(PSF_InitializeMap))
734  {
736  if (!scen_proplist || !scen_proplist->GetFunc(PSF_InitializeMap)) return false;
737  }
738  // Create proplist as script context
739  std::unique_ptr<C4MapScriptMap> map(CreateMap());
740 
741  // Drawing on existing map or create new?
742  if (*pmap_fg_surface && *pmap_bg_surface)
743  {
744  // Existing map
745  map->SetSurfaces(std::move(*pmap_fg_surface), std::move(*pmap_bg_surface));
746  }
747  else
748  {
749  assert(!*pmap_fg_surface && !*pmap_bg_surface);
750  // No existing map. Create new.
751  int32_t map_wdt,map_hgt;
752  pLandscape->GetMapSize(map_wdt, map_hgt, iPlayerCount);
753  if (!map->CreateSurface(map_wdt, map_hgt)) return false;
754  }
755  C4AulParSet Pars(C4VPropList(map.get()));
756  C4Value result = map->Call(PSF_InitializeMap, &Pars);
757  if (!result) result = ::GameScript.Call(PSF_InitializeMap, &Pars);
758  // Map creation done.
759  if (result)
760  {
761  map->ConvertSkyToTransparent();
762  }
763  std::tie(*pmap_fg_surface, *pmap_bg_surface) = map->ReleaseSurfaces();
764  return !!result;
765 }
#define PSF_InitializeMap
Definition: C4GameScript.h:44
C4GameScriptHost GameScript
C4Value Call(const char *szFunction, C4AulParSet *pPars=nullptr, bool fPassError=false)
C4Value ScenPropList
Definition: C4ScriptHost.h:164
C4MaterialMap * pMatMap
Definition: C4MapScript.h:366
C4TextureMap * pTexMap
Definition: C4MapScript.h:365
void GetMapSize(int32_t &rWdt, int32_t &rHgt, int32_t iPlayerNum)
Definition: C4Scenario.cpp:319

References C4Value::_getPropList(), C4VPropList(), C4GameScriptHost::Call(), GameScript, C4PropList::GetFunc(), C4SLandscape::GetMapSize(), pMatMap, PSF_InitializeMap, pTexMap, and C4GameScriptHost::ScenPropList.

Referenced by c4_mapgen_handle_new_script().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsReady()

bool C4ScriptHost::IsReady ( )
inlineinherited

Definition at line 54 of file C4ScriptHost.h.

54 { return State == ASS_PARSED; } // whether script calls may be done
@ ASS_PARSED
Definition: C4ScriptHost.h:36
C4AulScriptState State
Definition: C4ScriptHost.h:94

References ASS_PARSED, and C4ScriptHost::State.

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

Here is the caller graph for this function:

◆ IsWarningEnabled()

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

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 }

◆ Load() [1/3]

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

Reimplemented from C4ScriptHost.

Definition at line 694 of file C4MapScript.cpp.

695 {
696  assert(LayerPrototype && MapPrototype);
697  return C4ScriptHost::Load(g, f, l, t);
698 }
virtual bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage, C4LangStringTable *pLocalTable)

References C4ScriptHost::Load().

Here is the call graph for this function:

◆ Load() [2/3]

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

Definition at line 23 of file C4ComponentHost.cpp.

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_LEN];
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 }
#define _MAX_FNAME_LEN
void SReplaceChar(char *str, char fc, char tc)
Definition: Standard.cpp:354
void FinishLoad(const StdStrBuf &, C4Group &hGroup)
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430
char * getMData()
Definition: StdBuf.h:443
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:174

References _MAX_FNAME_LEN, 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(), C4ScriptHost::Load(), C4ScenarioListLoader::Entry::Load(), C4Language::LoadComponentHost(), and C4Game::LoadScenarioComponents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Load() [3/3]

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

Definition at line 60 of file C4ComponentHost.cpp.

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_LEN];
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 }
bool LoadEntryString(const char *szEntryName, StdStrBuf *rBuf)
Definition: C4GroupSet.cpp:225
C4Group * GetGroup(int32_t iIndex)
Definition: C4GroupSet.cpp:259
C4Group * FindEntry(const char *szWildcard, int32_t *pPriority=nullptr, int32_t *pID=nullptr)
Definition: C4GroupSet.cpp:175

References _MAX_FNAME_LEN, 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().

Here is the call graph for this function:

◆ LoadData()

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

Reimplemented from C4ScriptHost.

Definition at line 700 of file C4MapScript.cpp.

701 {
702  assert(LayerPrototype && MapPrototype);
703  return C4ScriptHost::LoadData(f, d, t);
704 }
virtual bool LoadData(const char *szFilename, const char *szData, class C4LangStringTable *pLocalTable)

References C4ScriptHost::LoadData().

Referenced by c4_mapgen_handle_new_script().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeScript()

void C4ScriptHost::MakeScript ( )
protectedinherited

Definition at line 208 of file C4ScriptHost.cpp.

209 {
210  // clear prev
211  Script.Clear();
212 
213  // create script
214  if (stringTable)
215  {
217  }
218  else
219  {
220  Script.Ref(GetDataBuf());
221  }
222 
223  // preparse script
224  Preparse();
225 }
const StdStrBuf & GetDataBuf() const
void ReplaceStrings(StdStrBuf &rBuf)
bool Preparse()
Definition: C4AulParse.cpp:693
C4LangStringTable * stringTable
Definition: C4ScriptHost.h:92
void Ref(const char *pnData)
Definition: StdBuf.h:455
void Clear()
Definition: StdBuf.h:466

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

Referenced by C4ScriptHost::Load().

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.

39 {}

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

Here is the caller graph for this function:

◆ Parse()

bool C4ScriptHost::Parse ( )
protectedvirtualinherited

Reimplemented in C4DefScriptHost.

Definition at line 1739 of file C4AulParse.cpp.

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 (auto & SourceScript : SourceScripts)
1754  {
1755  CopyPropList(SourceScript->LocalValues, p);
1756  if (SourceScript == this)
1757  continue;
1758  // definition appends
1759  if (GetPropList() && GetPropList()->GetDef() && SourceScript->GetPropList() && SourceScript->GetPropList()->GetDef())
1760  GetPropList()->GetDef()->IncludeDefinition(SourceScript->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 }
#define s
@ ASS_LINKED
Definition: C4ScriptHost.h:35
int SGetLine(const char *szText, const char *cpPosition)
Definition: Standard.cpp:479
static void Compile(C4AulScriptFunc *out, const ::aul::ast::Function *f)
void IncludeDefinition(C4Def *pIncludeDef)
Definition: C4Def.cpp:641
virtual C4Def const * GetDef() const
Definition: C4PropList.cpp:654
C4AulScriptEngine * Engine
Definition: C4ScriptHost.h:77
std::list< StdCopyStrBuf > Appends
Definition: C4ScriptHost.h:81
const char * getPtr(size_t i) const
Definition: StdBuf.h:448

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Preparse()

bool C4ScriptHost::Preparse ( )
protectedinherited

Definition at line 693 of file C4AulParse.cpp.

694 {
695  // handle easiest case first
696  if (State < ASS_NONE) return false;
697 
698  // clear stuff
699  Includes.clear(); Appends.clear();
700 
701  GetPropList()->C4PropList::Clear();
703  LocalValues.Clear();
704 
705  // Add any engine functions specific to this script
707 
708  // Insert default warnings
709  assert(enabledWarnings.empty());
710  auto &warnings = enabledWarnings[Script.getData()];
711 #define DIAG(id, text, enabled) warnings.set(static_cast<size_t>(C4AulWarningId::id), enabled);
712 #include "C4AulWarnings.h"
713 #undef DIAG
714 
715  C4AulParse parser(this);
716  ast = parser.Parse_Script(this);
717 
718  C4AulCompiler::Preparse(this, this, ast.get());
719 
720  // #include will have to be resolved now...
721  IncludesResolved = false;
722 
723  // Parse will write the properties back after the ones from included scripts
724  GetPropList()->Properties.Swap(&LocalValues);
725 
726  // return success
727  this->State = ASS_PREPARSED;
728  return true;
729 }
@ ASS_PREPARSED
Definition: C4ScriptHost.h:34
@ ASS_NONE
Definition: C4ScriptHost.h:33
static void Preparse(C4ScriptHost *out, C4ScriptHost *source, const ::aul::ast::Script *s)
void SetProperty(C4PropertyName k, const C4Value &to)
Definition: C4PropList.h:124
C4Set< C4Property > LocalValues
Definition: C4ScriptHost.h:93
virtual void AddEngineFunctions()
Definition: C4ScriptHost.h:83
bool IncludesResolved
Definition: C4ScriptHost.h:89
void Clear()

References C4ScriptHost::AddEngineFunctions(), C4ScriptHost::Appends, ASS_NONE, ASS_PREPARSED, C4VPropList(), C4Set< T >::Clear(), C4ScriptHost::Engine, StdStrBuf::getData(), C4AulScriptEngine::GetPropList(), C4ScriptHost::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().

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 146 of file C4ScriptHost.cpp.

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

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

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

Here is the caller graph for this function:

◆ ReloadScript()

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

Definition at line 227 of file C4ScriptHost.cpp.

228 {
229  // this?
230  if (SEqualNoCase(szPath, GetFilePath()) || (stringTable && SEqualNoCase(szPath, stringTable->GetFilePath())))
231  {
232  // try reload
233  char szParentPath[_MAX_PATH_LEN]; C4Group ParentGrp;
234  if (GetParentPath(szPath, szParentPath))
235  if (ParentGrp.Open(szParentPath))
236  if (Load(ParentGrp, nullptr, szLanguage, stringTable))
237  return true;
238  }
239  return false;
240 }
#define _MAX_PATH_LEN
bool SEqualNoCase(const char *szStr1, const char *szStr2, int iLen)
Definition: Standard.cpp:213
bool GetParentPath(const char *szFilename, char *szBuffer)
Definition: StdFile.cpp:186
const char * GetFilePath() const
bool Open(const char *group_name, bool do_create=false)
Definition: C4Group.cpp:660

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

Here is the call graph for this function:

◆ ResolveAppends()

bool C4ScriptHost::ResolveAppends ( C4DefList rDefs)
protectedinherited

Definition at line 46 of file C4AulLink.cpp.

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 }
Definition: C4Def.h:99
int32_t GetDefCount()
C4Def * GetDef(int32_t Index)
C4Def * GetByName(const StdStrBuf &)
void DoAppend(C4Def *def)
Definition: C4AulLink.cpp:28

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

Here is the call graph for this function:

◆ ResolveIncludes()

bool C4ScriptHost::ResolveIncludes ( C4DefList rDefs)
protectedinherited

Definition at line 83 of file C4AulLink.cpp.

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 (auto 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 }
virtual void OnError(const char *msg)=0
C4AulErrorHandler * GetErrorHandler() const
Definition: C4Aul.h:173
bool ResolveIncludes(C4DefList *rDefs)
Definition: C4AulLink.cpp:83

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::ResolveIncludes().

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 242 of file C4ScriptHost.cpp.

243 {
244  if (stringTable)
245  return stringTable->Translate(text);
247 }
const std::string & Translate(const std::string &text) const

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

Here is the call graph for this function:

◆ UnLink()

void C4ScriptHost::UnLink ( )
protectedvirtualinherited

Definition at line 130 of file C4AulLink.cpp.

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 }
void DeleteOwnedPropLists()

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

Here is the call graph for this function:

◆ UnlinkOwnedFunctions()

void C4ScriptHost::UnlinkOwnedFunctions ( )
protectedinherited

Definition at line 72 of file C4ScriptHost.cpp.

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  func->OwnerOverloaded = nullptr; // func_chain now takes care of this.
109  func->DecRef(); // decrease rc because func_chain no longer has a reference to func.
110  break;
111  }
112  assert(func_chain->OwnerOverloaded && "Removed function not found in inheritance chain");
113  func_chain = func_chain->OwnerOverloaded->SFunc();
114  }
115  }
116  }
117  ownedFunctions.clear();
118 }
C4PropListStatic * Parent
Definition: C4AulFunc.h:55
C4AulFunc * OwnerOverloaded
C4AulScriptFunc * SFunc() override
void Thaw()
Definition: C4PropList.h:133
virtual bool GetPropertyByS(const C4String *k, C4Value *pResult) const
Definition: C4PropList.cpp:726
virtual void ResetProperty(C4String *k)
Definition: C4PropList.cpp:961
void DecRef()
Definition: C4StringTable.h:28
std::vector< C4Value > ownedFunctions
Definition: C4ScriptHost.h:97

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

Referenced by C4ScriptHost::Clear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unreg()

void C4ScriptHost::Unreg ( )
protectedinherited

Definition at line 137 of file C4ScriptHost.cpp.

138 {
139  // remove from list
140  if (Prev) Prev->Next = Next; else if (Engine) Engine->Child0 = Next;
141  if (Next) Next->Prev = Prev; else if (Engine) Engine->ChildL = Prev;
142  Prev = Next = nullptr;
143  Engine = nullptr;
144 }

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

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

Here is the caller graph for this function:

◆ Warn()

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

Definition at line 124 of file C4AulParse.cpp.

125 {
126  va_list args; va_start(args, pMsg);
127  StdStrBuf Buf = FormatStringV(pMsg, args);
128  Buf.AppendFormat(" (%s)", ScriptName.getData());
130  va_end(args);
131 }
StdStrBuf FormatStringV(const char *szFmt, va_list args)
Definition: StdBuf.cpp:276
virtual void OnWarning(const char *msg)=0
StdCopyStrBuf ScriptName
Definition: C4ScriptHost.h:58
void AppendFormat(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:190

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

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

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 93 of file C4ScriptHost.h.

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

◆ Next

C4ScriptHost * C4ScriptHost::Next {nullptr}
protectedinherited

Definition at line 78 of file C4ScriptHost.h.

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

◆ ownedFunctions

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

◆ ownedPropLists

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

Definition at line 102 of file C4ScriptHost.h.

Referenced by C4ScriptHost::DeleteOwnedPropLists().

◆ pMatMap

C4MaterialMap* C4MapScriptHost::pMatMap {nullptr}

Definition at line 366 of file C4MapScript.h.

Referenced by InitializeMap().

◆ Prev

C4ScriptHost* C4ScriptHost::Prev {nullptr}
protectedinherited

Definition at line 78 of file C4ScriptHost.h.

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

◆ pTexMap

C4TextureMap* C4MapScriptHost::pTexMap {nullptr}

Definition at line 365 of file C4MapScript.h.

Referenced by FnParTexCol(), and InitializeMap().

◆ Resolving

bool C4ScriptHost::Resolving
protectedinherited

Definition at line 88 of file C4ScriptHost.h.

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

◆ Script

◆ ScriptName

◆ SourceScripts

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

◆ State

◆ stringTable


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