forked from Mirrors/openclonk
Clean up C4AulScriptFunc API
parent
65801a5188
commit
8091dff419
|
@ -220,21 +220,29 @@ std::string C4AulScript::Translate(const std::string &text) const
|
|||
throw C4LangStringTable::NoSuchTranslation(text);
|
||||
}
|
||||
|
||||
C4AulScriptFunc::C4AulScriptFunc(C4AulScript *pOwner, const char *pName):
|
||||
C4AulFunc(pOwner, pName), OwnerOverloaded(NULL), ParCount(0), tProfileTime(0)
|
||||
C4AulScriptFunc::C4AulScriptFunc(C4AulScript *pOwner, C4ScriptHost *pOrgScript, const char *pName, const char *Script):
|
||||
C4AulFunc(pOwner, pName),
|
||||
CodePos(0),
|
||||
Script(Script),
|
||||
OwnerOverloaded(NULL),
|
||||
ParCount(0),
|
||||
pOrgScript(pOrgScript),
|
||||
tProfileTime(0)
|
||||
{
|
||||
for (int i = 0; i < C4AUL_MAX_Par; i++) ParType[i] = C4V_Any;
|
||||
}
|
||||
|
||||
void C4AulScriptFunc::CopyBody(C4AulScriptFunc &FromFunc)
|
||||
C4AulScriptFunc::C4AulScriptFunc(C4AulScript *pOwner, const C4AulScriptFunc &FromFunc):
|
||||
C4AulFunc(pOwner, FromFunc.GetName()),
|
||||
CodePos(0),
|
||||
Script(FromFunc.Script),
|
||||
VarNamed(FromFunc.VarNamed),
|
||||
ParNamed(FromFunc.ParNamed),
|
||||
OwnerOverloaded(NULL),
|
||||
ParCount(FromFunc.ParCount),
|
||||
pOrgScript(FromFunc.pOrgScript),
|
||||
tProfileTime(0)
|
||||
{
|
||||
// copy some members, that are set before linking
|
||||
Access = FromFunc.Access;
|
||||
Script = FromFunc.Script;
|
||||
VarNamed = FromFunc.VarNamed;
|
||||
ParNamed = FromFunc.ParNamed;
|
||||
ParCount = FromFunc.ParCount;
|
||||
pOrgScript = FromFunc.pOrgScript;
|
||||
for (int i = 0; i < C4AUL_MAX_Par; i++)
|
||||
ParType[i] = FromFunc.ParType[i];
|
||||
}
|
||||
|
@ -376,16 +384,12 @@ std::list<const char*> C4AulScriptEngine::GetFunctionNames(C4AulScript * script)
|
|||
{
|
||||
if ((pRef = f->SFunc()))
|
||||
{
|
||||
// Public functions only
|
||||
if (pRef->Access == AA_PUBLIC)
|
||||
{
|
||||
// Insert divider if necessary
|
||||
if (!divider)
|
||||
functions.push_back(0);
|
||||
divider = true;
|
||||
// Add function
|
||||
functions.push_back(pRef->GetName());
|
||||
}
|
||||
// Insert divider if necessary
|
||||
if (!divider)
|
||||
functions.push_back(0);
|
||||
divider = true;
|
||||
// Add function
|
||||
functions.push_back(pRef->GetName());
|
||||
}
|
||||
f = f->Prev;
|
||||
}
|
||||
|
|
|
@ -253,7 +253,6 @@ protected:
|
|||
int CodePos; // code pos
|
||||
|
||||
public:
|
||||
C4AulAccess Access;
|
||||
const char *Script; // script pos
|
||||
C4ValueMapNames VarNamed; // list of named vars in this function
|
||||
C4ValueMapNames ParNamed; // list of named pars in this function
|
||||
|
@ -262,7 +261,8 @@ public:
|
|||
void AddPar(const char * Idtf) { ParNamed.AddName(Idtf); ++ParCount; }
|
||||
C4ScriptHost *pOrgScript; // the orginal script (!= Owner if included or appended)
|
||||
|
||||
C4AulScriptFunc(C4AulScript *pOwner, const char *pName);
|
||||
C4AulScriptFunc(C4AulScript *pOwner, C4ScriptHost *pOrgScript, const char *pName, const char *Script);
|
||||
C4AulScriptFunc(C4AulScript *pOwner, const C4AulScriptFunc &FromFunc); // copy script/code, etc from given func
|
||||
|
||||
void ParseFn(C4AulScriptContext* context = NULL);
|
||||
virtual void UnLink();
|
||||
|
@ -276,8 +276,6 @@ public:
|
|||
|
||||
void SetError(C4AulContext *ctx, const char *szMessage); // set error message
|
||||
|
||||
void CopyBody(C4AulScriptFunc &FromFunc); // copy script/code, etc from given func
|
||||
|
||||
int GetLineOfCode(C4AulBCC * bcc);
|
||||
C4AulBCC * GetCode();
|
||||
C4ScriptHost * GetCodeOwner();
|
||||
|
|
|
@ -1107,9 +1107,7 @@ C4Value C4AulScript::DirectExec(C4Object *pObj, const char *szScript, const char
|
|||
C4ScriptHost* pScript = new C4DirectExecScript(this, pObj, szContext, stringTable);
|
||||
pScript->Reg2List(Engine, this);
|
||||
// Add a new function
|
||||
C4AulScriptFunc *pFunc = new C4AulScriptFunc(pScript, 0);
|
||||
pFunc->Script = szScript;
|
||||
pFunc->pOrgScript = pScript;
|
||||
C4AulScriptFunc *pFunc = new C4AulScriptFunc(pScript, pScript, 0, szScript);
|
||||
// Parse function
|
||||
try
|
||||
{
|
||||
|
@ -1125,7 +1123,7 @@ C4Value C4AulScript::DirectExec(C4Object *pObj, const char *szScript, const char
|
|||
return C4VNull;
|
||||
}
|
||||
pScript->State = ASS_PARSED;
|
||||
// Execute. The TemporaryScript-parameter makes sure the script will be deleted later on.
|
||||
// Execute. The TemporaryScript-parameter makes sure the script will be deleted.
|
||||
C4Value vRetVal(AulExec.Exec(pFunc, pObj, NULL, fPassErrors, true));
|
||||
// profiler
|
||||
AulExec.StopDirectExec();
|
||||
|
|
|
@ -1378,13 +1378,13 @@ void C4AulParseState::Parse_Function()
|
|||
if (Acc == AA_GLOBAL)
|
||||
{
|
||||
// global func
|
||||
Fn = new C4AulScriptFunc(a->Engine, Idtf);
|
||||
Fn = new C4AulScriptFunc(a->Engine, pOrgScript, Idtf, SPos);
|
||||
Acc = AA_PUBLIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal, local func
|
||||
Fn = new C4AulScriptFunc(a, Idtf);
|
||||
Fn = new C4AulScriptFunc(a, pOrgScript, Idtf, SPos);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1408,9 +1408,6 @@ void C4AulParseState::Parse_Function()
|
|||
if (Fn->GetCodeOwner() == a)
|
||||
Fn->CodePos = a->Code.size();
|
||||
}
|
||||
// set up func (in the case we got an error)
|
||||
Fn->Script = SPos;
|
||||
Fn->Access = Acc; Fn->pOrgScript = pOrgScript;
|
||||
Shift();
|
||||
// expect an opening bracket now
|
||||
if (TokenType != ATT_BOPEN)
|
||||
|
@ -2901,12 +2898,11 @@ bool C4ScriptHost::Parse()
|
|||
// append all funcs
|
||||
C4AulScriptFunc *sf;
|
||||
for (C4AulFunc *f = (*s)->Func0; f; f = f->Next)
|
||||
// script funcs only, no need to append global funcs
|
||||
if ((sf = f->SFunc()) && sf->Access != AA_GLOBAL && sf->pOrgScript == *s)
|
||||
// funcs from other scripts get appended directly from their script
|
||||
if ((sf = f->SFunc()) && sf->pOrgScript == *s)
|
||||
{
|
||||
// append: create copy
|
||||
C4AulScriptFunc *sfc = new C4AulScriptFunc(this, sf->GetName());
|
||||
sfc->CopyBody(*sf);
|
||||
C4AulScriptFunc *sfc = new C4AulScriptFunc(this, *sf);
|
||||
}
|
||||
// copy local var definitions
|
||||
for (int ivar = 0; ivar < (*s)->LocalNamed.iSize; ivar ++)
|
||||
|
|
|
@ -328,13 +328,13 @@ C4ValueMapNames::C4ValueMapNames()
|
|||
|
||||
}
|
||||
|
||||
C4ValueMapNames::C4ValueMapNames(C4ValueMapNames& NamesToCopy)
|
||||
C4ValueMapNames::C4ValueMapNames(const C4ValueMapNames& NamesToCopy)
|
||||
: pNames(0), iSize(0), pFirst(0)
|
||||
{
|
||||
ChangeNameList(const_cast<const char **>(NamesToCopy.pNames), NamesToCopy.iSize);
|
||||
}
|
||||
|
||||
C4ValueMapNames& C4ValueMapNames::operator = (C4ValueMapNames &NamesToCopy)
|
||||
C4ValueMapNames& C4ValueMapNames::operator = (const C4ValueMapNames &NamesToCopy)
|
||||
{
|
||||
ChangeNameList(const_cast<const char **>(NamesToCopy.pNames), NamesToCopy.iSize);
|
||||
return *this;
|
||||
|
|
|
@ -102,8 +102,8 @@ public:
|
|||
|
||||
// construction/destruction
|
||||
C4ValueMapNames();
|
||||
C4ValueMapNames(C4ValueMapNames& NamesToCopy);
|
||||
C4ValueMapNames& operator = (C4ValueMapNames &NamesToCopy);
|
||||
C4ValueMapNames(const C4ValueMapNames& NamesToCopy);
|
||||
C4ValueMapNames& operator = (const C4ValueMapNames &NamesToCopy);
|
||||
virtual ~C4ValueMapNames();
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue