Skip to content

Commit

Permalink
更新tolua#到1.0.4.109版
Browse files Browse the repository at this point in the history
  • Loading branch information
jarjin committed Mar 25, 2016
1 parent e8e9eb4 commit 10876c4
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 37 deletions.
8 changes: 4 additions & 4 deletions Assets/LuaFramework/ToLua/Core/LuaDLL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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" };

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1176,6 +1176,6 @@ public static void tolua_bindthis(IntPtr L, LuaCSFunction get, LuaCSFunction set
}

tolua_regthis(L, pGet, pSet);
}
}
}
}
8 changes: 7 additions & 1 deletion Assets/LuaFramework/ToLua/Core/LuaState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public LuaState()
LuaDLL.lua_settop(L, 0);

if (!LuaFileUtils.Instance.beZip)
{
{
AddSearchPath(LuaConst.luaDir);
AddSearchPath(LuaConst.toluaDir);
}
Expand Down Expand Up @@ -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");
Expand Down
58 changes: 31 additions & 27 deletions Assets/LuaFramework/ToLua/Core/ObjectTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}
}
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions Assets/LuaFramework/ToLua/Lua/math/Bounds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
23 changes: 21 additions & 2 deletions Assets/LuaFramework/ToLua/Lua/math/Color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion Assets/LuaFramework/ToLua/Lua/math/Quaternion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Assets/LuaFramework/ToLua/Lua/math/Ray.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Assets/LuaFramework/ToLua/Lua/math/Touch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Assets/LuaFramework/ToLua/Lua/math/Vector2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Assets/LuaFramework/ToLua/Lua/math/Vector4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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版
Expand Down

0 comments on commit 10876c4

Please sign in to comment.