Пример #1
0
        /// <summary>
        /// Checks if the type is a specific userdata type, and returns it or throws.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="funcName">Name of the function.</param>
        /// <param name="argNum">The argument number.</param>
        /// <param name="flags">The flags.</param>
        /// <returns></returns>
        public T CheckUserDataType <T>(string funcName, int argNum = -1, TypeValidationFlags flags = TypeValidationFlags.Default)
        {
            DynValue v        = this.CheckType(funcName, DataType.UserData, argNum, flags);
            bool     allowNil = ((int)(flags & TypeValidationFlags.AllowNil) != 0);

            if (v.IsNil())
            {
                return(default(T));
            }

            object o = v.UserData.Object;

            if (o != null && o is T)
            {
                return((T)o);
            }

            throw ScriptRuntimeException.BadArgumentUserData(argNum, funcName, typeof(T), o, allowNil);
        }
Пример #2
0
        /// <summary>
        /// Sets the value associated with the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Set(object key, DynValue value)
        {
            if (key == null)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            if (key is string)
            {
                Set((string)key, value);
            }
            else if (key is int)
            {
                Set((int)key, value);
            }
            else
            {
                Set(DynValue.FromObject(OwnerScript, key), value);
            }
        }
Пример #3
0
        /// <summary>
        /// Resumes the coroutine.
        /// </summary>
        /// <param name="context">The ScriptExecutionContext.</param>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        public DynValue Resume(ScriptExecutionContext context, params DynValue[] args)
        {
            this.CheckScriptOwnership(context);
            this.CheckScriptOwnership(args);

            if (Type == CoroutineType.Coroutine)
            {
                return(m_Processor.Coroutine_Resume(args));
            }
            else if (Type == CoroutineType.ClrCallback)
            {
                DynValue ret = m_ClrCallback.Invoke(context, args);
                MarkClrCallbackAsDead();
                return(ret);
            }
            else
            {
                throw ScriptRuntimeException.CannotResumeNotSuspended(CoroutineState.Dead);
            }
        }
Пример #4
0
        /// <summary>
        /// Sets the value associated to the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public void Set(DynValue key, DynValue value)
        {
            if (key.IsNilOrNan())
            {
                if (key.IsNil())
                {
                    throw ScriptRuntimeException.TableIndexIsNil();
                }
                else
                {
                    throw ScriptRuntimeException.TableIndexIsNaN();
                }
            }

            if (key.Type == DataType.String)
            {
                Set(key.String, value);
                return;
            }

            if (key.Type == DataType.Number)
            {
                int idx = GetIntegralKey(key.Number);

                if (idx > 0)
                {
                    Set(idx, value);
                    return;
                }
            }

            this.CheckScriptOwnership(key);
            this.CheckScriptOwnership(value);

            PerformTableSet(m_ValueMap, key, key, value, false, -1);
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScriptRuntimeException"/> class.
 /// </summary>
 /// <param name="ex">The ex.</param>
 public ScriptRuntimeException(ScriptRuntimeException ex)
     : base(ex, ex.DecoratedMessage)
 {
     this.DecoratedMessage     = Message;
     this.DoNotDecorateMessage = true;
 }