shithub: lu9-p9

Download patch

ref: fbdd4e91a0d9285cd2bbe05659444493211edc8e
parent: 3fc6d7a0f87a487c5d33b838ff5b5b9968b7b1cc
author: kvik <kvik@a-b.xyz>
date: Mon Apr 19 09:17:35 EDT 2021

proc: implement p9.fatal()

--- a/p9.c
+++ b/p9.c
@@ -172,6 +172,7 @@
 	
 	{"abort", p9_abort},
 	{"exits", p9_exits},
+	{"fatal", p9_fatal},
 	{"sleep", p9_sleep},
 	{"alarm", p9_alarm},
 	{"rfork", p9_rfork},
--- a/proc.c
+++ b/proc.c
@@ -13,6 +13,21 @@
 }
 
 static int
+p9_fatal(lua_State *L)
+{
+	if(lua_gettop(L) > 1
+	&& lua_getglobal(L, "string") == LUA_TTABLE
+	&& lua_getfield(L, -1, "format") == LUA_TFUNCTION){
+		lua_remove(L, -2);
+		lua_insert(L, 1);
+		if(lua_pcall(L, lua_gettop(L) - 1, 1, 0) == LUA_OK)
+			sysfatal(lua_tostring(L, -1));
+	}
+	sysfatal(luaL_optstring(L, 1, "fatal"));
+	/* never */ return 0;
+}
+
+static int
 p9_sleep(lua_State *L)
 {
 	long t;