diff a/lauxlib.c lua/lauxlib.c
245,265d244
< 
< LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
<   int en = errno;  /* calls to Lua API may change this value */
<   if (stat) {
<     lua_pushboolean(L, 1);
<     return 1;
<   }
<   else {
<     const char *msg;
<     luaL_pushfail(L);
<     msg = (en != 0) ? strerror(en) : "(no extra info)";
<     if (fname)
<       lua_pushfstring(L, "%s: %s", fname, msg);
<     else
<       lua_pushstring(L, msg);
<     lua_pushinteger(L, en);
<     return 3;
<   }
< }
< 
< 
288,303d266
< LUALIB_API int luaL_execresult (lua_State *L, int stat) {
<   if (stat != 0 && errno != 0)  /* error with an 'errno'? */
<     return luaL_fileresult(L, 0, NULL);
<   else {
<     const char *what = "exit";  /* type of termination */
<     l_inspectstat(stat, what);  /* interpret result */
<     if (*what == 'e' && stat == 0)  /* successful termination? */
<       lua_pushboolean(L, 1);
<     else
<       luaL_pushfail(L);
<     lua_pushstring(L, what);
<     lua_pushinteger(L, stat);
<     return 3;  /* return true/fail,what,code */
<   }
< }
< 
711,825d673
< 
< typedef struct LoadF {
<   int n;  /* number of pre-read characters */
<   FILE *f;  /* file being read */
<   char buff[BUFSIZ];  /* area for reading file */
< } LoadF;
< 
< 
< static const char *getF (lua_State *L, void *ud, size_t *size) {
<   LoadF *lf = (LoadF *)ud;
<   (void)L;  /* not used */
<   if (lf->n > 0) {  /* are there pre-read characters to be read? */
<     *size = lf->n;  /* return them (chars already in buffer) */
<     lf->n = 0;  /* no more pre-read characters */
<   }
<   else {  /* read a block from file */
<     /* 'fread' can return > 0 *and* set the EOF flag. If next call to
<        'getF' called 'fread', it might still wait for user input.
<        The next check avoids this problem. */
<     if (feof(lf->f)) return NULL;
<     *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);  /* read block */
<   }
<   return lf->buff;
< }
< 
< 
< static int errfile (lua_State *L, const char *what, int fnameindex) {
<   int err = errno;
<   const char *filename = lua_tostring(L, fnameindex) + 1;
<   if (err != 0)
<     lua_pushfstring(L, "cannot %s %s: %s", what, filename, strerror(err));
<   else
<     lua_pushfstring(L, "cannot %s %s", what, filename);
<   lua_remove(L, fnameindex);
<   return LUA_ERRFILE;
< }
< 
< 
< /*
< ** Skip an optional BOM at the start of a stream. If there is an
< ** incomplete BOM (the first character is correct but the rest is
< ** not), returns the first character anyway to force an error
< ** (as no chunk can start with 0xEF).
< */
< static int skipBOM (FILE *f) {
<   int c = getc(f);  /* read first character */
<   if (c == 0xEF && getc(f) == 0xBB && getc(f) == 0xBF)  /* correct BOM? */
<     return getc(f);  /* ignore BOM and return next char */
<   else  /* no (valid) BOM */
<     return c;  /* return first character */
< }
< 
< 
< /*
< ** reads the first character of file 'f' and skips an optional BOM mark
< ** in its beginning plus its first line if it starts with '#'. Returns
< ** true if it skipped the first line.  In any case, '*cp' has the
< ** first "valid" character of the file (after the optional BOM and
< ** a first-line comment).
< */
< static int skipcomment (FILE *f, int *cp) {
<   int c = *cp = skipBOM(f);
<   if (c == '#') {  /* first line is a comment (Unix exec. file)? */
<     do {  /* skip first line */
<       c = getc(f);
<     } while (c != EOF && c != '\n');
<     *cp = getc(f);  /* next character after comment, if present */
<     return 1;  /* there was a comment */
<   }
<   else return 0;  /* no comment */
< }
< 
< 
< LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
<                                              const char *mode) {
<   LoadF lf;
<   int status, readstatus;
<   int c;
<   int fnameindex = lua_gettop(L) + 1;  /* index of filename on the stack */
<   if (filename == NULL) {
<     lua_pushliteral(L, "=stdin");
<     lf.f = stdin;
<   }
<   else {
<     lua_pushfstring(L, "@%s", filename);
<     errno = 0;
<     lf.f = fopen(filename, "r");
<     if (lf.f == NULL) return errfile(L, "open", fnameindex);
<   }
<   lf.n = 0;
<   if (skipcomment(lf.f, &c))  /* read initial portion */
<     lf.buff[lf.n++] = '\n';  /* add newline to correct line numbers */
<   if (c == LUA_SIGNATURE[0]) {  /* binary file? */
<     lf.n = 0;  /* remove possible newline */
<     if (filename) {  /* "real" file? */
<       errno = 0;
<       lf.f = freopen(filename, "rb", lf.f);  /* reopen in binary mode */
<       if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
<       skipcomment(lf.f, &c);  /* re-read initial portion */
<     }
<   }
<   if (c != EOF)
<     lf.buff[lf.n++] = c;  /* 'c' is the first character of the stream */
<   errno = 0;
<   status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
<   readstatus = ferror(lf.f);
<   if (filename) fclose(lf.f);  /* close file (even in case of errors) */
<   if (readstatus) {
<     lua_settop(L, fnameindex);  /* ignore results from 'lua_load' */
<     return errfile(L, "read", fnameindex);
<   }
<   lua_remove(L, fnameindex);
<   return status;
< }
< 
diff a/lauxlib.h lua/lauxlib.h
26,29d25
< /* extra error code for 'luaL_loadfilex' */
< #define LUA_ERRFILE     (LUA_ERRERR+1)
< 
< 
81,84d76
< LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
< LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
< 
< 
92,96d83
< LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
<                                                const char *mode);
< 
< #define luaL_loadfile(L,f)	luaL_loadfilex(L,f,NULL)
< 
144,146d130
< #define luaL_dofile(L, fn) \
< 	(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
< 
242,249d225
< #define LUA_FILEHANDLE          "FILE*"
< 
< 
< typedef struct luaL_Stream {
<   FILE *f;  /* stream (NULL for incompletely created streams) */
<   lua_CFunction closef;  /* to close stream (NULL for closed streams) */
< } luaL_Stream;
< 
258,266c234
< /* print a string */
< #if !defined(lua_writestring)
< #define lua_writestring(s,l)   fwrite((s), sizeof(char), (l), stdout)
< #endif
< 
< /* print a newline and flush the output */
< #if !defined(lua_writeline)
< #define lua_writeline()        (lua_writestring("\n", 1), fflush(stdout))
< #endif
---
> void main_log(int lvl, const char* fmt, ...);
269,272c237
< #if !defined(lua_writestringerror)
< #define lua_writestringerror(s,p) \
<         (fprintf(stderr, (s), (p)), fflush(stderr))
< #endif
---
> #define lua_writestringerror(s,p) (main_log(1, (s), (p)))
diff a/lbaselib.c lua/lbaselib.c
24,39d23
< static int luaB_print (lua_State *L) {
<   int n = lua_gettop(L);  /* number of arguments */
<   int i;
<   for (i = 1; i <= n; i++) {  /* for each argument */
<     size_t l;
<     const char *s = luaL_tolstring(L, i, &l);  /* convert it to string */
<     if (i > 1)  /* not the first element? */
<       lua_writestring("\t", 1);  /* add a tab before it */
<     lua_writestring(s, l);  /* print it */
<     lua_pop(L, 1);  /* pop result */
<   }
<   lua_writeline();
<   return 0;
< }
< 
< 
340,348d323
< static int luaB_loadfile (lua_State *L) {
<   const char *fname = luaL_optstring(L, 1, NULL);
<   const char *mode = luaL_optstring(L, 2, NULL);
<   int env = (!lua_isnone(L, 3) ? 3 : 0);  /* 'env' index or 0 if no 'env' */
<   int status = luaL_loadfilex(L, fname, mode);
<   return load_aux(L, status, env);
< }
< 
< 
409,424d383
< static int dofilecont (lua_State *L, int d1, lua_KContext d2) {
<   (void)d1;  (void)d2;  /* only to match 'lua_Kfunction' prototype */
<   return lua_gettop(L) - 1;
< }
< 
< 
< static int luaB_dofile (lua_State *L) {
<   const char *fname = luaL_optstring(L, 1, NULL);
<   lua_settop(L, 1);
<   if (l_unlikely(luaL_loadfile(L, fname) != LUA_OK))
<     return lua_error(L);
<   lua_callk(L, 0, LUA_MULTRET, 0, dofilecont);
<   return dofilecont(L, 0, 0);
< }
< 
< 
509d467
<   {"dofile", luaB_dofile},
513d470
<   {"loadfile", luaB_loadfile},
518d474
<   {"print", luaB_print},
Only in a: lcorolib.c
Only in a: ldblib.c
diff a/linit.c lua/linit.c
44,45d43
<   {LUA_LOADLIBNAME, luaopen_package},
<   {LUA_COLIBNAME, luaopen_coroutine},
47,48d44
<   {LUA_IOLIBNAME, luaopen_io},
<   {LUA_OSLIBNAME, luaopen_os},
52d47
<   {LUA_DBLIBNAME, luaopen_debug},
Only in a: liolib.c
Only in a: loadlib.c
Only in a: loslib.c
diff a/lstrlib.c lua/lstrlib.c
1273c1273
< static int str_format (lua_State *L) {
---
> int str_format (lua_State *L) {
Only in a: lua.c
Only in a: luac.c
diff a/luaconf.h lua/luaconf.h
44c44
< /* #define LUA_USE_C89 */
---
> #define LUA_USE_C89
125c125
< #define LUA_32BITS	0
---
> #define LUA_32BITS	1
596c596
< #if !defined(LUA_USE_C89)
---
> /*#if !defined(LUA_USE_C89)*/
598c598
< #else
---
> /*#else
600c600
< #endif
---
> #endif*/
749c749
< #define LUAI_MAXSTACK		1000000
---
> #define LUAI_MAXSTACK		16384
751c751
< #define LUAI_MAXSTACK		15000
---
> #define LUAI_MAXSTACK		16384
diff a/lualib.h lua/lualib.h
20,22d19
< #define LUA_COLIBNAME	"coroutine"
< LUAMOD_API int (luaopen_coroutine) (lua_State *L);
< 
26,31d22
< #define LUA_IOLIBNAME	"io"
< LUAMOD_API int (luaopen_io) (lua_State *L);
< 
< #define LUA_OSLIBNAME	"os"
< LUAMOD_API int (luaopen_os) (lua_State *L);
< 
40,45d30
< 
< #define LUA_DBLIBNAME	"debug"
< LUAMOD_API int (luaopen_debug) (lua_State *L);
< 
< #define LUA_LOADLIBNAME	"package"
< LUAMOD_API int (luaopen_package) (lua_State *L);
diff a/Makefile lua/Makefile
7c7
< PLAT= guess
---
> PLAT= c89
37c37
< LIB_O=	lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o
---
> LIB_O=	lauxlib.o lbaselib.o lmathlib.o lstrlib.o ltablib.o lutf8lib.o linit.o
46,47c46,47
< ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
< ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
---
> ALL_O= $(BASE_O)
> ALL_T= $(LUA_A)
