/*- Author: Brian Tiffin Dedicated to the public domain Date: November 2016 Modified: 2016-11-14/14:27-0500 +*/ /* unilua-v1.c loadfunc a Lua interpreter in Unicon tectonics: gcc -o unilua-v1.so -shared -fpic unilua-v1.c \ -I/usr/include/lua5.3 -llua5.3 */ #include #include #include #include #include #include "icall.h" int unilua (int argc, descriptor argv[]) { char buff[256]; int error; char *unibuf; #ifdef LUA50 lua_State *L = lua_open(); /* opens Lua */ if (!L) { Error(500); } luaopen_base(L); /* opens the basic library */ luaopen_table(L); /* opens the table library */ luaopen_io(L); /* opens the I/O library */ luaopen_string(L); /* opens the string lib. */ luaopen_math(L); /* opens the math lib. */ #else lua_State *L = luaL_newstate(); if (!L) { Error(500); } luaL_openlibs(L); #endif /* ensure argv[1] is a string */ ArgString(1); /* evaluate some Lua */ unibuf = StringVal(argv[1]); error = luaL_loadbuffer(L, unibuf, strlen(unibuf), "line") || lua_pcall(L, 0, 0, 0); if (error) { fprintf(stderr, "%s", lua_tostring(L, -1)); lua_pop(L, 1); /* pop error message from the stack */ Error(107); } lua_close(L); RetInteger(42); return 0; }