Beispiel #1
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(string key, DynValue value)
        {
            if (key == null)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            this.CheckScriptOwnership(value);
            PerformTableSet(m_StringMap, key, DynValue.NewString(key), value, false, -1);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the value associated with the specified keys.
        /// Multiple keys can be used to access subtables.
        /// </summary>
        /// <param name="key">The keys.</param>
        /// <param name="value">The value.</param>
        public void Set(object[] keys, DynValue value)
        {
            if (keys == null || keys.Length <= 0)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            object key;

            ResolveMultipleKeys(keys, out key).Set(key, value);
        }
Beispiel #3
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 <T>(T key, DynValue value)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            if (key == null)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            Set(DynValue.FromObject(OwnerScript, key), value);
        }
Beispiel #4
0
        /// <summary>
        /// Sets the value associated with the specified keys.
        /// Multiple keys can be used to access subtables.
        /// </summary>
        /// <param name="key">The keys.</param>
        /// <param name="value">The value.</param>
        public void Set(object[] keys, DynValue value)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            if (keys == null || keys.Length <= 0)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            object key;

            ResolveMultipleKeys(keys, out key).Set(key, value);
        }
Beispiel #5
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 (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            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);

            if (m_ValueMap == null)
            {
                m_ValueMap = new LinkedListIndex <DynValue, TablePair>(ValuesList);
            }
            PerformTableSet(m_ValueMap, key, key, value, false, -1);
        }
Beispiel #6
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(string key, DynValue value)
        {
            if (!_isAlive)
            {
                throw new InvalidOperationException(string.Format("Attempting to Set on dead Table"));
            }
            if (key == null)
            {
                throw ScriptRuntimeException.TableIndexIsNil();
            }

            this.CheckScriptOwnership(value);

            if (m_StringMap == null)
            {
                m_StringMap = new LinkedListIndex <string, TablePair>(ValuesList);
            }
            PerformTableSet(m_StringMap, key, DynValue.NewString(key), value, false, -1);
        }
Beispiel #7
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);
            }
        }
Beispiel #8
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 >= (OwnerScript.Options.ZeroIndexTables ? 0 : 1))
                {
                    Set(idx, value);
                    return;
                }
            }

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

            PerformTableSet(m_ValueMap, key, key, value, false, -1);
        }
Beispiel #9
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;
                }
            }

            CheckValueOwner(key);
            CheckValueOwner(value);

            PerformTableSet(m_ValueMap, key, key, value, false);
        }