forked from Mirrors/openclonk
Add num and float type specifiers for function parameters
Also, add C4Real to the template magic for engine script functionsfloating-point
parent
a464332ec7
commit
7e0a51c0c7
|
@ -149,9 +149,16 @@ template <> struct C4ValueConv<int32_t>
|
|||
{
|
||||
inline static C4V_Type Type() { return C4V_Int; }
|
||||
inline static int32_t FromC4V(C4Value &v) { return v.getInt(); }
|
||||
inline static int32_t _FromC4V(C4Value &v) { return v._getInt(); }
|
||||
inline static int32_t _FromC4V(C4Value &v) { return v.getInt(); }
|
||||
inline static C4Value ToC4V(int32_t v) { return C4VInt(v); }
|
||||
};
|
||||
template <> struct C4ValueConv<C4Real>
|
||||
{
|
||||
inline static C4V_Type Type() { return C4V_Float; }
|
||||
inline static C4Real FromC4V(C4Value &v) { return v.getFloat(); }
|
||||
inline static C4Real _FromC4V(C4Value &v) { return v.getFloat(); }
|
||||
inline static C4Value ToC4V(C4Real v) { return C4Value(v); }
|
||||
};
|
||||
template <> struct C4ValueConv<C4Numeric>
|
||||
{
|
||||
inline static C4V_Type Type() { return C4V_Numeric; }
|
||||
|
|
|
@ -801,6 +801,9 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4
|
|||
C4AulScriptFunc *pSFunc = pFunc->SFunc();
|
||||
if (pSFunc)
|
||||
{
|
||||
// Convert numeric parameters
|
||||
for (int i = 0; i < pFunc->GetParCount(); i++)
|
||||
pPars[i].NumericConversion(pTypes[i]); // Enforce numerics to have the right type, does nothing for other variables
|
||||
// Push a new context
|
||||
C4AulScriptContext ctx;
|
||||
ctx.Obj = pContext ? pContext->GetObject() : 0;
|
||||
|
|
|
@ -79,6 +79,8 @@
|
|||
#define C4AUL_VarNamed "var"
|
||||
|
||||
#define C4AUL_TypeInt "int"
|
||||
#define C4AUL_TypeFloat "float"
|
||||
#define C4AUL_TypeNumeric "num"
|
||||
#define C4AUL_TypeBool "bool"
|
||||
#define C4AUL_TypeC4ID "id"
|
||||
#define C4AUL_TypeDef "def"
|
||||
|
@ -666,6 +668,7 @@ static const char * GetTTName(C4AulBCCType e)
|
|||
case AB_CALLFS: return "CALLFS"; // failsafe direct call
|
||||
case AB_STACK: return "STACK"; // push nulls / pop
|
||||
case AB_INT: return "INT"; // constant: int
|
||||
case AB_FLOAT: return "FLOAT"; // constant: float
|
||||
case AB_BOOL: return "BOOL"; // constant: bool
|
||||
case AB_STRING: return "STRING"; // constant: string
|
||||
case AB_CPROPLIST: return "CPROPLIST"; // constant: proplist
|
||||
|
@ -1437,6 +1440,8 @@ void C4AulParseState::Parse_Function()
|
|||
// type identifier?
|
||||
C4V_Type t = C4V_Any;
|
||||
if (SEqual(Idtf, C4AUL_TypeInt)) { t = C4V_Int; Shift(); }
|
||||
else if (SEqual(Idtf, C4AUL_TypeNumeric)) { t = C4V_Numeric; Shift(); }
|
||||
else if (SEqual(Idtf, C4AUL_TypeFloat)) { t = C4V_Float; Shift(); }
|
||||
else if (SEqual(Idtf, C4AUL_TypeBool)) { t = C4V_Bool; Shift(); }
|
||||
else if (SEqual(Idtf, C4AUL_TypeC4ID)) { t = C4V_Def; Shift(); }
|
||||
else if (SEqual(Idtf, C4AUL_TypeDef)) { t = C4V_Def; Shift(); }
|
||||
|
|
|
@ -583,7 +583,7 @@ C4ScriptConstDef C4ScriptConstMap[]=
|
|||
{
|
||||
{ "C4V_Nil", C4V_Int, C4V_Nil},
|
||||
{ "C4V_Int", C4V_Int, C4V_Int},
|
||||
{ "C4V_Float", C4V_Int, C4V_Int},
|
||||
{ "C4V_Float", C4V_Int, C4V_Float},
|
||||
{ "C4V_Bool", C4V_Int, C4V_Bool},
|
||||
{ "C4V_C4Object", C4V_Int, C4V_Object},
|
||||
{ "C4V_Effect", C4V_Int, C4V_Effect},
|
||||
|
|
|
@ -327,6 +327,18 @@ public:
|
|||
}
|
||||
}
|
||||
static bool WarnAboutConversion(C4V_Type Type, C4V_Type vtToType);
|
||||
inline void NumericConversion(C4V_Type vToType)
|
||||
{
|
||||
if(Type == vToType) return;
|
||||
if(Type != C4V_Nil && Type != C4V_Int && Type != C4V_Float && Type != C4V_Nil) return;
|
||||
switch(vToType)
|
||||
{
|
||||
case C4V_Bool: SetBool(getBool()); return;
|
||||
case C4V_Int: SetInt(getInt()); return;
|
||||
case C4V_Float: SetFloat(getFloat()); return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// Compilation
|
||||
void CompileFunc(StdCompiler *pComp, C4ValueNumbers *);
|
||||
|
|
Loading…
Reference in New Issue