1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef USCRIPT_FUNCTION_H 16 #define USCRIPT_FUNCTION_H 17 18 #include <vector> 19 #include "script_context.h" 20 #include "script_statement.h" 21 22 namespace Uscript { 23 class UScriptStatementList; 24 class ScriptParams; 25 26 class ScriptFunction { 27 public: CreateInstance(std::string & identifier,ScriptParams * params,UScriptStatementList * list)28 static ScriptFunction* CreateInstance(std::string &identifier, ScriptParams *params, 29 UScriptStatementList *list) 30 { 31 return new ScriptFunction(identifier, params, list); 32 } 33 34 public: ScriptFunction(std::string & functionName,ScriptParams * params,UScriptStatementList * list)35 ScriptFunction(std::string& functionName, ScriptParams *params, UScriptStatementList *list) 36 : functionName_(functionName), params_(params), statements_(list) 37 { 38 } 39 ~ScriptFunction(); GetFunctionName()40 const std::string GetFunctionName() 41 { 42 return functionName_; 43 } 44 UScriptValuePtr Execute(ScriptInterpreter &inter, UScriptContextPtr local, ScriptParams *params); 45 46 private: 47 std::vector<std::string> GetParamNames(ScriptInterpreter &inter, UScriptContextPtr context) const; 48 std::string functionName_; 49 ScriptParams* params_ = nullptr; 50 UScriptStatementList* statements_ = nullptr; 51 }; 52 } // namespace Uscript 53 #endif // USCRIPT_FUNCTION_H 54