Beispiel #1
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            var methodIdx = target.FindMethod(methodName);
            var methInfo  = target.GetMethodInfo(methodIdx);

            var argsToPass = GetArgsToPass(arguments, methInfo);

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, argsToPass, out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, argsToPass);
            }

            if (arguments != null)
            {
                for (int i = 0; i < argsToPass.Length; i++)
                {
                    if (i < arguments.Count())
                    {
                        arguments.Set(i, argsToPass[i]?.GetRawValue());
                    }
                }
            }

            return(retValue);
        }
Beispiel #2
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, IRuntimeContextInstance arguments = null)
        {
            ArrayImpl argArray;

            if (arguments != null)
            {
                argArray = arguments as ArrayImpl;
                if (argArray == null)
                {
                    throw RuntimeException.InvalidArgumentType();
                }
            }
            else
            {
                argArray = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var    methInfo = target.GetMethodInfo(methodIdx);
            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, argArray.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, argArray.ToArray());
            }

            return(retValue);
        }
Beispiel #3
0
        public IValue CallMethod(IRuntimeContextInstance target, string methodName, ArrayImpl arguments = null)
        {
            if (arguments == null)
            {
                arguments = new ArrayImpl();
            }

            var methodIdx = target.FindMethod(methodName);

            var methInfo = target.GetMethodInfo(methodIdx);

            if (methInfo.ArgCount < arguments.Count())
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            if (methInfo.ArgCount > arguments.Count())
            {
                throw RuntimeException.TooLittleArgumentsPassed();
            }

            IValue retValue = ValueFactory.Create();

            if (methInfo.IsFunction)
            {
                target.CallAsFunction(methodIdx, arguments.ToArray(), out retValue);
            }
            else
            {
                target.CallAsProcedure(methodIdx, arguments.ToArray());
            }

            return(retValue);
        }
        public void CallCommonModuleProcedure(string moduleName, string methodName, IValue[] parameters)
        {
            IRuntimeContextInstance commonModule = (IRuntimeContextInstance)_hostedScript.EngineInstance.Environment.GetGlobalProperty(moduleName);
            int methodId = commonModule.FindMethod(methodName);

            commonModule.CallAsProcedure(methodId, parameters);
        }
 public void CallAsProcedure(int methodNumber, IValue[] arguments)
 {
     _inst.CallAsProcedure(_methRedirects[methodNumber], arguments);
 }