Ejemplo n.º 1
0
        /// Gets the local text array value assigned to a specific variable.
        /// </summary>
        /// <param name="name">the variable name</param>
        /// <returns></returns>
        public string[] GetLocalStringArrayVariableValue(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            if (svar == null ||
                svar.Type != ScriptConsts.TYPE_L_09_TEXT_ARR)
            {
                PooledStringBuilder sb =
                    StringBuilderPool.Instance.GetStringBuilder();
                try
                {
                    sb.Append("Local string array variable ");
                    sb.Append(name);
                    sb.Append(" was never set.");
                }
                catch (PooledException e)
                {
                    throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                }
                RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM,
                                                   sb.ToString());
                sb.ReturnToPool();
                throw ex;
            }
            return(svar.Textaval);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the local floating-point value assigned to a specific variable.
        /// </summary>
        /// <param name="name">the variable name</param>
        /// <returns></returns>
        public float GetLocalFloatVariableValue(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            if (svar == null ||
                svar.Type != ScriptConsts.TYPE_L_10_FLOAT)
            {
                PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
                try
                {
                    sb.Append("Local floating-point variable ");
                    sb.Append(name);
                    sb.Append(" was never set.");
                }
                catch (PooledException e)
                {
                    throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                }
                RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
                sb.ReturnToPool();
                sb = null;
                throw ex;
            }
            return(svar.Fval);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// ets a local <see cref="Scriptable"/> variable.
        /// </summary>
        /// <param name="index">the index of the variable</param>
        /// <returns></returns>
        public ScriptVariable GetLocalVariable(int index)
        {
            ScriptVariable svar = null;

            if (index >= 0 &&
                index < lvar.Length)
            {
                svar = lvar[index];
            }
            return(svar);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a local <see cref="Scriptable"/> variable.
        /// </summary>
        /// <param name="name">the name of the variable</param>
        /// <returns></returns>
        public ScriptVariable GetLocalVariable(string name)
        {
            ScriptVariable svar = null;

            for (int i = lvar.Length - 1; i >= 0; i--)
            {
                if (lvar[i] != null &&
                    lvar[i].Name != null &&
                    string.Equals(lvar[i].Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    svar = lvar[i];
                    break;
                }
            }
            return(svar);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the local integer array value assigned to a specific variable.
        /// </summary>
        /// <param name="name"> the variable name</param>
        /// <returns></returns>
        public int[] GetLocalIntArrayVariableValue(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            if (svar == null ||
                svar.Type != ScriptConsts.TYPE_L_13_INT_ARR)
            {
                PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
                sb.Append("Local floating-point variable ");
                sb.Append(name);
                sb.Append(" was never set.");
                RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
                sb.ReturnToPool();
                throw ex;
            }
            return(svar.Iaval);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a local variable.
        /// </summary>
        /// <param name="svar">the local variable</param>
        public void AddLocalVariable(ScriptVariable svar)
        {
            int index = -1;

            for (int i = 0; i < lvar.Length; i++)
            {
                if (lvar[i] == null)
                {
                    lvar[i] = svar;
                    index   = i;
                    break;
                }
            }
            if (index == -1)
            {
                lvar = ArrayUtilities.Instance.ExtendArray(svar, lvar);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Sets a local <see cref="ScriptVariable"/>.
 /// </summary>
 /// <param name="svar">the local <see cref="ScriptVariable"/></param>
 public void SetLocalVariable(ScriptVariable svar)
 {
     if (svar != null)
     {
         bool found = false;
         for (int i = lvar.Length - 1; i >= 0; i--)
         {
             if (lvar[i] != null &&
                 lvar[i].Name != null &&
                 string.Equals(lvar[i].Name, svar.Name, StringComparison.OrdinalIgnoreCase))
             {
                 lvar[i] = svar;
                 found   = true;
                 break;
             }
         }
         // if the local variable was not found
         if (!found)
         {
             // find an empty index
             int i = lvar.Length - 1;
             for (; i >= 0; i--)
             {
                 if (lvar[i] == null)
                 {
                     break;
                 }
             }
             if (i >= 0)
             {
                 lvar[i] = svar;
             }
             else
             {
                 lvar = ArrayUtilities.Instance.ExtendArray(svar, lvar);
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * Creates a new instance of <see cref="ScriptVariable"/>.
  * @param newName the variable name
  * @param newType the variable type
  * @param value the variable value
  * @ if the type is invalid
  */
 public ScriptVariable(ScriptVariable clone)
 {
     if (clone == null)
     {
         throw new RPGException(ErrorMessage.BAD_PARAMETERS, "Cannot clone from null!");
     }
     name = clone.name;
     type = clone.type;
     if (clone.faval != null)
     {
         faval = new float[clone.faval.Length];
         Array.Copy(clone.faval, faval, clone.faval.Length);
     }
     fval = clone.fval;
     if (clone.iaval != null)
     {
         iaval = new int[clone.iaval.Length];
         Array.Copy(clone.iaval, iaval, clone.iaval.Length);
     }
     ival = clone.ival;
     if (clone.laval != null)
     {
         laval = new long[clone.laval.Length];
         Array.Copy(clone.laval, laval, clone.laval.Length);
     }
     lval = clone.lval;
     if (clone.text != null)
     {
         text = new string(clone.text.ToCharArray());
     }
     if (clone.textaval != null)
     {
         textaval = new string[clone.textaval.Length];
         Array.Copy(clone.textaval, textaval, clone.textaval.Length);
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Sets a local <see cref="ScriptVariable"/>.
 /// </summary>
 /// <param name="index">the index of the variable</param>
 /// <param name="svar">the local <see cref="ScriptVariable"/></param>
 public void SetLocalVariable(int index, ScriptVariable svar)
 {
     // if the index number is valid
     if (index >= 0)
     {
         // if the local variables array needs to be extended, do so
         if (index >= lvar.Length)
         {
             lvar = ArrayUtilities.Instance.ExtendArray(svar, lvar);
         }
         else
         {
             lvar[index] = svar;
         }
     }
     else
     {
         PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
         try
         {
             sb.Append("Invalid array index ");
             sb.Append(index);
             sb.Append(".");
         }
         catch (PooledException e)
         {
             sb.ReturnToPool();
             sb = null;
             throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
         }
         RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
         sb.ReturnToPool();
         sb = null;
         throw ex;
     }
 }
Ejemplo n.º 10
0
        public int GetLocalVariableType(string name)
        {
            ScriptVariable svar = GetLocalVariable(name);

            return(svar.Type);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Sets a local variable.
        /// </summary>
        /// <param name="name">he name of the global variable</param>
        /// <param name="value">the variable's value</param>
        public void SetLocalVariable(string name, Object value)
        {
            bool found = false;

            for (int i = 0, len = lvar.Length; i < len; i++)
            {
                ScriptVariable svar = lvar[i];
                if (svar != null &&
                    svar.Name != null &&
                    string.Equals(svar.Name, name, StringComparison.OrdinalIgnoreCase))
                {
                    svar.Set(value);
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                // create a new variable and add to the global array
                ScriptVariable svar = null;
                if (value is string ||
                    value is char[])
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_08_TEXT,
                                              value);
                }
                else if (value is string[] ||
                         value is char[][])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_09_TEXT_ARR, value);
                }
                else if (value is float)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_10_FLOAT,
                                              value);
                }
                else if (value is Double)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_10_FLOAT,
                                              value);
                }
                else if (value is float[])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_11_FLOAT_ARR, value);
                }
                else if (value is int)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_12_INT,
                                              value);
                }
                else if (value is int[])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_13_INT_ARR, value);
                }
                else if (value is long)
                {
                    svar = new ScriptVariable(name, ScriptConsts.TYPE_L_14_LONG,
                                              value);
                }
                else if (value is long[])
                {
                    svar = new ScriptVariable(name,
                                              ScriptConsts.TYPE_L_15_LONG_ARR, value);
                }
                else
                {
                    PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();
                    try
                    {
                        sb.Append("Local variable ");
                        sb.Append(name);
                        sb.Append(" was passed new value of type ");
                        sb.Append(value.GetType().Name);
                        sb.Append(". Only string, Float, float[], Integer, int[],");
                        sb.Append(" Long, or long[] allowed.");
                    }
                    catch (PooledException e)
                    {
                        throw new RPGException(ErrorMessage.INTERNAL_ERROR, e);
                    }
                    RPGException ex = new RPGException(ErrorMessage.INVALID_PARAM, sb.ToString());
                    sb.ReturnToPool();
                    sb = null;
                    throw ex;
                }
                lvar = ArrayUtilities.Instance.ExtendArray(svar, lvar);
            }
        }