ref: 4d255d3f3e8bba62cdf62a4b1202d83f686b05b8
parent: 0ab5e19fd514edbed395c43cbe854cf43bd2a01d
author: telephil9 <telephil9@gmail.com>
date: Wed Oct 28 01:29:44 EDT 2020
Change fork() to accept multiple arguments fork() now allows functions that take any number of arguments. All additional arguments passed to fork are then passed to the function. This simplifies the overall API and do not require currying anymore.
--- a/lib9.c
+++ b/lib9.c
@@ -11,6 +11,7 @@
lfork(lua_State *L)
{
char err[128];
+ int n;
if(lua_isfunction(L, 1) == 0)
return luaL_argerror(L, 1, "expected a function");
@@ -22,7 +23,8 @@
case 0:
break;
default:
- lua_call(L, 0, 0);
+ n = lua_gettop(L);
+ lua_call(L, n - 1, 0);
}
return 0;
}
--- a/samples/plumbmon.lua
+++ b/samples/plumbmon.lua
@@ -7,17 +7,15 @@
print(s)
end
-function make_listener(port)
- return function()
- fd = plumb.open(port, plan9.OREAD)
- while true do
- local m = plumb.recv(fd)
- log_message(port, m.data)
- end
- end
+function listen(port)
+ fd = plumb.open(port, plan9.OREAD)
+ while true do
+ local m = plumb.recv(fd)
+ log_message(port, m.data)
+ end
end
local ports = { "edit", "web", "image", "seemail" }
for k,v in ipairs(ports) do
- plan9.fork(make_listener(v))
+ plan9.fork(listen, v)
end