Exemplo n.º 1
0
        private void ProcessHOST()
        {
            // get function proto
            HostFunctionPrototype hostFunctionPrototype
                = m_scriptInstruction.Operand0.HostFunctionRef;

            // determine which handler to use
            HostFunctionHandler hostFunctionHandler = null;

            if (hostFunctionPrototype.Handler == null)
            {
                // if prototype handler not set, but
                // context handler set, use it
                if (m_scriptHandler != null)
                {
                    hostFunctionHandler = m_scriptHandler;
                }
            }
            else
            {
                // prefer prototype handler over context handler
                hostFunctionHandler = hostFunctionPrototype.Handler;
            }

            // pop values from stack into list
            List <object> listParameters = new List <object>();

            for (int iIndex = 0; iIndex < hostFunctionPrototype.ParameterTypes.Count; iIndex++)
            {
                listParameters.Insert(0, m_stackParameters.Pop());
            }

            // verify param list against proto
            hostFunctionPrototype.VerifyParameters(listParameters);

            // delegate call to handler (if set)
            object objectResult = null;

            if (hostFunctionHandler != null)
            {
                objectResult = hostFunctionHandler.OnHostFunctionCall(
                    hostFunctionPrototype.Name, listParameters);

                // verify result against proto
                hostFunctionPrototype.VerifyResult(objectResult);
            }

            // push result into stack
            if (objectResult == null)
            {
                objectResult = NullReference.Instance;
            }
            m_stackParameters.Push(objectResult);

            if (m_bInterruptOnHostfunctionCall)
            {
                m_bInterruped = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers the given <see cref="HostFunctionPrototype"/> with an
        /// accompanying <see cref="HostFunctionHandler"/>. Handlers
        /// defined at <see cref="ScriptContext"/> level for this function
        /// are ignored.
        /// </summary>
        /// <param name="hostFunctionPrototype">Host function prototype to
        /// register.</param>
        /// <param name="hostFunctionHandler">Handler associated with the
        /// host function.</param>
        public void RegisterHostFunction(
            HostFunctionPrototype hostFunctionPrototype,
            HostFunctionHandler hostFunctionHandler)
        {
            String strName = hostFunctionPrototype.Name;

            if (m_dictHostFunctionPrototypes.ContainsKey(strName))
            {
                throw new UbikException(
                          "Host function '" + strName + "' already registered.");
            }

            hostFunctionPrototype.Handler         = hostFunctionHandler;
            m_dictHostFunctionPrototypes[strName] = hostFunctionPrototype;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Registers the given <see cref="HostFunctionPrototype"/> without
 /// a handler. If a <see cref="Script"/> uses the given host
 /// function, the handler must be bound at
 /// <see cref="ScriptContext"/> level.
 /// </summary>
 /// <param name="hostFunctionPrototype">Host function prototype to
 /// register.</param>
 public void RegisterHostFunction(
     HostFunctionPrototype hostFunctionPrototype)
 {
     RegisterHostFunction(hostFunctionPrototype, null);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a <see cref="HostFunctionPrototype"/> reference.
 /// </summary>
 /// <param name="hostFunctionPrototype">Host function referred by
 /// the operand.</param>
 /// <returns>Host function reference operand.</returns>
 public static Operand CreateHostFunctionRef(
     HostFunctionPrototype hostFunctionPrototype)
 {
     return(new Operand(OperandType.HostFunctionRef, hostFunctionPrototype, null));
 }