Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix a Lua stack overflow in the C callback MJLuaCompletionsForWord
  • Loading branch information
cmsj committed Apr 10, 2018
1 parent 901b7ab commit 2b7abf2
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Hammerspoon/MJLua.m
Expand Up @@ -787,19 +787,16 @@ void MJLuaDealloc(void) {
_lua_stackguard_entry(skin.L);

[skin pushLuaRef:refTable ref:completionsForWordFn];
if (!lua_isfunction(skin.L, -1)) {
HSNSLOG(@"ERROR: MJLuaCompletionsForWord doesn't seem to have a completionsForWordFn");
_lua_stackguard_exit(skin.L);
return @[];
}
[skin pushNSObject:completionWord];
if ([skin protectedCallAndError:@"MJLuaCompletionsForWord" nargs:1 nresults:1] == NO) {
_lua_stackguard_exit(skin.L);
return @[];
}

NSArray *completions = [skin toNSObjectAtIndex:-1];
lua_pop(skin.L, 1);
_lua_stackguard_exit(skin.L);
return [skin toNSObjectAtIndex:-1];
return completions;
}

// C-Code helper to return current active LuaState. Useful for callbacks to
Expand Down

0 comments on commit 2b7abf2

Please sign in to comment.