diff --git a/Assets/LuaFramework/ToLua/Core/LuaDLL.cs b/Assets/LuaFramework/ToLua/Core/LuaDLL.cs index e904379..aeba6d3 100644 --- a/Assets/LuaFramework/ToLua/Core/LuaDLL.cs +++ b/Assets/LuaFramework/ToLua/Core/LuaDLL.cs @@ -75,7 +75,7 @@ sealed class LuaIndexes public static class ToLuaFlags { public const int INDEX_ERROR = 1; //Index 失败提示error信息,false返回nil - public const int USE_INT64 = 2; //是否内部支持原生int64, 默认 false + public const int USE_INT64 = 2; //是否luavm内部支持原生int64(目前用的vm都不支持, 默认false) } [StructLayout(LayoutKind.Sequential)] @@ -182,7 +182,7 @@ public string short_src public class LuaDLL { - public static string version = "1.0.4.102"; + public static string version = "1.0.4.105"; public static int LUA_MULTRET = -1; public static string[] LuaTypeName = { "none", "nil", "boolean", "lightuserdata", "number", "string", "table", "function", "userdata", "thread" }; @@ -235,7 +235,7 @@ public static int lua_upvalueindex(int i) * state manipulation */ //[DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] - //public static extern IntPtr lua_newstate(LuaAlloc f, IntPtr ud); + //public static extern IntPtr lua_newstate(LuaAlloc f, IntPtr ud); //luajit64位不能用这个函数 [DllImport(LUADLL, CallingConvention = CallingConvention.Cdecl)] public static extern void lua_close(IntPtr luaState); @@ -1176,6 +1176,6 @@ public static void tolua_bindthis(IntPtr L, LuaCSFunction get, LuaCSFunction set } tolua_regthis(L, pGet, pSet); - } + } } } diff --git a/Assets/LuaFramework/ToLua/Core/LuaState.cs b/Assets/LuaFramework/ToLua/Core/LuaState.cs index 72b81bb..b585abb 100644 --- a/Assets/LuaFramework/ToLua/Core/LuaState.cs +++ b/Assets/LuaFramework/ToLua/Core/LuaState.cs @@ -99,7 +99,7 @@ public LuaState() LuaDLL.lua_settop(L, 0); if (!LuaFileUtils.Instance.beZip) - { + { AddSearchPath(LuaConst.luaDir); AddSearchPath(LuaConst.toluaDir); } @@ -455,6 +455,12 @@ public void Require(string fileName) public void AddSearchPath(string fullPath) { + if (!Directory.Exists(fullPath)) + { + string msg = string.Format("Lua config path not exists: {0}", fullPath); + throw new LuaException(msg, null, 1); + } + if (!Path.IsPathRooted(fullPath)) { throw new LuaException(fullPath + " is not a full path"); diff --git a/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs b/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs index c0472c5..f699869 100644 --- a/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs +++ b/Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs @@ -29,13 +29,15 @@ public class ObjectTranslator { private class DelayGC { - public DelayGC(int id, float time) + public DelayGC(int id, UnityEngine.Object obj, float time) { this.id = id; this.time = time; + this.obj = obj; } public int id; + public UnityEngine.Object obj = null; public float time; } @@ -94,10 +96,10 @@ public static ObjectTranslator Get(IntPtr L) #endif } - //完全移除一个对象,适合lua gc + //lua gc一个对象(lua 库不再引用,但不代表c#没使用) public void RemoveObject(int udata) - { - RemoveFromGCList(udata); + { + //只有lua gc才能移除 object o = objects.Remove(udata); if (o != null) @@ -109,7 +111,7 @@ public void RemoveObject(int udata) if (LogGC) { - Debugger.Log("remove object {0}, id {1}", o, udata); + Debugger.Log("gc object {0}, id {1}", o, udata); } } } @@ -119,10 +121,9 @@ public object GetObject(int udata) return objects.TryGetValue(udata); } - //删除,但不移除一个lua对象 + //删除,但不移除一个lua对象(移除id只能由gc完成) public void Destroy(int udata) - { - RemoveFromGCList(udata); + { object o = objects.Destroy(udata); if (o != null) @@ -139,9 +140,15 @@ public void Destroy(int udata) } } + //Unity Object 延迟删除 public void DelayDestroy(int id, float time) { - gcList.Add(new DelayGC(id, time)); + UnityEngine.Object obj = (UnityEngine.Object)GetObject(id); + + if (obj != null) + { + gcList.Add(new DelayGC(id, obj, time)); + } } public bool Getudata(object o, out int index) @@ -157,39 +164,36 @@ public void SetBack(int index, object o) objectsBackMap[o] = index; } - void RemoveFromGCList(int id) + bool RemoveFromGCList(int id) { int index = gcList.FindIndex((p) => { return p.id == id; }); if (index >= 0) { - gcList.RemoveAt(index); + gcList.RemoveAt(index); + return true; } + + return false; } - void DestroyUnityObject(int udata) + void DestroyUnityObject(int udata, UnityEngine.Object obj) { - object o = objects.Destroy(udata); - - if (o != null) - { - if (!TypeChecker.IsValueType(o.GetType())) - { - objectsBackMap.Remove(o); - } + object o = objects.TryGetValue(udata); - UnityEngine.Object obj = o as UnityEngine.Object; - - if (obj != null) - { - UnityEngine.Object.Destroy(obj); - } + if (object.ReferenceEquals(o, obj)) + { + objectsBackMap.Remove(o); + //一定不能Remove, 因为GC还可能再来一次 + objects.Destroy(udata); if (LogGC) { Debugger.Log("destroy object {0}, id {1}", o, udata); } } + + UnityEngine.Object.Destroy(obj); } public void Collect() @@ -207,7 +211,7 @@ public void Collect() if (time <= 0) { - DestroyUnityObject(gcList[i].id); + DestroyUnityObject(gcList[i].id, gcList[i].obj); gcList.RemoveAt(i); } else diff --git a/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs b/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs index f89b4ed..0966e95 100644 --- a/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs +++ b/Assets/LuaFramework/ToLua/Examples/02_ScriptsFromFile/ScriptsFromFile.cs @@ -19,9 +19,10 @@ void Start () #endif lua = new LuaState(); lua.Start(); + //移动了ToLua路径,自己手动修复吧,只是例子就不做配置了 string fullPath = Application.dataPath + "/ToLua/Examples/02_ScriptsFromFile"; - lua.AddSearchPath(fullPath); - } + lua.AddSearchPath(fullPath); + } void Log(string msg, string stackTrace, LogType type) { diff --git a/Assets/LuaFramework/ToLua/Lua/math/Bounds.lua b/Assets/LuaFramework/ToLua/Lua/math/Bounds.lua index 534c8c1..62051a1 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Bounds.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Bounds.lua @@ -31,6 +31,9 @@ Bounds.__index = function(t,k) return var end +Bounds.__call = function(t, center, size) + return Bounds.New(center, size) +end function Bounds.New(center, size) local bd = {center = zero, extents = zero} diff --git a/Assets/LuaFramework/ToLua/Lua/math/Color.lua b/Assets/LuaFramework/ToLua/Lua/math/Color.lua index cb2f8a4..ac0020f 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Color.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Color.lua @@ -22,6 +22,10 @@ Color.__index = function(t,k) return var end +Color.__call = function(t, r, g, b, a) + return Color.New(r, g, b, a) +end + function Color.New(r, g, b, a) local v = {r = r or 0, g = g or 0, b = b or 0, a = a or 1} setmetatable(v, Color) @@ -43,16 +47,19 @@ function Color:Equals(other) return self.r == other.r and self.g == other.g and self.b == other.b and self.a == other.a end -function Color:Lerp(a, b, t) +function Color.Lerp(a, b, t) t = Mathf.Clamp01(t) return Color.New(a.r + t * (b.r - a.r), a.g + t * (b.g - a.g), a.b + t * (b.b - a.b), a.a + t * (b.a - a.a)) end +function Color.LerpUnclamped(a, b, t) + return Color.New(a.r + t * (b.r - a.r), a.g + t * (b.g - a.g), a.b + t * (b.b - a.b), a.a + t * (b.a - a.a)) +end + function Color.GrayScale(a) return 0.299 * a.r + 0.587 * a.g + 0.114 * a.b end - Color.__tostring = function(self) return string.format("RGBA(%f,%f,%f,%f)", self.r, self.g, self.b, self.a) end @@ -92,6 +99,18 @@ get.magenta = function() return Color.New(1,0,1,1) end get.gray = function() return Color.New(0.5,0.5,0.5,1) end get.clear = function() return Color.New(0,0,0,0) end +get.gamma = function(c) + return Color.New(Mathf.LinearToGammaSpace(c.r), Mathf.LinearToGammaSpace(c.g), Mathf.LinearToGammaSpace(c.b), c.a) +end + +get.linear = function(c) + return Color.New(Mathf.GammaToLinearSpace(c.r), Mathf.GammaToLinearSpace(c.g), Mathf.GammaToLinearSpace(c.b), c.a) +end + +get.maxColorComponent = function(c) + return Mathf.Max(Mathf.Max(c.r, c.g), c.b) +end + get.grayscale = Color.GrayScale setmetatable(Color, Color) diff --git a/Assets/LuaFramework/ToLua/Lua/math/Quaternion.lua b/Assets/LuaFramework/ToLua/Lua/math/Quaternion.lua index 26f1acc..72e28ee 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Quaternion.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Quaternion.lua @@ -55,6 +55,10 @@ Quaternion.__newindex = function(t, name, k) end end +Quaternion.__call = function(t, x, y, z, w) + return Quaternion.New(x, y, z, w) +end + function Quaternion.New(x, y, z, w) local quat = {x = x or 0, y = y or 0, z = z or 0, w = w or 0} setmetatable(quat, Quaternion) @@ -471,7 +475,7 @@ function Quaternion:ToAngleAxis() end local div = 1 / sqrt(1 - sqrt(self.w)) - return angle * 57.29578, Vector3.New(q.x * div, q.y * div, q.z * div) + return angle * 57.29578, Vector3.New(self.x * div, self.y * div, self.z * div) end local pi = Mathf.PI diff --git a/Assets/LuaFramework/ToLua/Lua/math/Ray.lua b/Assets/LuaFramework/ToLua/Lua/math/Ray.lua index 5ae66be..b0af8ba 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Ray.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Ray.lua @@ -21,6 +21,10 @@ Ray.__index = function(t,k) return var end +Ray.__call = function(t, direction, origin) + return Ray.New(direction, origin) +end + function Ray.New(direction, origin) local ray = {} ray.direction = direction:Normalize() diff --git a/Assets/LuaFramework/ToLua/Lua/math/Touch.lua b/Assets/LuaFramework/ToLua/Lua/math/Touch.lua index 61e5e0c..46e746b 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Touch.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Touch.lua @@ -46,6 +46,7 @@ Touch.__index = function(t,k) return var end +--c# 创建 function Touch.New(fingerId, position, rawPosition, deltaPostion, deltaTime, tapCount, phase) local touch = {fingerId = fingerId or 0, position = position or zero, rawPosition = rawPosition or zero, deltaPostion = deltaPostion or zero, deltaTime = deltaTime or 0, tapCount = tapCount or 0, phase = phase or 0} setmetatable(touch, Touch) diff --git a/Assets/LuaFramework/ToLua/Lua/math/Vector2.lua b/Assets/LuaFramework/ToLua/Lua/math/Vector2.lua index 98b1a53..a505ee5 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Vector2.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Vector2.lua @@ -29,6 +29,10 @@ Vector2.__index = function(t,k) return var end +Vector2.__call = function(t, x, y) + return Vector2.New(x, y) +end + function Vector2.New(x, y) local v = {x = x or 0, y = y or 0} setmetatable(v, Vector2) diff --git a/Assets/LuaFramework/ToLua/Lua/math/Vector4.lua b/Assets/LuaFramework/ToLua/Lua/math/Vector4.lua index 5e31a2f..107e9bb 100644 --- a/Assets/LuaFramework/ToLua/Lua/math/Vector4.lua +++ b/Assets/LuaFramework/ToLua/Lua/math/Vector4.lua @@ -31,6 +31,10 @@ Vector4.__index = function(t,k) return var end +Vector4.__call = function(t, x, y, z, w) + return Vector4.New(x, y, z, w) +end + function Vector4.New(x, y, z, w) local v = {x = 0, y = 0, z = 0, w = 0} setmetatable(v, Vector4) diff --git a/ReadMe.txt b/ReadMe.txt index 19ad4bf..d3dbf43 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -16,6 +16,7 @@ tolua#地址: https://github.com/topameng/tolua //-------------2016-03-25------------- (1)清理meta文件等问题。 +(2)更新tolua#到1.0.4.109版 //-------------2016-03-22------------- (1)更新tolua#到1.0.4.102版