using UnityEngine;
using System.Collections.Generic;
using LuaInterface;
public sealed class TestAccount
{
public int id;
public string name;
public int sex;
public TestAccount(int id, string name, int sex)
{
this.id = id;
this.name = name;
this.sex = sex;
}
}
public class UseDictionary : MonoBehaviour
{
Dictionary<int, TestAccount> map = new Dictionary<int, TestAccount>();
string script =
@"
function TestDict(map)
local iter = map:GetEnumerator() --获得迭代器
while iter:MoveNext() do --用迭代器遍历
local v = iter.Current.Value --用迭代器获得值
print('id: '..v.id ..' name: '..v.name..' sex: '..v.sex)
end
local flag, account = map:TryGetValue(1, nil) --获得account
if flag then
print('TryGetValue result ok: '..account.name) --