From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason at zx2c4.com (Jason A. Donenfeld) Date: Sat, 11 Jan 2014 03:34:49 +0100 Subject: RFE: .so filters In-Reply-To: <52D0520C.1070609@xinu.at> References: <20140109225802.GM7608@serenity.lan> <20140110090639.GN7608@serenity.lan> <52D029F9.40805@xinu.at> <52D0520C.1070609@xinu.at> Message-ID: On Fri, Jan 10, 2014 at 9:03 PM, Florian Pritz wrote: > How about using the current fork approach but instead of calling execvp > use lua. I believe forks are pretty cheap on linux, it's the exec that's > costly. > > If we do it like that we could reuse stdin/stdout, we could pass > arguments via lua tables (like command line arguments now), but we > should have little overhead for the script loading/executing. > This is a very interesting idea. But I think it defeats a lot of the benefits of using lua in the first place. The pipe requires copying to and from the kernel, whereas if we did it in the same process, it's just a more or less transfer of memory in the same space. Further, there's no need to fork(), since what we're doing is distinctly synchronous -- the parent process in such a fork() would simply be wait()ing on the child to complete. So it's really not even necessary. I think the best solution is to hook the html_raw function, which usually calls write, into calling the lua function (referred to as filter_write(char *data, size_t len) above). This way, the same approach would allow other types of plugin systems easy -- .so files or whatever else.