mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
copy with sentinel instead of manually adding it
This commit is contained in:
parent
41865d11ab
commit
60a8466fe8
1 changed files with 5 additions and 15 deletions
|
|
@ -55,15 +55,10 @@ remote: *RemoteLua,
|
||||||
const chunk = std.mem.sliceTo(req.lua_chunk, 0);
|
const chunk = std.mem.sliceTo(req.lua_chunk, 0);
|
||||||
// TODO: this could be a lot smarter, we don't want to add return to a
|
// TODO: this could be a lot smarter, we don't want to add return to a
|
||||||
// statement which already has return infront of it.
|
// statement which already has return infront of it.
|
||||||
const str = std.mem.concat(gpa, u8, &[_][]const u8{ "return ", chunk }) catch {
|
const str = std.mem.concatWithSentinel(gpa, u8, &[_][]const u8{ "return ", chunk }, 0) catch return catchLuaFail(remote);
|
||||||
return catchLuaFail(remote);
|
defer gpa.free(str);
|
||||||
};
|
|
||||||
|
|
||||||
const w_sentinel = gpa.allocSentinel(u8, str.len, 0) catch Utils.oomPanic();
|
remote.L.loadString(str) catch catchLuaFail(remote);
|
||||||
defer gpa.free(w_sentinel);
|
|
||||||
std.mem.copyForwards(u8, w_sentinel, str[0..str.len]);
|
|
||||||
|
|
||||||
remote.L.loadString(w_sentinel) catch catchLuaFail(remote);
|
|
||||||
remote.L.protectedCall(.{
|
remote.L.protectedCall(.{
|
||||||
.results = zlua.mult_return,
|
.results = zlua.mult_return,
|
||||||
}) catch catchLuaFail(remote);
|
}) catch catchLuaFail(remote);
|
||||||
|
|
@ -89,14 +84,9 @@ fn handleDestroy(_: *mez.RemoteLuaV1, remote_lua: *RemoteLua) void {
|
||||||
|
|
||||||
fn catchLuaFail(remote: *RemoteLua) void {
|
fn catchLuaFail(remote: *RemoteLua) void {
|
||||||
const err_txt: []const u8 = remote.L.toString(-1) catch "zig error";
|
const err_txt: []const u8 = remote.L.toString(-1) catch "zig error";
|
||||||
const txt = std.mem.concat(gpa, u8, &[_][]const u8{ "repl: ", err_txt }) catch Utils.oomPanic();
|
const txt = std.mem.concatWithSentinel(gpa, u8, &[_][]const u8{ "repl: ", err_txt }, 0) catch Utils.oomPanic();
|
||||||
defer gpa.free(txt);
|
defer gpa.free(txt);
|
||||||
|
|
||||||
// must add the sentinel back to pass the data over the wire
|
sendNewLogEntry(txt);
|
||||||
const w_sentinel = gpa.allocSentinel(u8, txt.len, 0) catch Utils.oomPanic();
|
|
||||||
defer gpa.free(w_sentinel);
|
|
||||||
std.mem.copyForwards(u8, w_sentinel, txt[0..txt.len]);
|
|
||||||
|
|
||||||
sendNewLogEntry(w_sentinel);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue