forked from Mirrors/openclonk
Script: Call can execute functions directly
Call(this["foo"],...) is now the same as Call("foo",...).
parent
fb9309ec2c
commit
8cf2b6adf1
|
@ -8,11 +8,12 @@
|
|||
<category>Script</category>
|
||||
<subcat>Function call</subcat>
|
||||
<version>5.1 OC</version>
|
||||
<extversion>5.4 OC</extversion>
|
||||
<syntax>
|
||||
<rtype>any</rtype>
|
||||
<params>
|
||||
<param>
|
||||
<type>string</type>
|
||||
<type>string or function</type>
|
||||
<name>function</name>
|
||||
<desc>Function to be called.</desc>
|
||||
</param>
|
||||
|
@ -23,11 +24,12 @@
|
|||
</param>
|
||||
</params>
|
||||
</syntax>
|
||||
<desc>Calls the local function function. If "~" is prepended to the function name then the call does not fail if the function does not exist.</desc>
|
||||
<desc>Calls the specified function. If given a string, the function is looked up in the context object (<code>this</code>). For example, <code>obj->Call("Foo")</code> is the same as <code>obj->Foo()</code>. Using Call like this is primarily useful when the name of the function can vary. If "~" is prepended to the function name then the call does not fail if the function does not exist.</desc>
|
||||
<related>
|
||||
<funclink>GameCall</funclink>
|
||||
<funclink>eval</funclink>
|
||||
</related>
|
||||
</func>
|
||||
<author>jwk</author><date>2002-04</date>
|
||||
<author>Günther</author><date>2012</date>
|
||||
</funcs>
|
||||
|
|
|
@ -1059,13 +1059,6 @@ C4Object* FnObject(C4PropList * _this, long iNumber)
|
|||
// See FnObjectNumber
|
||||
}
|
||||
|
||||
static C4Value FnCall(C4PropList * _this, C4Value * Pars)
|
||||
{
|
||||
if (!_this) return C4Value();
|
||||
C4AulParSet ParSet(&Pars[1], 9);
|
||||
return _this->CallOrThrow(FnStringPar(Pars[0].getStr()), &ParSet);
|
||||
}
|
||||
|
||||
static C4Value FnGameCall(C4PropList * _this, C4Value * Pars)
|
||||
{
|
||||
C4String * fn = Pars[0].getStr();
|
||||
|
@ -2588,7 +2581,6 @@ C4ScriptFnDef C4ScriptGameFnMap[]=
|
|||
{ "ObjectCount", 1, C4V_Int, { C4V_Array ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnObjectCount },
|
||||
{ "GameCall", 1, C4V_Any, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnGameCall },
|
||||
{ "GameCallEx", 1, C4V_Any, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnGameCallEx },
|
||||
{ "Call", 1, C4V_Any, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnCall },
|
||||
{ "PlayerMessage", 1, C4V_Int, { C4V_Int ,C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnPlayerMessage },
|
||||
{ "Message", 1, C4V_Bool, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnMessage },
|
||||
{ "AddMessage", 1, C4V_Bool, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnAddMessage },
|
||||
|
|
|
@ -41,7 +41,8 @@ inline C4Object * Object(C4PropList * _this)
|
|||
StdStrBuf FnStringFormat(C4PropList * _this, C4String *szFormatPar, C4Value * Pars, int ParCount);
|
||||
|
||||
template <typename T> struct C4ValueConv;
|
||||
// Allow parameters to be nil
|
||||
// Allow integer and boolean parameters to be nil
|
||||
// pointer parameters represent nil via plain NULL
|
||||
template<typename T>
|
||||
class Nillable
|
||||
{
|
||||
|
|
|
@ -490,18 +490,6 @@ C4Value C4PropList::Call(const char * s, C4AulParSet *Pars)
|
|||
return pFn->Exec(this, Pars);
|
||||
}
|
||||
|
||||
C4Value C4PropList::CallOrThrow(const char * s, C4AulParSet *Pars)
|
||||
{
|
||||
C4AulFunc *pFn = Status ? GetFunc(s) : NULL;
|
||||
if (!pFn)
|
||||
{
|
||||
if (s[0] == '~')
|
||||
return C4Value();
|
||||
throw new C4AulExecError(FormatString("Call: no function \"%s\"", s).getData());
|
||||
}
|
||||
return pFn->Exec(this, Pars);
|
||||
}
|
||||
|
||||
C4PropertyName C4PropList::GetPropertyP(C4PropertyName n) const
|
||||
{
|
||||
C4String * k = &Strings.P[n];
|
||||
|
|
|
@ -98,7 +98,6 @@ public:
|
|||
{ return Call(&Strings.P[k], pPars); }
|
||||
C4Value Call(C4String * k, C4AulParSet *pPars=0);
|
||||
C4Value Call(const char * k, C4AulParSet *pPars=0);
|
||||
C4Value CallOrThrow(const char * k, C4AulParSet *pPars=0);
|
||||
C4PropertyName GetPropertyP(C4PropertyName k) const;
|
||||
int32_t GetPropertyInt(C4PropertyName k) const;
|
||||
bool HasProperty(C4String * k) { return Properties.Has(k); }
|
||||
|
|
|
@ -215,6 +215,28 @@ static C4ValueArray * FnGetProperties(C4PropList * _this, C4PropList * p)
|
|||
return r;
|
||||
}
|
||||
|
||||
static C4Value FnCall(C4PropList * _this, C4Value * Pars)
|
||||
{
|
||||
if (!_this) return C4Value();
|
||||
C4AulParSet ParSet(&Pars[1], 9);
|
||||
C4AulFunc * fn = Pars[0].getFunction();
|
||||
if (!fn)
|
||||
fn = _this->GetFunc(Pars[0].getStr());
|
||||
if (!fn)
|
||||
{
|
||||
const char * s = FnStringPar(Pars[0].getStr());
|
||||
if (s[0] == '~')
|
||||
{
|
||||
fn = _this->GetFunc(&s[1]);
|
||||
if (!fn)
|
||||
return C4Value();
|
||||
}
|
||||
}
|
||||
if (!fn)
|
||||
throw new C4AulExecError(FormatString("Call: no function %s", Pars[0].GetDataString().getData()).getData());
|
||||
return fn->Exec(_this, &ParSet, true);
|
||||
}
|
||||
|
||||
static C4Value FnLog(C4PropList * _this, C4Value * Pars)
|
||||
{
|
||||
Log(FnStringFormat(_this, Pars[0].getStr(), &Pars[1], 9).getData());
|
||||
|
@ -579,6 +601,7 @@ C4ScriptConstDef C4ScriptConstMap[]=
|
|||
|
||||
C4ScriptFnDef C4ScriptFnMap[]=
|
||||
{
|
||||
{ "Call", 1, C4V_Any, { C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnCall },
|
||||
{ "Log", 1, C4V_Bool, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnLog },
|
||||
{ "DebugLog", 1, C4V_Bool, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnDebugLog },
|
||||
{ "Format", 1, C4V_String, { C4V_String ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any ,C4V_Any}, FnFormat },
|
||||
|
|
Loading…
Reference in New Issue