forked from Mirrors/openclonk
Script: Add a proplist representing the global scope, named "Global"
parent
f166fdaed7
commit
8185d318bf
|
@ -306,8 +306,9 @@ void C4Def::CompileFunc(StdCompiler *pComp)
|
|||
|
||||
//-------------------------------- C4Def -------------------------------------------------------
|
||||
|
||||
C4Def::C4Def(): Script(this)
|
||||
C4Def::C4Def(): Script(this), C4PropList(ScriptEngine.GetPropList())
|
||||
{
|
||||
assert(ScriptEngine.GetPropList());
|
||||
Graphics.pDef = this;
|
||||
Default();
|
||||
}
|
||||
|
|
|
@ -377,7 +377,7 @@ void C4AulScript::AddFunc(const char *pIdtf, C4ScriptFnDef* Def)
|
|||
/*--- C4AulScriptEngine ---*/
|
||||
|
||||
C4AulScriptEngine::C4AulScriptEngine():
|
||||
warnCnt(0), errCnt(0), nonStrictCnt(0), lineCnt(0)
|
||||
GlobalPropList(0), warnCnt(0), errCnt(0), nonStrictCnt(0), lineCnt(0)
|
||||
{
|
||||
// /me r b engine
|
||||
Engine = this;
|
||||
|
@ -392,6 +392,15 @@ C4AulScriptEngine::C4AulScriptEngine():
|
|||
GlobalConsts.SetNameList(&GlobalConstNames);
|
||||
}
|
||||
|
||||
C4PropList * C4AulScriptEngine::GetPropList()
|
||||
{
|
||||
if (!GlobalPropList)
|
||||
{
|
||||
GlobalPropList = C4PropList::NewScen();
|
||||
RegisterGlobalConstant("Global", C4VPropList(GlobalPropList));
|
||||
}
|
||||
return GlobalPropList;
|
||||
}
|
||||
|
||||
C4AulScriptEngine::~C4AulScriptEngine() { Clear(); }
|
||||
|
||||
|
@ -404,6 +413,7 @@ void C4AulScriptEngine::Clear()
|
|||
// clear inherited
|
||||
C4AulScript::Clear();
|
||||
// clear own stuff
|
||||
GetPropList()->Clear();
|
||||
// reset values
|
||||
warnCnt = errCnt = nonStrictCnt = lineCnt = 0;
|
||||
// resetting name lists will reset all data lists, too
|
||||
|
|
|
@ -449,6 +449,7 @@ class C4AulScriptEngine : public C4AulScript
|
|||
{
|
||||
protected:
|
||||
C4AulFuncMap FuncLookUp;
|
||||
C4PropList * GlobalPropList;
|
||||
|
||||
public:
|
||||
int warnCnt, errCnt; // number of warnings/errors
|
||||
|
@ -470,6 +471,7 @@ public:
|
|||
void Clear(); // clear data
|
||||
void Link(C4DefList *rDefs); // link and parse all scripts
|
||||
void ReLink(C4DefList *rDefs); // unlink + relink and parse all scripts
|
||||
virtual C4PropList * GetPropList();
|
||||
using C4AulScript::ReloadScript;
|
||||
bool ReloadScript(const char *szScript, C4DefList *pDefs, const char *szLanguage); // search script and reload + relink, if found
|
||||
C4AulFunc * GetFirstFunc(const char * Name)
|
||||
|
|
|
@ -209,8 +209,6 @@ bool C4AulScript::ReloadScript(const char *szPath, const char *szLanguage)
|
|||
|
||||
void C4AulScriptEngine::Link(C4DefList *rDefs)
|
||||
{
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
@ -228,6 +226,7 @@ void C4AulScriptEngine::Link(C4DefList *rDefs)
|
|||
|
||||
// get common funcs
|
||||
AfterLink();
|
||||
GlobalPropList->Freeze();
|
||||
|
||||
// non-strict scripts?
|
||||
if (nonStrictCnt)
|
||||
|
|
|
@ -143,7 +143,8 @@ C4GameScriptHost::~C4GameScriptHost() { }
|
|||
bool C4GameScriptHost::LoadScenarioScripts(C4Group &hGroup, C4LangStringTable *pLocalTable)
|
||||
{
|
||||
// Script
|
||||
ScenPrototype = C4PropList::NewScen();
|
||||
assert(ScriptEngine.GetPropList());
|
||||
ScenPrototype = C4PropList::NewScen(ScriptEngine.GetPropList());
|
||||
ScenPropList = C4PropList::NewScen(ScenPrototype);
|
||||
::ScriptEngine.RegisterGlobalConstant("Scenario", C4VPropList(ScenPropList));
|
||||
Reg2List(&ScriptEngine, &ScriptEngine);
|
||||
|
|
|
@ -131,6 +131,8 @@ StdStrBuf C4Value::GetDataString(int depth) const
|
|||
return StdStrBuf(Data ? "true" : "false");
|
||||
case C4V_PropList:
|
||||
{
|
||||
if (Data.PropList == ScriptEngine.GetPropList())
|
||||
return StdStrBuf("Global");
|
||||
StdStrBuf DataString;
|
||||
DataString = "{";
|
||||
if (Data.PropList->GetObject())
|
||||
|
@ -267,6 +269,8 @@ void C4Value::CompileFunc(StdCompiler *pComp, C4ValueNumbers * numbers)
|
|||
cC4VID = 'c';
|
||||
else if (getPropList() == GameScript.ScenPrototype)
|
||||
cC4VID = 't';
|
||||
else if (getPropList() == ScriptEngine.GetPropList())
|
||||
cC4VID = 'g';
|
||||
else
|
||||
cC4VID = 'E';
|
||||
break;
|
||||
|
@ -360,6 +364,11 @@ void C4Value::CompileFunc(StdCompiler *pComp, C4ValueNumbers * numbers)
|
|||
SetPropList(GameScript.ScenPrototype);
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
if (fCompiler)
|
||||
SetPropList(ScriptEngine.GetPropList());
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
case 'A': // compat with OC 5.1
|
||||
if (fCompiler)
|
||||
|
|
Loading…
Reference in New Issue