this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

lua: ref commands and config tables

Prevent garbage collection of commands and config tables by referencing
them in the global registry.

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

+11 -3
+11 -3
src/lua.zig
··· 307 307 lua.pop(1); // [table] 308 308 break :blk true; 309 309 }, 310 - .boolean => lua.toBoolean(-1), // [table] 310 + .boolean => blk: { 311 + const val = lua.toBoolean(-1); 312 + lua.pop(1); // [table] 313 + break :blk val; 314 + }, 311 315 else => lua.raiseErrorStr("expected a boolean for field 'tls'", .{}), 312 316 }; 313 317 314 - lua.pop(1); // [] 318 + // Ref the config table so it doesn't get garbage collected 319 + _ = lua.ref(registry_index) catch lua.raiseErrorStr("couldn't ref config table", .{}); // [] 315 320 316 321 Client.initTable(lua); // [table] 317 322 const table_ref = lua.ref(registry_index) catch { ··· 364 369 fn addCommand(lua: *Lua) i32 { 365 370 lua.argCheck(lua.isString(1), 1, "expected a string"); // [string, function] 366 371 lua.argCheck(lua.isFunction(2), 2, "expected a function"); // [string, function] 367 - const ref = lua.ref(registry_index) catch lua.raiseErrorStr("couldn't ref function", .{}); 372 + const ref = lua.ref(registry_index) catch lua.raiseErrorStr("couldn't ref function", .{}); // [string] 368 373 const cmd = lua.toString(1) catch unreachable; 374 + 375 + // ref the string so we don't garbage collect it 376 + _ = lua.ref(registry_index) catch lua.raiseErrorStr("couldn't ref command name", .{}); // [] 369 377 comlink.Command.user_commands.put(cmd, ref) catch lua.raiseErrorStr("out of memory", .{}); 370 378 return 0; 371 379 }