File tree Expand file tree Collapse file tree 4 files changed +35
-24
lines changed
Expand file tree Collapse file tree 4 files changed +35
-24
lines changed Original file line number Diff line number Diff line change 1111#import " LSCContext_Private.h"
1212#import " LSCValue_Private.h"
1313#import " LSCTuple_Private.h"
14- #import " LSCManagedObjectProtocol.h"
15-
16- @interface LSCFunction () <LSCManagedObjectProtocol>
17-
18- /* *
19- 连接标识
20- */
21- @property (nonatomic , copy ) NSString *_linkId;
22-
23- @end
2414
2515@implementation LSCFunction
2616
@@ -29,8 +19,11 @@ - (instancetype)initWithContext:(LSCContext *)context index:(NSInteger)index
2919 if (self = [super init ])
3020 {
3121 self.context = context;
32- self._linkId = [NSString stringWithFormat: @" %p " , self ];
22+ self.linkId = [NSString stringWithFormat: @" %p " , self ];
3323
24+ // 设置Lua对象到_vars_表中
25+ [self .context.dataExchanger setLubObjectByStackIndex: index objectId: self .linkId];
26+ // 进行引用
3427 [self .context retainValue: [LSCValue functionValue: self ]];
3528 }
3629
@@ -112,11 +105,6 @@ - (LSCValue *)invokeWithArguments:(NSArray<LSCValue *> *)arguments
112105
113106#pragma mark - LSCManagedObjectProtocol
114107
115- - (NSString *)linkId
116- {
117- return self._linkId ;
118- }
119-
120108- (BOOL )pushWithContext : (LSCContext *)context
121109{
122110 return YES ;
Original file line number Diff line number Diff line change 88
99#import " LSCFunction.h"
1010#import " lua.h"
11+ #import " LSCManagedObjectProtocol.h"
1112
1213@class LSCContext;
1314
14- @interface LSCFunction ()
15+ @interface LSCFunction () <LSCManagedObjectProtocol>
1516
1617/* *
1718 上下文对象
2425 */
2526@property (nonatomic , copy ) NSString *index;
2627
28+ /* *
29+ 连接标识
30+ */
31+ @property (nonatomic , copy ) NSString *linkId;
32+
2733/* *
2834 初始化Lua方法
2935
Original file line number Diff line number Diff line change 4646 */
4747- (void )getLuaObject : (id )nativeObject ;
4848
49+ /* *
50+ 设置Lua对象
51+
52+ @param index Lua对象在栈中索引
53+ @param objectId 对象标识
54+ */
55+ - (void )setLubObjectByStackIndex : (NSInteger )index objectId : (NSString *)objectId ;
56+
4957/* *
5058 保留对象对应在Lua中的引用
5159
6068 */
6169- (void )releaseLuaObject : (id )nativeObject ;
6270
71+
72+
6373@end
Original file line number Diff line number Diff line change @@ -205,13 +205,7 @@ - (LSCValue *)valueByStackIndex:(int)index
205205 if (objectId && (type == LUA_TTABLE || type == LUA_TUSERDATA || type == LUA_TLIGHTUSERDATA || type == LUA_TFUNCTION))
206206 {
207207 // 将引用对象放入表中
208- [self doActionInVarsTable: ^{
209-
210- // 放入对象到_vars_表中
211- lua_pushvalue (state, (int )index);
212- lua_setfield (state, -2 , objectId.UTF8String );
213-
214- }];
208+ [self setLubObjectByStackIndex: index objectId: objectId];
215209 }
216210
217211 return value;
@@ -328,6 +322,19 @@ - (void)getLuaObject:(id)nativeObject
328322 }
329323}
330324
325+ - (void )setLubObjectByStackIndex : (NSInteger )index objectId : (NSString *)objectId
326+ {
327+ lua_State *state = self.context .state ;
328+
329+ [self doActionInVarsTable: ^{
330+
331+ // 放入对象到_vars_表中
332+ lua_pushvalue (state, (int )index);
333+ lua_setfield (state, -2 , objectId.UTF8String );
334+
335+ }];
336+ }
337+
331338- (void )retainLuaObject : (id )nativeObject
332339{
333340 if (nativeObject)
You can’t perform that action at this time.
0 commit comments