Skip to content

Commit

Permalink
更新tolua#到1.0.7.343版
Browse files Browse the repository at this point in the history
  • Loading branch information
jarjin2000 committed Jul 17, 2017
1 parent 5f973e9 commit 0e43041
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 439 deletions.
2 changes: 1 addition & 1 deletion Assets/LuaFramework/ToLua/BaseType/System_StringWrap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int Equals(IntPtr L)
System.String obj = (System.String)ToLua.CheckObject(L, 1, typeof(System.String));
string arg0 = ToLua.CheckString(L, 2);
System.StringComparison arg1 = (System.StringComparison)ToLua.CheckObject(L, 3, typeof(System.StringComparison));
bool o = obj != null ? obj.Equals(arg0, arg1) : arg0 == null;
bool o = obj.Equals(arg0, arg1);
LuaDLL.lua_pushboolean(L, o);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/LuaFramework/ToLua/Core/LuaDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public string short_src

public class LuaDLL
{
public static string version = "1.0.7.335";
public static string version = "1.0.7.343";
public static int LUA_MULTRET = -1;
public static string[] LuaTypeName = { "none", "nil", "boolean", "lightuserdata", "number", "string", "table", "function", "userdata", "thread" };

Expand Down
1 change: 1 addition & 0 deletions Assets/LuaFramework/ToLua/Core/LuaState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,7 @@ public bool BeginCall(string name, int top, bool beLogMiss)
}
else
{
LuaDLL.lua_settop(L, top);
if (beLogMiss)
{
Debugger.Log("Lua function {0} not exists", name);
Expand Down
148 changes: 143 additions & 5 deletions Assets/LuaFramework/ToLua/Core/LuaTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ public void RawSetIndex<T>(int index, T value)
}
}

public T RawGet<T>(string key)
public V RawGet<K, V>(K key)
{
int top = luaState.LuaGetTop();

try
{
luaState.Push(this);
luaState.Push(key);
luaState.PushGeneric(key);
luaState.LuaRawGet(top + 1);
T ret = luaState.CheckValue<T>(top + 2);
V ret = luaState.CheckValue<V>(top + 2);
luaState.LuaSetTop(top);
return ret;
}
Expand All @@ -183,14 +183,14 @@ public T RawGet<T>(string key)
}
}

public void RawSet<T>(string key, T arg)
public void RawSet<K, V>(K key, V arg)
{
int top = luaState.LuaGetTop();

try
{
luaState.Push(this);
luaState.Push(key);
luaState.PushGeneric(key);
luaState.PushGeneric(arg);
luaState.LuaRawSet(top + 1);
luaState.LuaSetTop(top);
Expand Down Expand Up @@ -738,6 +738,11 @@ public LuaDictTable ToDictTable()
return new LuaDictTable(this);
}

public LuaDictTable<K, V> ToDictTable<K, V>()
{
return new LuaDictTable<K, V>(this);
}

public LuaTable GetMetaTable()
{
int oldTop = luaState.LuaGetTop();
Expand Down Expand Up @@ -993,4 +998,137 @@ public void Dispose()
}
}
}

public struct LuaDictEntry<K, V>
{
public LuaDictEntry(K key, V value)
{
Key = key;
Value = value;
}

public K Key { get; set; }
public V Value { get; set; }
}

public class LuaDictTable<K, V> : IDisposable, IEnumerable<LuaDictEntry<K, V>>
{
LuaTable table;
LuaState state;

public LuaDictTable(LuaTable table)
{
table.AddRef();
this.table = table;
this.state = table.GetLuaState();
}

public void Dispose()
{
if (table != null)
{
table.Dispose();
table = null;
}
}

public V this[K key]
{
get
{
return table.RawGet<K, V>(key);
}

set
{
table.RawSet(key, value);
}
}

public Dictionary<K, V> ToDictionary()
{
Dictionary<K, V> dict = new Dictionary<K, V>();
var iter = GetEnumerator();

while (iter.MoveNext())
{
dict.Add(iter.Current.Key, iter.Current.Value);
}

iter.Dispose();
return dict;
}

public IEnumerator<LuaDictEntry<K, V>> GetEnumerator()
{
return new Enumerator(this);
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

class Enumerator : IEnumerator<LuaDictEntry<K, V>>
{
LuaState state;
LuaDictEntry<K, V> current = new LuaDictEntry<K, V>();
int top = -1;

public Enumerator(LuaDictTable<K, V> list)
{
state = list.state;
top = state.LuaGetTop();
state.Push(list.table);
state.LuaPushNil();
}

public LuaDictEntry<K, V> Current
{
get
{
return current;
}
}

object IEnumerator.Current
{
get
{
return Current;
}
}

public bool MoveNext()
{
if (state.LuaNext(-2))
{
current = new LuaDictEntry<K, V>();
current.Key = state.CheckValue<K>(-2);
current.Value = state.CheckValue<V>(-1);
state.LuaPop(1);
return true;
}
else
{
current = new LuaDictEntry<K, V>();
return false;
}
}

public void Reset()
{
current = new LuaDictEntry<K, V>();
}

public void Dispose()
{
if (state != null)
{
state.LuaSetTop(top);
state = null;
}
}
}
}
}
2 changes: 1 addition & 1 deletion Assets/LuaFramework/ToLua/Core/ToLua.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,7 @@ public static void Push(IntPtr L, object obj)
}
else if (t == typeof(LayerMask))
{
Push(L, (LayerMask)obj);
PushLayerMask(L, (LayerMask)obj);
}
else
{
Expand Down
Loading

0 comments on commit 0e43041

Please sign in to comment.