Skip to content

Commit

Permalink
LuaSkin's pushNSObject helpers for arrays, sets and dictionaries now …
Browse files Browse the repository at this point in the history
…explicitly request Lua expand its stack to 2x the number of items in those collections, so we don't silently overflow the stack
  • Loading branch information
cmsj committed Apr 4, 2018
1 parent 3b8f170 commit fe884a1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LuaSkin/LuaSkin/Skin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,11 @@ - (int)pushNSValue:(id)obj withOptions:(__unused NSUInteger)options {

- (int)pushNSArray:(id)obj withOptions:(NSUInteger)options alreadySeenObjects:(NSMutableDictionary *)alreadySeen {
NSArray* list = obj;
// Ensure our Lua stack is large enough for the number of items being pushed
if (!lua_checkstack(self.L, (int)list.count * 2)) {
lua_pushnil(self.L);
return 1;
}
lua_newtable(self.L);
alreadySeen[obj] = @(luaL_ref(self.L, LUA_REGISTRYINDEX)) ;
lua_rawgeti(self.L, LUA_REGISTRYINDEX, [alreadySeen[obj] intValue]) ; // put it back on the stack
Expand All @@ -1046,6 +1051,11 @@ - (int)pushNSArray:(id)obj withOptions:(NSUInteger)options alreadySeenObjects:(N

- (int)pushNSSet:(id)obj withOptions:(NSUInteger)options alreadySeenObjects:(NSMutableDictionary *)alreadySeen {
NSSet* list = obj;
// Ensure our Lua stack is large enough for the number of items being pushed
if (!lua_checkstack(self.L, (int)list.count * 2)) {
lua_pushnil(self.L);
return 1;
}
lua_newtable(self.L);
alreadySeen[obj] = @(luaL_ref(self.L, LUA_REGISTRYINDEX)) ;
lua_rawgeti(self.L, LUA_REGISTRYINDEX, [alreadySeen[obj] intValue]) ; // put it back on the stack
Expand All @@ -1061,6 +1071,11 @@ - (int)pushNSSet:(id)obj withOptions:(NSUInteger)options alreadySeenObjects:(NSM
- (int)pushNSDictionary:(id)obj withOptions:(NSUInteger)options alreadySeenObjects:(NSMutableDictionary *)alreadySeen {
NSArray *keys = [obj allKeys];
NSArray *values = [obj allValues];
// Ensure our Lua stack is large enough for the number of items being pushed
if (!lua_checkstack(self.L, (int)keys.count * 2)) {
lua_pushnil(self.L);
return 1;
}
lua_newtable(self.L);
alreadySeen[obj] = @(luaL_ref(self.L, LUA_REGISTRYINDEX)) ;
lua_rawgeti(self.L, LUA_REGISTRYINDEX, [alreadySeen[obj] intValue]) ; // put it back on the stack
Expand Down

0 comments on commit fe884a1

Please sign in to comment.