@@ -56,6 +56,11 @@ public class LuaContext : LuaBaseObject
5656 /// </summary>
5757 private Dictionary < string , LuaMethodHandler > _methodHandlers ;
5858
59+ /// <summary>
60+ /// 导出类型管理器
61+ /// </summary>
62+ private LuaExportsTypeManager _exportsTypeManager ;
63+
5964 /// <summary>
6065 /// 方法处理委托
6166 /// </summary>
@@ -157,12 +162,25 @@ internal static LuaContext getContext(int nativeId)
157162 return null ;
158163 }
159164
165+ /// <summary>
166+ /// 获取导出类型管理器
167+ /// </summary>
168+ /// <value>导出类型管理器.</value>
169+ internal LuaExportsTypeManager exportsTypemanager
170+ {
171+ get
172+ {
173+ return _exportsTypeManager ;
174+ }
175+ }
176+
160177 /// <summary>
161178 /// 初始化上下文
162179 /// </summary>
163180 public LuaContext ( )
164181 {
165182 _methodHandlers = new Dictionary < string , LuaMethodHandler > ( ) ;
183+ _exportsTypeManager = new LuaExportsTypeManager ( this ) ;
166184 _nativeObjectId = NativeUtils . createLuaContext ( ) ;
167185 _contexts . Add ( _nativeObjectId , new WeakReference ( this ) ) ;
168186
@@ -190,7 +208,7 @@ public LuaContext()
190208 //注册类型
191209 foreach ( Type t in _regTypes )
192210 {
193- LuaExportsTypeManager . defaultManager . exportType ( t , this ) ;
211+ _exportsTypeManager . exportType ( t , this ) ;
194212 }
195213 }
196214
@@ -233,7 +251,7 @@ public void setGlobal(string name, LuaValue value)
233251 IntPtr valuePtr = IntPtr . Zero ;
234252 if ( value != null )
235253 {
236- LuaObjectEncoder encoder = new LuaObjectEncoder ( ) ;
254+ LuaObjectEncoder encoder = new LuaObjectEncoder ( this ) ;
237255 encoder . writeObject ( value ) ;
238256
239257 byte [ ] bytes = encoder . bytes ;
@@ -261,7 +279,7 @@ public LuaValue getGlobal(string name)
261279
262280 if ( valuePtr != IntPtr . Zero && size > 0 )
263281 {
264- LuaObjectDecoder decoder = new LuaObjectDecoder ( valuePtr , size ) ;
282+ LuaObjectDecoder decoder = new LuaObjectDecoder ( valuePtr , size , this ) ;
265283 return decoder . readObject ( ) as LuaValue ;
266284 }
267285
@@ -279,7 +297,7 @@ public void retainValue(LuaValue value)
279297 if ( value != null )
280298 {
281299 IntPtr valuePtr = IntPtr . Zero ;
282- LuaObjectEncoder encoder = new LuaObjectEncoder ( ) ;
300+ LuaObjectEncoder encoder = new LuaObjectEncoder ( this ) ;
283301 encoder . writeObject ( value ) ;
284302
285303 byte [ ] bytes = encoder . bytes ;
@@ -306,7 +324,7 @@ public void releaseValue(LuaValue value)
306324 if ( value != null )
307325 {
308326 IntPtr valuePtr = IntPtr . Zero ;
309- LuaObjectEncoder encoder = new LuaObjectEncoder ( ) ;
327+ LuaObjectEncoder encoder = new LuaObjectEncoder ( this ) ;
310328 encoder . writeObject ( value ) ;
311329
312330 byte [ ] bytes = encoder . bytes ;
@@ -331,7 +349,7 @@ public LuaValue evalScript(string script)
331349 {
332350 IntPtr resultPtr = IntPtr . Zero ;
333351 int size = NativeUtils . evalScript ( _nativeObjectId , script , out resultPtr ) ;
334- return LuaObjectDecoder . DecodeObject ( resultPtr , size ) as LuaValue ;
352+ return LuaObjectDecoder . DecodeObject ( resultPtr , size , this ) as LuaValue ;
335353 }
336354
337355 /// <summary>
@@ -373,7 +391,7 @@ public LuaValue evalScriptFromFile(string filePath)
373391#endif
374392 IntPtr resultPtr ;
375393 int size = NativeUtils . evalScriptFromFile ( _nativeObjectId , filePath , out resultPtr ) ;
376- LuaValue retValue = LuaObjectDecoder . DecodeObject ( resultPtr , size ) as LuaValue ;
394+ LuaValue retValue = LuaObjectDecoder . DecodeObject ( resultPtr , size , this ) as LuaValue ;
377395
378396 return retValue ;
379397
@@ -392,7 +410,7 @@ public LuaValue callMethod(string methodName, List<LuaValue> arguments)
392410
393411 if ( arguments != null )
394412 {
395- LuaObjectEncoder encoder = new LuaObjectEncoder ( ) ;
413+ LuaObjectEncoder encoder = new LuaObjectEncoder ( this ) ;
396414 encoder . writeInt32 ( arguments . Count ) ;
397415 foreach ( LuaValue value in arguments )
398416 {
@@ -413,7 +431,7 @@ public LuaValue callMethod(string methodName, List<LuaValue> arguments)
413431
414432 if ( size > 0 )
415433 {
416- return LuaObjectDecoder . DecodeObject ( resultPtr , size ) as LuaValue ;
434+ return LuaObjectDecoder . DecodeObject ( resultPtr , size , this ) as LuaValue ;
417435 }
418436
419437 return new LuaValue ( ) ;
@@ -468,7 +486,7 @@ private IntPtr luaMethodHandler(string methodName, IntPtr args, int size)
468486 if ( _methodHandlers . ContainsKey ( methodName ) )
469487 {
470488 //反序列化参数列表
471- LuaObjectDecoder decoder = new LuaObjectDecoder ( args , size ) ;
489+ LuaObjectDecoder decoder = new LuaObjectDecoder ( args , size , this ) ;
472490 int argSize = decoder . readInt32 ( ) ;
473491
474492 List < LuaValue > argumentsList = new List < LuaValue > ( ) ;
@@ -486,7 +504,7 @@ private IntPtr luaMethodHandler(string methodName, IntPtr args, int size)
486504 retValue = new LuaValue ( ) ;
487505 }
488506
489- LuaObjectEncoder encoder = new LuaObjectEncoder ( ) ;
507+ LuaObjectEncoder encoder = new LuaObjectEncoder ( this ) ;
490508 encoder . writeObject ( retValue ) ;
491509
492510 byte [ ] bytes = encoder . bytes ;
0 commit comments