an experimental irc client

lua: clear stack in all callbacks

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>

+4 -1
+4 -1
src/lua.zig
··· 117 117 118 118 /// The on_connect event is emitted when we complete registration and receive a RPL_WELCOME message 119 119 pub fn onConnect(lua: *Lua, client: *irc.Client) !void { 120 + defer lua.setTop(0); // [] 120 121 lua.pushLightUserdata(client); // [light_userdata] 121 122 lua.setField(registry_index, client_key); // [] 122 123 ··· 135 136 } 136 137 137 138 pub fn onMessage(lua: *Lua, client: *irc.Client, channel: []const u8, sender: []const u8, msg: []const u8) !void { 139 + defer lua.setTop(0); // [] 138 140 Client.getTable(lua, client.config.lua_table); // [table] 139 141 const lua_type = lua.getField(1, "on_message"); // [table, type] 140 142 switch (lua_type) { ··· 145 147 _ = lua.pushString(msg); // [function,string,string,string] 146 148 lua.protectedCall(3, 0, 0) catch return error.LuaError; 147 149 }, 148 - else => lua.pop(2), // [] 150 + else => {}, 149 151 } 150 152 } 151 153 ··· 158 160 } 159 161 160 162 pub fn execUserCommand(lua: *Lua, cmdline: []const u8, func: i32) !void { 163 + defer lua.setTop(0); // [] 161 164 const lua_type = lua.rawGetIndex(registry_index, func); // [function] 162 165 _ = lua.pushString(cmdline); // [function, string] 163 166