Search code examples
luaipcinterprocess

Interprocess communication in Lua with Example?


I have been struggling a lot to get this to work. Can someone provide an example with any LUA api of 2 scripts that pass a message back and forth.

I have tried Oil, lua-ipc and zeromq. But I face several missing libraries issues.

The ultimate goal is to pass a vector of numbers from one Lua process to another Lua process (with a different version of Lua) without going through disk.

Here is a similar example in python of IPC in a single file. Something similar in lua would be extremely helpful.

I really need an example as my knowledge in pipes or UDP/TCP is not strong.


Solution

  • The equivalent would be to use luasocket. These examples come very close to the python example given. Here socket:receive() is used for the framing.

    https://github.com/diegonehab/luasocket/blob/master/samples/listener.lua

    https://github.com/diegonehab/luasocket/blob/master/samples/talker.lua