From d8acb18ce8bf6e89a042d166f61b2934e8722cf0 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 24 Jul 2025 16:51:49 +0200 Subject: Rework function bytecode dumping to be Lua5.5-ready * prepare the luaL_Buffer in the destination state instead of the source state to prevent stack issues when everything happens in the same state --- unit_tests/scripts/lane/tasking_send_receive_code.lua | 18 ++++++++---------- .../scripts/linda/send_receive_func_and_string.lua | 13 +++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 unit_tests/scripts/linda/send_receive_func_and_string.lua (limited to 'unit_tests/scripts') diff --git a/unit_tests/scripts/lane/tasking_send_receive_code.lua b/unit_tests/scripts/lane/tasking_send_receive_code.lua index cb3663f..fdc2602 100644 --- a/unit_tests/scripts/lane/tasking_send_receive_code.lua +++ b/unit_tests/scripts/lane/tasking_send_receive_code.lua @@ -53,28 +53,26 @@ local function chunk2(linda) assert(info.linedefined == 32, "bad linedefined") -- start of 'chunk2' assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' - local k,func= linda:receive("down") - assert(type(func)=="function", "not a function") + assert(linda:count("down") == 2, "bad linda contents") -- function, "ok" + local k,func,str= linda:receive_batched("down", 2) assert(k=="down") + assert(type(func)=="function", "not a function") + assert(str=="ok", "bad receive result: " .. tostring(k) .. " -> ".. tostring(str)) + assert(linda:count("down") == 0, "bad linda contents") -- nothing func(linda) - - local k,str= linda:receive("down") - assert(str=="ok", "bad receive result") - linda:send("up", function() return ":)" end, "ok2") end local linda = lanes_linda{name = "auto"} local t2= lanes_gen("debug,package,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch -linda:send("down", function(linda) linda:send("up", "ready!") end, - "ok") +linda:send("down", function(linda) linda:send("up", "ready!") end, "ok") -- wait to see if the tiny function gets executed -- local k,s= linda:receive(1, "up") if t2.status == "error" then - PRINT("t2 error: " , t2:join()) - assert(false) + local n,err,s = t2:join() + assert(false, "t2 error: " .. err) end PRINT(s) assert(s=="ready!", s .. " is not 'ready!'") diff --git a/unit_tests/scripts/linda/send_receive_func_and_string.lua b/unit_tests/scripts/linda/send_receive_func_and_string.lua new file mode 100644 index 0000000..188cfcd --- /dev/null +++ b/unit_tests/scripts/linda/send_receive_func_and_string.lua @@ -0,0 +1,13 @@ +local lanes = require "lanes" + +-- a newly created linda doesn't contain anything +local l = lanes.linda() + +-- send a function and a string, make sure that's what we read back +l:send("k", function() end, "str") +local c = l:count("k") +assert(c == 2, "got " .. c) +local k, v1, v2 = l:receive_batched("k", 2) +local tv1, tv2 = type(v1), type(v2) +assert(k == "k" and tv1 == "function" and tv2 == "string", "got " .. tv1 .. " " .. tv2) +assert(l:count("k") == 0) -- cgit v1.2.3-55-g6feb