The code path I'm imagining is:
-receiveMessage()
-find the next message in the queue
-set a flag saying "we're receiving a message of length n"
-lua_pushlstring(L, msg, n);
-the allocator sees the flag is set, sees Lua asking for a string of length n, and gives it the message's memory block (with refcount set appropriately)
-receiveMessage() returns
But I wonder if it's possible that for whatever internal reasons, Lua happens to allocate an unrelated string as well during this time, also of length n?
If not then this would definitely be an interesting solution.
--
Sent from my Game Boy.