/// <summary> /// Clears all of the key-value pairs. /// </summary> public void Clear() { PushOnto(Lua.MainState); LuaApi.PushNil(Lua.MainState); while (LuaApi.Next(Lua.MainState, -2)) { LuaApi.Pop(Lua.MainState, 1); LuaApi.PushValue(Lua.MainState, -1); LuaApi.PushNil(Lua.MainState); LuaApi.SetTable(Lua.MainState, -4); } LuaApi.Pop(Lua.MainState, 1); }
/// <summary> /// Gets an enumerator iterating through the key-value pairs. /// </summary> /// <returns>An enumerator iterating through the key-value pairs.</returns> public IEnumerator <KeyValuePair <object, object> > GetEnumerator() { object currentKey = null; while (true) { PushOnto(Lua.MainState); Lua.PushObject(currentKey); if (!LuaApi.Next(Lua.MainState, -2)) { LuaApi.Pop(Lua.MainState, 1); yield break; } currentKey = Lua.ToObject(-2); var value = Lua.ToObject(-1); LuaApi.Pop(Lua.MainState, 3); yield return(new KeyValuePair <object, object>(currentKey, value)); } }