/// <summary> /// Determines whether the given key exists. /// </summary> /// <param name="key">The key.</param> /// <returns><c>true</c> if <paramref name="key"/> exists, <c>false</c> otherwise.</returns> public bool ContainsKey(object key) { if (key == null) { return(false); } PushOnto(Lua.MainState); Lua.PushObject(key); var type = LuaApi.GetTable(Lua.MainState, -2); var result = type != LuaType.Nil; LuaApi.Pop(Lua.MainState, 2); return(result); }
/// <summary> /// Gets or sets the value corresponding to the given key. /// </summary> /// <param name="key">The key.</param> /// <returns>The value.</returns> /// <exception cref="ArgumentException"> /// <paramref name="value"/> is a <see cref="LuaReference"/> which is tied to a different <see cref="Lua"/> environment. /// </exception> /// <exception cref="ArgumentNullException"><paramref name="key"/> is <c>null</c> and is set.</exception> public object this[object key] { get { PushOnto(Lua.MainState); Lua.PushObject(key); var type = LuaApi.GetTable(Lua.MainState, -2); var result = Lua.ToObject(-1, type); LuaApi.Pop(Lua.MainState, 2); return(result); } set { if (key == null) { throw new ArgumentNullException(nameof(key)); } PushOnto(Lua.MainState); Lua.PushObject(key); Lua.PushObject(value); LuaApi.SetTable(Lua.MainState, -3); LuaApi.Pop(Lua.MainState, 1); } }