Переглянути джерело

more uniformity for defining system-dependent features

Roberto Ierusalimschy 11 роки тому
батько
коміт
c6c41e85b2
6 змінених файлів з 101 додано та 65 видалено
  1. 12 9
      ldo.c
  2. 21 20
      liolib.c
  3. 14 6
      lobject.c
  4. 18 7
      loslib.c
  5. 23 10
      lua.c
  6. 13 13
      luaconf.h

+ 12 - 9
ldo.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ldo.c,v 2.112 2013/11/08 18:16:33 roberto Exp roberto $
+** $Id: ldo.c,v 2.113 2014/02/15 13:12:01 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 */
@@ -46,30 +46,33 @@
 ** C++ code, with _longjmp/_setjmp when asked to use them, and with
 ** longjmp/setjmp otherwise.
 */
-#if !defined(LUAI_THROW)
+#if !defined(LUAI_THROW)				/* { */
+
+#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)	/* { */
 
-#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
 /* C++ exceptions */
 #define LUAI_THROW(L,c)		throw(c)
 #define LUAI_TRY(L,c,a) \
 	try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
 #define luai_jmpbuf		int  /* dummy variable */
 
-#elif defined(LUA_USE_ULONGJMP)
-/* in Unix, try _longjmp/_setjmp (more efficient) */
+#elif defined(LUA_USE_POSIX)				/* }{ */
+
+/* in Posix, try _longjmp/_setjmp (more efficient) */
 #define LUAI_THROW(L,c)		_longjmp((c)->b, 1)
 #define LUAI_TRY(L,c,a)		if (_setjmp((c)->b) == 0) { a }
 #define luai_jmpbuf		jmp_buf
 
-#else
-/* default handling with long jumps */
+#else							/* }{ */
+
+/* ANSI handling with long jumps */
 #define LUAI_THROW(L,c)		longjmp((c)->b, 1)
 #define LUAI_TRY(L,c,a)		if (setjmp((c)->b) == 0) { a }
 #define luai_jmpbuf		jmp_buf
 
-#endif
+#endif							/* } */
 
-#endif
+#endif							/* } */
 
 
 

+ 21 - 20
liolib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: liolib.c,v 2.115 2014/01/27 13:28:45 roberto Exp roberto $
+** $Id: liolib.c,v 2.116 2014/02/21 14:39:50 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 */
@@ -51,29 +51,30 @@
 ** =======================================================
 */
 
-#if !defined(lua_popen)	/* { */
+#if !defined(lua_popen)		/* { */
 
-#if defined(LUA_USE_POPEN)	/* { */
+#if defined(LUA_USE_POSIX)	/* { */
 
-#define lua_popen(L,c,m)	((void)L, fflush(NULL), popen(c,m))
-#define lua_pclose(L,file)	((void)L, pclose(file))
+#define lua_popen(L,c,m)	(fflush(NULL), popen(c,m))
+#define lua_pclose(L,file)	(pclose(file))
 
 #elif defined(LUA_WIN)		/* }{ */
 
-#define lua_popen(L,c,m)		((void)L, _popen(c,m))
-#define lua_pclose(L,file)		((void)L, _pclose(file))
-
+#define lua_popen(L,c,m)		(_popen(c,m))
+#define lua_pclose(L,file)		(_pclose(file))
 
 #else				/* }{ */
 
-#define lua_popen(L,c,m)		((void)((void)c, m),  \
-		luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
+/* ANSI definitions */
+#define lua_popen(L,c,m)  \
+	  ((void)((void)c, m), \
+	  luaL_error(L, LUA_QL("popen") " not supported"), \
+	  (FILE*)0)
 #define lua_pclose(L,file)		((void)((void)L, file), -1)
 
-
 #endif				/* } */
 
-#endif			/* } */
+#endif				/* } */
 
 /* }====================================================== */
 
@@ -84,7 +85,7 @@
 ** =======================================================
 */
 
-#if !defined(lua_fseek)	&& !defined(LUA_ANSI)	/* { */
+#if !defined(lua_fseek)		/* { */
 
 #if defined(LUA_USE_POSIX)	/* { */
 
@@ -94,22 +95,22 @@
 
 #elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
    && defined(_MSC_VER) && (_MSC_VER >= 1400)	/* }{ */
-/* Windows (but not DDK) and Visual C++ 2005 or higher */
 
+/* Windows (but not DDK) and Visual C++ 2005 or higher */
 #define l_fseek(f,o,w)		_fseeki64(f,o,w)
 #define l_ftell(f)		_ftelli64(f)
 #define l_seeknum		__int64
 
-#endif	/* } */
-
-#endif			/* } */
-
+#else				/* }{ */
 
-#if !defined(l_fseek)		/* default definitions */
+/* ANSI definitions */
 #define l_fseek(f,o,w)		fseek(f,o,w)
 #define l_ftell(f)		ftell(f)
 #define l_seeknum		long
-#endif
+
+#endif				/* } */
+
+#endif				/* } */
 
 /* }====================================================== */
 

+ 14 - 6
lobject.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.c,v 2.72 2014/01/27 13:34:32 roberto Exp roberto $
+** $Id: lobject.c,v 2.73 2014/02/06 15:59:24 roberto Exp $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -159,22 +159,26 @@ static int isneg (const char **s) {
 
 
 /*
+** {======================================================
 ** lua_strx2number converts an hexadecimal numeric string to a number.
 ** In C99, 'strtod' does both conversions. C89, however, has no function
 ** to convert floating hexadecimal strings to numbers. For these
 ** systems, you can leave 'lua_strx2number' undefined and Lua will
 ** provide its own implementation.
+** =======================================================
 */
-#if defined(LUA_USE_STRTODHEX)
+#if !defined(lua_strx2number)		/* { */
+
+#if defined(LUA_USE_C99)		/* { */
+
 #define lua_strx2number(s,p)    lua_str2number(s,p)
-#endif
 
+#else					/* }{ */
 
-#if !defined(lua_strx2number)
+/* Lua's implementation for 'lua_strx2number' */
 
 #include <math.h>
 
-
 /* maximum number of significant digits to read (to avoid overflows
    even with single floats) */
 #define MAXSIGDIG	30
@@ -237,7 +241,11 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
   return l_mathop(ldexp)(r, e);
 }
 
-#endif
+#endif					/* } */
+
+#endif					/* } */
+
+/* }====================================================== */
 
 
 int luaO_str2d (const char *s, size_t len, lua_Number *result) {

+ 18 - 7
loslib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: loslib.c,v 1.40 2012/10/19 15:54:02 roberto Exp roberto $
+** $Id: loslib.c,v 1.41 2013/05/14 15:57:11 roberto Exp roberto $
 ** Standard Operating System library
 ** See Copyright Notice in lua.h
 */
@@ -42,7 +42,10 @@
 ** By default, Lua uses tmpnam except when POSIX is available, where it
 ** uses mkstemp.
 */
-#if defined(LUA_USE_MKSTEMP)
+#if !defined(lua_tmpnam)	/* { */
+
+#if defined(LUA_USE_POSIX)	/* { */
+
 #include <unistd.h>
 #define LUA_TMPNAMBUFSIZE	32
 #define lua_tmpnam(b,e) { \
@@ -51,29 +54,37 @@
         if (e != -1) close(e); \
         e = (e == -1); }
 
-#elif !defined(lua_tmpnam)
+#else				/* }{ */
 
+/* ANSI definitions */
 #define LUA_TMPNAMBUFSIZE	L_tmpnam
 #define lua_tmpnam(b,e)		{ e = (tmpnam(b) == NULL); }
 
-#endif
+#endif				/* } */
+
+#endif				/* } */
 
 
 /*
 ** By default, Lua uses gmtime/localtime, except when POSIX is available,
 ** where it uses gmtime_r/localtime_r
 */
-#if defined(LUA_USE_GMTIME_R)
+#if !defined(l_gmtime)		/* { */
+
+#if defined(LUA_USE_POSIX)	/* { */
 
 #define l_gmtime(t,r)		gmtime_r(t,r)
 #define l_localtime(t,r)	localtime_r(t,r)
 
-#elif !defined(l_gmtime)
+#else				/* }{ */
 
+/* ANSI definitions */
 #define l_gmtime(t,r)		((void)r, gmtime(t))
 #define l_localtime(t,r)  	((void)r, localtime(t))
 
-#endif
+#endif				/* } */
+
+#endif				/* } */
 
 
 

+ 23 - 10
lua.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lua.c,v 1.208 2013/12/16 14:27:17 roberto Exp roberto $
+** $Id: lua.c,v 1.209 2014/02/05 14:22:55 roberto Exp roberto $
 ** Lua stand-alone interpreter
 ** See Copyright Notice in lua.h
 */
@@ -43,16 +43,26 @@
 ** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
 ** is, whether we're running lua interactively).
 */
-#if defined(LUA_USE_ISATTY)
+#if !defined(lua_stdin_is_tty)	/* { */
+
+#if defined(LUA_USE_POSIX)	/* { */
+
 #include <unistd.h>
 #define lua_stdin_is_tty()	isatty(0)
-#elif defined(LUA_WIN)
+
+#elif defined(LUA_WIN)		/* }{ */
+
 #include <io.h>
-#include <stdio.h>
 #define lua_stdin_is_tty()	_isatty(_fileno(stdin))
-#else
+
+#else				/* }{ */
+
+/* ANSI definition */
 #define lua_stdin_is_tty()	1  /* assume stdin is a tty */
-#endif
+
+#endif				/* } */
+
+#endif				/* } */
 
 
 /*
@@ -61,9 +71,10 @@
 ** lua_saveline defines how to "save" a read line in a "history".
 ** lua_freeline defines how to free a line read by lua_readline.
 */
-#if defined(LUA_USE_READLINE)
+#if !defined(lua_readline)	/* { */
+
+#if defined(LUA_USE_READLINE)	/* { */
 
-#include <stdio.h>
 #include <readline/readline.h>
 #include <readline/history.h>
 #define lua_readline(L,b,p)	((void)L, ((b)=readline(p)) != NULL)
@@ -72,7 +83,7 @@
           add_history(lua_tostring(L, idx));  /* add it to history */
 #define lua_freeline(L,b)	((void)L, free(b))
 
-#elif !defined(lua_readline)
+#else				/* }{ */
 
 #define lua_readline(L,b,p) \
         ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
@@ -80,7 +91,9 @@
 #define lua_saveline(L,idx)	{ (void)L; (void)idx; }
 #define lua_freeline(L,b)	{ (void)L; (void)b; }
 
-#endif
+#endif				/* } */
+
+#endif				/* } */
 
 
 

+ 13 - 13
luaconf.h

@@ -1,5 +1,5 @@
 /*
-** $Id: luaconf.h,v 1.188 2013/11/21 17:23:14 roberto Exp roberto $
+** $Id: luaconf.h,v 1.189 2014/01/27 13:34:32 roberto Exp roberto $
 ** Configuration file for Lua
 ** See Copyright Notice in lua.h
 */
@@ -41,24 +41,28 @@
 
 
 #if defined(LUA_USE_LINUX)
+#define LUA_USE_C99
 #define LUA_USE_POSIX
 #define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
 #define LUA_USE_READLINE	/* needs some extra libraries */
-#define LUA_USE_STRTODHEX	/* assume 'strtod' handles hex formats */
-#define LUA_USE_AFORMAT		/* assume 'printf' handles 'aA' specifiers */
-#define LUA_USE_LONGLONG	/* assume support for long long */
 #endif
 
 #if defined(LUA_USE_MACOSX)
+#define LUA_USE_C99
 #define LUA_USE_POSIX
 #define LUA_USE_DLOPEN		/* does not need -ldl */
 #define LUA_USE_READLINE	/* needs an extra library: -lreadline */
-#define LUA_USE_STRTODHEX	/* assume 'strtod' handles hex formats */
-#define LUA_USE_AFORMAT		/* assume 'printf' handles 'aA' specifiers */
-#define LUA_USE_LONGLONG	/* assume support for long long */
 #endif
 
 
+/*
+@@ LUA_USE_C99 includes all functionality from C 99.
+** CHANGE it (define it) if your system is compatible.
+*/
+#if defined(LUA_USE_C99)
+#define LUA_USE_AFORMAT		/* assume 'printf' handles 'aA' specifiers */
+#endif
+
 
 /*
 @@ LUA_USE_POSIX includes all functionality listed as X/Open System
@@ -66,11 +70,6 @@
 ** CHANGE it (define it) if your system is XSI compatible.
 */
 #if defined(LUA_USE_POSIX)
-#define LUA_USE_MKSTEMP
-#define LUA_USE_ISATTY
-#define LUA_USE_POPEN
-#define LUA_USE_ULONGJMP
-#define LUA_USE_GMTIME_R
 #endif
 
 
@@ -381,7 +380,8 @@
 ** The following definitions set the numeric types for Lua.
 ** Lua should work fine with 32-bit or 64-bit integers mixed with
 ** 32-bit or 64-bit floats. The usual configurations are 64-bit
-** integers and floats (the default) and 32-bit integers and floats.
+** integers and floats (the default) and 32-bit integers and floats
+** (for restricted hardware).
 ** ===================================================================
 */