2012-05-14 20:07:33 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 2001, 2007, Sven Eberhardt
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2011-2016, The OpenClonk Team and contributors
|
2012-05-14 20:07:33 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2012-05-14 20:07:33 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2012-05-14 20:07:33 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2012-05-14 20:07:33 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "C4Include.h"
|
|
|
|
#include "script/C4Value.h"
|
|
|
|
#include "script/C4AulFunc.h"
|
|
|
|
#include "script/C4Aul.h"
|
2012-05-14 20:07:33 +00:00
|
|
|
|
2014-04-20 13:52:09 +00:00
|
|
|
C4AulFunc::C4AulFunc(C4PropListStatic * Parent, const char *pName):
|
|
|
|
Parent(Parent),
|
2017-05-03 18:28:00 +00:00
|
|
|
Name(pName ? Strings.RegString(pName) : nullptr),
|
2016-11-02 23:58:02 +00:00
|
|
|
MapNext(nullptr)
|
2012-05-14 20:07:33 +00:00
|
|
|
{
|
|
|
|
// add to global lookuptable with this name
|
|
|
|
if (GetName())
|
2012-10-14 18:45:35 +00:00
|
|
|
::ScriptEngine.FuncLookUp.Add(this);
|
2012-05-14 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
C4AulFunc::~C4AulFunc()
|
|
|
|
{
|
2012-10-14 18:45:35 +00:00
|
|
|
if (GetName())
|
|
|
|
::ScriptEngine.FuncLookUp.Remove(this);
|
2012-05-14 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 12:44:30 +00:00
|
|
|
StdStrBuf C4AulFunc::GetFullName() const
|
2012-05-14 20:07:33 +00:00
|
|
|
{
|
|
|
|
StdStrBuf r;
|
|
|
|
// "lost" function?
|
2014-04-20 13:52:09 +00:00
|
|
|
if (!Parent)
|
2012-05-14 20:07:33 +00:00
|
|
|
{
|
|
|
|
r.Ref("(unowned) ");
|
|
|
|
}
|
2014-04-20 13:52:09 +00:00
|
|
|
else
|
2012-05-14 20:07:33 +00:00
|
|
|
{
|
2014-04-20 13:52:09 +00:00
|
|
|
r.Take(Parent->GetDataString());
|
2012-05-14 20:07:33 +00:00
|
|
|
r.AppendChar('.');
|
|
|
|
}
|
2014-04-20 13:52:09 +00:00
|
|
|
if (GetName())
|
|
|
|
r.Append(Name->GetData());
|
2012-05-14 20:07:33 +00:00
|
|
|
else
|
2014-04-20 13:52:09 +00:00
|
|
|
r.Append("(unnamed)");
|
2012-05-14 20:07:33 +00:00
|
|
|
return r;
|
|
|
|
}
|
2014-04-17 15:20:46 +00:00
|
|
|
|
2015-01-30 19:33:57 +00:00
|
|
|
bool C4AulFunc::CheckParTypes(const C4Value pPars[], bool fPassErrors) const {
|
2014-04-17 15:20:46 +00:00
|
|
|
// Convert parameters (typecheck)
|
|
|
|
const C4V_Type *pTypes = GetParType();
|
2014-04-19 17:01:35 +00:00
|
|
|
int parcount = GetParCount();
|
|
|
|
for (int i = 0; i < parcount; i++) {
|
2014-04-17 15:20:46 +00:00
|
|
|
if (!pPars[i].CheckParConversion(pTypes[i]))
|
2015-01-30 19:33:57 +00:00
|
|
|
{
|
|
|
|
C4AulExecError e(FormatString(
|
2017-05-03 18:28:00 +00:00
|
|
|
R"(call to "%s" parameter %d: passed %s, but expected %s)",
|
2015-01-30 19:33:57 +00:00
|
|
|
GetName(), i + 1, pPars[i].GetTypeName(), GetC4VName(pTypes[i])).getData());
|
|
|
|
if (fPassErrors)
|
|
|
|
throw e;
|
|
|
|
else
|
|
|
|
{
|
2016-07-25 12:57:54 +00:00
|
|
|
::ScriptEngine.GetErrorHandler()->OnError(e.what());
|
2015-01-30 19:33:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-04-17 15:20:46 +00:00
|
|
|
}
|
2015-01-30 19:33:57 +00:00
|
|
|
return true;
|
2014-04-17 15:20:46 +00:00
|
|
|
}
|