ref: a5c6a7b0ba55e5a88e1e1f1f5140b1195bbfbeaf
dir: /lib9.c/
#include <u.h> #include <lib9.h> #include <lua.h> #include <lauxlib.h> #include <lualib.h> #include "llib9.h" #include "utils.h" static int lfork(lua_State *L) { char err[128]; if(lua_isfunction(L, 1) == 0) return luaL_argerror(L, 1, "expected a function"); switch(rfork(RFFDG|RFREND|RFPROC)){ case -1: errstr(err, sizeof err); lua_pushfstring(L, "fork failed: %s", err); return lua_error(L); case 0: break; default: lua_call(L, 0, 0); } return 0; } static const struct luaL_Reg lib9 [] = { { "fork", lfork }, { NULL, NULL } }; int openlib9(lua_State *L) { luaL_newlib(L, lib9); pushglobal(L, "OREAD", 0); pushglobal(L, "OWRITE", 1); return 1; }