Skip to content

Commit

Permalink
Changed RegisterCallback to allow a Func object in place of a name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexikos committed Jan 20, 2012
1 parent 32aa3ab commit 54c7232
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions source/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,7 @@ double TokenToDouble(ExprTokenType &aToken, BOOL aCheckForHex = TRUE, BOOL aIsPu
LPTSTR TokenToString(ExprTokenType &aToken, LPTSTR aBuf = NULL);
ResultType TokenToDoubleOrInt64(ExprTokenType &aToken);
IObject *TokenToObject(ExprTokenType &aToken); // L31
Func *TokenToFunc(ExprTokenType &aToken);
ResultType TokenSetResult(ExprTokenType &aResultToken, LPCTSTR aResult, size_t aResultLength = -1);

LPTSTR RegExMatch(LPTSTR aHaystack, LPTSTR aNeedleRegEx);
Expand Down
20 changes: 13 additions & 7 deletions source/script2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15089,9 +15089,7 @@ void BIF_IsFunc(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParam
// dynamic function-call fails when too few parameters are passed (but not too many), it seems best to
// indicate to the caller not only that the function exists, but also how many parameters are required.
{
Func *func;
if ( !(func = dynamic_cast<Func *>(TokenToObject(*aParam[0]))) )
func = g_script.FindFunc(TokenToString(*aParam[0], aResultToken.buf));
Func *func = TokenToFunc(*aParam[0]);
aResultToken.value_int64 = func ? (__int64)func->mMinParams+1 : 0;
}

Expand Down Expand Up @@ -15916,11 +15914,8 @@ void BIF_RegisterCallback(ExprTokenType &aResultToken, ExprTokenType *aParam[],
aResultToken.marker = _T("");

// Loadtime validation has ensured that at least 1 parameter is present.
TCHAR func_buf[MAX_NUMBER_SIZE], *func_name;
Func *func;
if ( !*(func_name = TokenToString(*aParam[0], func_buf)) // Blank function name or...
|| !(func = g_script.FindFunc(func_name)) // ...the function doesn't exist or...
|| func->mIsBuiltIn ) // ...the function is built-in.
if ( !(func = TokenToFunc(*aParam[0])) || func->mIsBuiltIn ) // Not a valid user-defined function.
return; // Indicate failure by yielding the default result set earlier.

LPTSTR options = (aParamCount < 2) ? _T("") : TokenToString(*aParam[1]);
Expand Down Expand Up @@ -17892,6 +17887,17 @@ IObject *TokenToObject(ExprTokenType &aToken)



Func *TokenToFunc(ExprTokenType &aToken)
{
TCHAR buf[MAX_NUMBER_SIZE];
Func *func;
if ( !(func = dynamic_cast<Func *>(TokenToObject(aToken))) )
func = g_script.FindFunc(TokenToString(aToken, buf));
return func;
}



ResultType TokenSetResult(ExprTokenType &aResultToken, LPCTSTR aResult, size_t aResultLength)
// Utility function for handling memory allocation and return to callers of built-in functions; based on BIF_SubStr.
// Returns FAIL if malloc failed, in which case our caller is responsible for returning a sensible default value.
Expand Down

0 comments on commit 54c7232

Please sign in to comment.