ref: 9becc0f49e578b65be68e4b4e7c9bb576da09966
author: kvik <[email protected]>
date: Sat Feb 6 19:33:49 EST 2021
Start of native Lua standalone interpreter for Plan 9
--- /dev/null
+++ b/lua.c
@@ -1,0 +1,37 @@
+#include <u.h>
+#include <libc.h>
+
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+
+extern int luaopen_lpeg(lua_State *L);
+
+void
+main(int argc, char *argv[])
+{
+ lua_State *L;
+
+ if((L = luaL_newstate()) == NULL)
+ sysfatal("out of memory");
+ luaL_openlibs(L);
+ luaL_requiref(L, "lpeg", luaopen_lpeg, 1);
+ lua_pop(L, 1);
+
+ lua_createtable(L, argc, 0);
+ for(int i = 0; i < argc; i++){
+ lua_pushstring(L, argv[i]);
+ lua_rawseti(L, -2, i);
+ }
+ lua_setglobal(L, "arg");
+
+ if(luaL_loadfile(L, argv[1]) != LUA_OK)
+ sysfatal("%s", lua_tostring(L, -1));
+ for(int i = 1; i < argc; i++)
+ lua_pushstring(L, argv[i]);
+ if(lua_pcall(L, argc-1, LUA_MULTRET, 0) != LUA_OK)
+ sysfatal("%s", lua_tostring(L, -1));
+ lua_close(L);
+
+ exits(nil);
+}
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,35 @@
+</$objtype/mkfile
+
+CFLAGS=-FTVw -p -Ishim -Ilua -Ilpeg -DLUA_USE_PLAN9
+
+TARG=$O.lua
+
+OBJS=lua.$O
+
+LIBS=\
+ lua/liblua.a$O\
+ lpeg/liblpeg.a$O\
+ shim/libshim.a$O
+
+all:V: $TARG
+
+clean:V:
+ @{cd shim; mk clean}
+ @{cd lua; mk clean}
+ @{cd lpeg; mk clean}
+ rm -f $TARG [$OS].out *.[$OS] *.a[$OS]
+
+shim/libshim.a$O:
+ @{cd shim; mk}
+
+lua/liblua.a$O:
+ @{cd lua; mk}
+
+lpeg/liblpeg.a$O:
+ @{cd lpeg; mk}
+
+$TARG: $OBJS $LIBS
+ $LD -o $TARG $prereq
+
+%.$O: %.c
+ $CC $CFLAGS $stem.c