IronLua.Runtime.LuaTable.SetValue C# (CSharp) Method

SetValue() private method

private SetValue ( object key, object value ) : object
key object
value object
return object
        internal object SetValue(object key, object value)
        {
            if (value == null)
            {
                Remove(key);
                return null;
            }

            var hashCode = key.GetHashCode() & Int32.MaxValue;
            var modHashCode = hashCode % buckets.Length;

            for (var i = buckets[modHashCode]; i >= 0; i = entries[i].Next)
            {
                if (entries[i].HashCode == hashCode && entries[i].Key.Equals(key))
                {
                    entries[i].Value = value;
                    return value;
                }
            }

            int free;
            if (freeCount > 0)
            {
                free = freeList;
                freeList = entries[free].Next;
                freeCount--;
            }
            else
            {
                if (count == entries.Length)
                {
                    Resize();
                    modHashCode = hashCode % buckets.Length;
                }
                free = count;
                count++;
            }

            entries[free].HashCode = hashCode;
            entries[free].Next = buckets[modHashCode];
            entries[free].Key = key;
            entries[free].Value = value;
            buckets[modHashCode] = free;
            return value;
        }

Usage Example

示例#1
0
 public override void Setup(LuaTable table)
 {
     table.SetValue("assert", (Func<bool, object, object[], Varargs>)Assert);
     table.SetValue("collectgarbage", (Action<string, string>)CollectGarbage);
     table.SetValue("dofile", (Func<string, object>)DoFile);
     table.SetValue("error", (Action<string, object>)Error);
     table.SetValue("_G", table);
     table.SetValue("getfenv", (Func<object, object>)GetFEnv);
     table.SetValue("getmetatable", (Func<object, object>)GetMetatable);
     table.SetValue("ipairs", (Func<LuaTable, Varargs>)IPairs);
     table.SetValue("load", (Func<Delegate, string, Varargs>)Load);
     table.SetValue("loadfile", (Func<string, Varargs>)LoadFile);
     table.SetValue("loadstring", (Func<string, string, Varargs>)LoadString);
     table.SetValue("next", (Func<LuaTable, object, Varargs>)Next);
     table.SetValue("pairs", (Func<LuaTable, Varargs>)Pairs);
     table.SetValue("pcall", (Func<Delegate, object[], Varargs>)PCall);
     table.SetValue("print", (Action<object[]>)Print);
     table.SetValue("rawequal", (Func<object, object, bool>)RawEqual);
     table.SetValue("rawget", (Func<LuaTable, object, object>)RawGet);
     table.SetValue("rawset", (Func<LuaTable, object, object, object>)RawSet);
     table.SetValue("select", (Func<object, object[], Varargs>)Select);
     table.SetValue("setfenv", (Func<object, LuaTable, object>)SetFEnv);
     table.SetValue("setmetatable", (Func<LuaTable, LuaTable, LuaTable>)SetMetatable);
     table.SetValue("tonumber", (Func<string, object, object>)ToNumber);
     table.SetValue("tostring", (Func<object, object>)ToString);
     table.SetValue("type", (Func<object, string>)Type);
     table.SetValue("unpack", (Func<LuaTable, object, object, Varargs>)Unpack);
     table.SetValue("_VERSION", Constant.LUA_VERSION);
     table.SetValue("xpcall", (Func<Delegate, Delegate, Varargs>)XPCall);
 }
All Usage Examples Of IronLua.Runtime.LuaTable::SetValue