Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb9e009

Browse files
committed
不小心在master 分支上改动了 :(
1 parent53284fd commitdb9e009

File tree

5 files changed

+61
-45
lines changed

5 files changed

+61
-45
lines changed

‎Assets/Plugins/Slua_Managed/LuaDLL.cs‎

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ public static int lua_yield(IntPtr luaState,int nrets) {
298298

299299
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
300300
publicstaticexternintlua_resume(IntPtrL,IntPtrfrom,intnarg);
301-
publicstaticintlua_resume(IntPtrL,intnarg)
302-
{
303-
returnlua_resume(L,IntPtr.Zero,narg);
304-
}
301+
publicstaticintlua_resume(IntPtrL,intnarg)
302+
{
303+
returnlua_resume(L,IntPtr.Zero,narg);
304+
}
305305

306306
publicstaticvoidlua_replace(IntPtrluaState,intindex){
307307
lua_copy(luaState,-1,(index));
@@ -585,19 +585,19 @@ public static string lua_tostring(IntPtr luaState, int index)
585585
intstrlen;
586586

587587
IntPtrstr=luaS_tolstring32(luaState,index,outstrlen);// fix il2cpp 64 bit
588-
strings=null;
589-
if(strlen>0&&str!=IntPtr.Zero)
588+
strings=null;
589+
if(strlen>0&&str!=IntPtr.Zero)
590590
{
591-
s=Marshal.PtrToStringAnsi(str);
592-
// fallback method
593-
if(s==null)
594-
{
595-
byte[]b=newbyte[strlen];
596-
Marshal.Copy(str,b,0,strlen);
597-
s=System.Text.Encoding.Default.GetString(b);
598-
}
591+
s=Marshal.PtrToStringAnsi(str);
592+
// fallback method
593+
if(s==null)
594+
{
595+
byte[]b=newbyte[strlen];
596+
Marshal.Copy(str,b,0,strlen);
597+
s=System.Text.Encoding.Default.GetString(b);
598+
}
599599
}
600-
return(s==null)?string.Empty:s;
600+
return(s==null)?string.Empty:s;
601601
}
602602

603603
publicstaticbyte[]lua_tobytes(IntPtrluaState,intindex)
@@ -692,12 +692,13 @@ public static double luaL_checknumber(IntPtr luaState, int stackPos)
692692

693693
/// <summary>
694694
/// //check the data in the stack postion index is a userData, or it's most __base is a userData.
695-
/// if is, return the userdata(which is a int index) or -1 if it's not
696-
/// ref luaS_pushobject
695+
/// TODO: where is the __base got set??
696+
/// if is, return the userdata(which is a int index) or -1 if it's not
697+
/// ref luaS_pushobject
697698
/// </summary>
698699
/// <param name="luaState"></param>
699-
/// <param name="obj">the index in stack</param>
700-
/// <returns>the index of cache list</returns>
700+
/// <param name="obj">the index in stack</param>
701+
/// <returns>the index of cache list</returns>
701702
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]
702703
publicstaticexternintluaS_rawnetobj(IntPtrluaState,intobj);
703704

@@ -725,7 +726,7 @@ public static int lua_upvalueindex(int i)
725726
publicstaticvoidlua_pushcclosure(IntPtrl,LuaCSFunctionf,intnup)
726727
{
727728
#ifSLUA_STANDALONE
728-
// Add all LuaCSFunction, or they will be GC collected! (problem at windows, .net framework 4.5, `CallbackOnCollectedDelegated` exception)
729+
// Add all LuaCSFunction, or they will be GC collected! (problem at windows, .net framework 4.5, `CallbackOnCollectedDelegated` exception)
729730
GCHandle.Alloc(f);
730731
#endif
731732
IntPtrfn=Marshal.GetFunctionPointerForDelegate(f);
@@ -766,9 +767,9 @@ public static void lua_pushcclosure(IntPtr l, LuaCSFunction f, int nup)
766767
publicstaticexternvoidluaS_setDataVec(IntPtrl,intp,floatx,floaty,floatz,floatw);
767768

768769
/// <summary>
769-
/// NOTE: Only check lua value type
770+
/// NOTE: Only check lua value type
770771
/// 是一个table,并且有metatable,metatable[__typename] == t 如果t != null
771-
/// NOTE: where did the metatable got set ? in LuaValueType
772+
/// NOTE: where did the metatable got set ? in LuaValueType
772773
/// 返回1 表示true, 0表示FALSE
773774
/// </summary>
774775
/// <param name="l"></param>
@@ -779,12 +780,12 @@ public static void lua_pushcclosure(IntPtr l, LuaCSFunction f, int nup)
779780
publicstaticexternintluaS_checkluatype(IntPtrl,intp,stringt);
780781

781782
/// <summary>
782-
/// NOTE: the table to be set as metatable for userdata is instance table
783-
/// TODO: why does it set the metatable of the userdata(which is the only index value store in it)?
783+
/// NOTE: the table to be set as metatable for userdata is instance table
784+
/// TODO: why does it set the metatable of the userdata(which is the only index value store in it)?
784785
/// create an userdata to store index(int), push it on stack(if gco is true, push the userdata to register cref at index index),
785786
/// set the metatable of the userdata to
786-
/// the table associated to name t(luaL_getmetatable()), which is AQName
787-
/// left the userdata on the stack
787+
/// the table associated to name t(luaL_getmetatable()), which is AQName
788+
/// left the userdata on the stack
788789
/// </summary>
789790
/// <param name="l"></param>
790791
/// <param name="index">the index in the cache list</param>
@@ -807,12 +808,12 @@ public static void lua_pushcclosure(IntPtr l, LuaCSFunction f, int nup)
807808

808809

809810
/// <summary>
810-
/// 如果有__base,则向上查找, 然后判断metatable 的 __typename是否和t相同
811-
/// TODO: __base 在哪里设置的 ?
812-
/// NOTE: __typename is set in the instance table when create the lua table which represent the c# class
813-
/// </summary>
811+
/// 如果有__base,则向上查找, 然后判断metatable 的 __typename是否和t相同
812+
/// TODO: __base 在哪里设置的 ?
813+
/// NOTE: __typename is set in the instance table when create the lua table which represent the c# class
814+
/// </summary>
814815
/// <param name="l"></param>
815-
/// <param name="index">the luatype at index is a LuaTable</param>
816+
/// <param name="index">the luatype at index is a LuaTable</param>
816817
/// <param name="t"></param>
817818
/// <returns></returns>
818819
[DllImport(LUADLL,CallingConvention=CallingConvention.Cdecl)]

‎Assets/Plugins/Slua_Managed/LuaObject.cs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ static void completeTypeMeta(IntPtr l, LuaCSFunction con, Type self)
727727
/// <param name="self"></param>
728728
privatestaticvoidcompleteInstanceMeta(IntPtrl,Typeself)
729729
{
730-
//TODO: 什么时候用到的呢?
730+
//NOTE: 什么时候用到的呢?
731+
//用于判断是否是whether is a exported c# class ref
731732
LuaDLL.lua_pushstring(l,"__typename");
732733
LuaDLL.lua_pushstring(l,self.Name);
733734
LuaDLL.lua_rawset(l,-3);
@@ -875,10 +876,18 @@ protected static void addMember(IntPtr l, int v, string name)
875876
LuaDLL.lua_setfield(l,-2,name);
876877
}
877878

879+
880+
/// <summary>
881+
/// When an userdata is GC, if it's metatable has __gc method, the __gc method is called,
882+
/// pass the userdata as argument
883+
/// </summary>
884+
/// <param name="l"></param>
885+
/// <returns></returns>
878886
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
879887
staticpublicintluaGC(IntPtrl)
880888
{
881-
//TODO: why the index is 1 ?
889+
//NOTE: why the index is 1 ?
890+
//there is only one argument, the userdata itself, which is created by luaS_pushobject()
882891
intindex=LuaDLL.luaS_rawnetobj(l,1);
883892
if(index>0)
884893
{
@@ -1423,8 +1432,7 @@ static public object checkVar(IntPtr l, int p, Type t)
14231432
}
14241433

14251434
/// <summary>
1426-
/// 根据p在 lua 中的类型,返回相应的c# 数据类型
1427-
/// TODO: 感觉像是pushVar 的相反函数
1435+
/// 根据p在 lua 中的类型,返回相应的c# 数据类型(table/thread/function) or real C# class obj
14281436
/// </summary>
14291437
/// <param name="l"></param>
14301438
/// <param name="p"></param>
@@ -1530,8 +1538,9 @@ public static void pushValue(IntPtr l, Array a)
15301538
/// if o is value type, push it directly, if o is a ref in register, push ref
15311539
/// otherwise, push o and create userdata which stores the index in the cache list
15321540
/// NOTE: how to get the vaue? use checkVar
1533-
/// TODO: what is the difference between pushObject(push to cache list) and push(not push to cache list) ?
1534-
/// </summary>
1541+
/// NOTE: what is the difference between pushObject(push to cache list) and push(not push to cache list) ?
1542+
/// if the object is GC collectable, we need to cache it to prevent be GC collected, and then push it onto stack
1543+
/// </summary>
15351544
/// <param name="l"></param>
15361545
/// <param name="o"></param>
15371546
publicstaticvoidpushVar(IntPtrl,objecto)

‎Assets/Plugins/Slua_Managed/LuaState.cs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ function vars(f)
717717
while true do
718718
local name, value = debug.getlocal(f, i)
719719
if not name then break end
720-
if string.sub(name, 1, 1) ~= '(' then
721-
dump = dump .. "" "" .. name .. ""="" .. tostring(value) .. ""\n""
720+
if string.sub(name, 1, 1) ~= '(' then
721+
dump = dump .. "" "" .. name .. ""="" .. tostring(value) .. ""\n""
722722
end
723723
i = i + 1
724724
end
@@ -966,7 +966,7 @@ internal static int print(IntPtr L)
966966
LuaDLL.lua_pop(L,1);
967967
}
968968
LuaDLL.lua_settop(L,n);
969-
969+
970970
LuaDLL.lua_getglobal(L,"debug");
971971
LuaDLL.lua_getfield(L,-1,"traceback");
972972
LuaDLL.lua_call(L,0,1);
@@ -982,7 +982,7 @@ internal static int print(IntPtr L)
982982

983983
return0;
984984
}
985-
985+
986986
// copy from print()
987987
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
988988
internalstaticintprinterror(IntPtrL)
@@ -1007,7 +1007,7 @@ internal static int printerror(IntPtr L)
10071007
LuaDLL.lua_pop(L,1);
10081008
}
10091009
LuaDLL.lua_settop(L,n);
1010-
1010+
10111011
LuaDLL.lua_getglobal(L,"debug");
10121012
LuaDLL.lua_getfield(L,-1,"traceback");
10131013
LuaDLL.lua_call(L,0,1);
@@ -1533,6 +1533,7 @@ void setupPushVar()
15331533
LuaDLL.lua_pushboolean(L,(bool)o);
15341534
};
15351535

1536+
//NOTE: 因为这几个类本身是有ref 存储在 register 中的,所以push 的时候不用cache
15361537
typePushMap[typeof(LuaTable)]=
15371538
typePushMap[typeof(LuaFunction)]=
15381539
typePushMap[typeof(LuaThread)]=

‎Assets/Plugins/Slua_Managed/ObjectCache.cs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ public int size()
256256
returnobjMap.Count;
257257
}
258258

259+
/// <summary>
260+
/// delete from cache
261+
/// </summary>
262+
/// <param name="index"></param>
259263
internalvoidgc(intindex)
260264
{
261265
objecto;
@@ -326,7 +330,7 @@ internal void push(IntPtr l, object o)
326330
push(l,o,true);
327331
}
328332

329-
333+
330334

331335
/// <summary>
332336
/// analogy with function push(IntPtr l, object o, bool checkReflect)
@@ -377,7 +381,7 @@ internal int allocID(IntPtr l,object o) {
377381

378382
internalvoidpush(IntPtrl,objecto,boolcheckReflect)
379383
{
380-
384+
381385
intindex=allocID(l,o);
382386
if(index<0)
383387
return;

‎build/slua.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ LUA_API int luaS_pushobject(lua_State *l, int index, const char* t, int gco, int
473473

474474
//step 2
475475
//set the metatable of userdata
476-
//TODO: why do this?
476+
//NOTE: why do this?
477+
//set instance table as the metatable, so it can call methods
477478
lua_setmetatable(l,-2);
478479
returnis_reflect;
479480
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp