aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-26 12:27:56 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-26 12:27:56 -0300
commitc6c41e85b2992bba41cac23ac8bab32e29553e84 (patch)
treed48b427016446604131f730f016bceb90463777d
parent87c930676f4aef54054024b73a245a24747aa163 (diff)
downloadlua-c6c41e85b2992bba41cac23ac8bab32e29553e84.tar.gz
lua-c6c41e85b2992bba41cac23ac8bab32e29553e84.tar.bz2
lua-c6c41e85b2992bba41cac23ac8bab32e29553e84.zip
more uniformity for defining system-dependent features
-rw-r--r--ldo.c21
-rw-r--r--liolib.c41
-rw-r--r--lobject.c20
-rw-r--r--loslib.c25
-rw-r--r--lua.c33
-rw-r--r--luaconf.h26
6 files changed, 101 insertions, 65 deletions
diff --git a/ldo.c b/ldo.c
index 3440e3f9..22d1f0b3 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.112 2013/11/08 18:16:33 roberto Exp roberto $ 2** $Id: ldo.c,v 2.113 2014/02/15 13:12:01 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -46,30 +46,33 @@
46** C++ code, with _longjmp/_setjmp when asked to use them, and with 46** C++ code, with _longjmp/_setjmp when asked to use them, and with
47** longjmp/setjmp otherwise. 47** longjmp/setjmp otherwise.
48*/ 48*/
49#if !defined(LUAI_THROW) 49#if !defined(LUAI_THROW) /* { */
50
51#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP) /* { */
50 52
51#if defined(__cplusplus) && !defined(LUA_USE_LONGJMP)
52/* C++ exceptions */ 53/* C++ exceptions */
53#define LUAI_THROW(L,c) throw(c) 54#define LUAI_THROW(L,c) throw(c)
54#define LUAI_TRY(L,c,a) \ 55#define LUAI_TRY(L,c,a) \
55 try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; } 56 try { a } catch(...) { if ((c)->status == 0) (c)->status = -1; }
56#define luai_jmpbuf int /* dummy variable */ 57#define luai_jmpbuf int /* dummy variable */
57 58
58#elif defined(LUA_USE_ULONGJMP) 59#elif defined(LUA_USE_POSIX) /* }{ */
59/* in Unix, try _longjmp/_setjmp (more efficient) */ 60
61/* in Posix, try _longjmp/_setjmp (more efficient) */
60#define LUAI_THROW(L,c) _longjmp((c)->b, 1) 62#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
61#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } 63#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
62#define luai_jmpbuf jmp_buf 64#define luai_jmpbuf jmp_buf
63 65
64#else 66#else /* }{ */
65/* default handling with long jumps */ 67
68/* ANSI handling with long jumps */
66#define LUAI_THROW(L,c) longjmp((c)->b, 1) 69#define LUAI_THROW(L,c) longjmp((c)->b, 1)
67#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } 70#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
68#define luai_jmpbuf jmp_buf 71#define luai_jmpbuf jmp_buf
69 72
70#endif 73#endif /* } */
71 74
72#endif 75#endif /* } */
73 76
74 77
75 78
diff --git a/liolib.c b/liolib.c
index fddbf0cc..88be99ec 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.115 2014/01/27 13:28:45 roberto Exp roberto $ 2** $Id: liolib.c,v 2.116 2014/02/21 14:39:50 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -51,29 +51,30 @@
51** ======================================================= 51** =======================================================
52*/ 52*/
53 53
54#if !defined(lua_popen) /* { */ 54#if !defined(lua_popen) /* { */
55 55
56#if defined(LUA_USE_POPEN) /* { */ 56#if defined(LUA_USE_POSIX) /* { */
57 57
58#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) 58#define lua_popen(L,c,m) (fflush(NULL), popen(c,m))
59#define lua_pclose(L,file) ((void)L, pclose(file)) 59#define lua_pclose(L,file) (pclose(file))
60 60
61#elif defined(LUA_WIN) /* }{ */ 61#elif defined(LUA_WIN) /* }{ */
62 62
63#define lua_popen(L,c,m) ((void)L, _popen(c,m)) 63#define lua_popen(L,c,m) (_popen(c,m))
64#define lua_pclose(L,file) ((void)L, _pclose(file)) 64#define lua_pclose(L,file) (_pclose(file))
65
66 65
67#else /* }{ */ 66#else /* }{ */
68 67
69#define lua_popen(L,c,m) ((void)((void)c, m), \ 68/* ANSI definitions */
70 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) 69#define lua_popen(L,c,m) \
70 ((void)((void)c, m), \
71 luaL_error(L, LUA_QL("popen") " not supported"), \
72 (FILE*)0)
71#define lua_pclose(L,file) ((void)((void)L, file), -1) 73#define lua_pclose(L,file) ((void)((void)L, file), -1)
72 74
73
74#endif /* } */ 75#endif /* } */
75 76
76#endif /* } */ 77#endif /* } */
77 78
78/* }====================================================== */ 79/* }====================================================== */
79 80
@@ -84,7 +85,7 @@
84** ======================================================= 85** =======================================================
85*/ 86*/
86 87
87#if !defined(lua_fseek) && !defined(LUA_ANSI) /* { */ 88#if !defined(lua_fseek) /* { */
88 89
89#if defined(LUA_USE_POSIX) /* { */ 90#if defined(LUA_USE_POSIX) /* { */
90 91
@@ -94,22 +95,22 @@
94 95
95#elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \ 96#elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
96 && defined(_MSC_VER) && (_MSC_VER >= 1400) /* }{ */ 97 && defined(_MSC_VER) && (_MSC_VER >= 1400) /* }{ */
97/* Windows (but not DDK) and Visual C++ 2005 or higher */
98 98
99/* Windows (but not DDK) and Visual C++ 2005 or higher */
99#define l_fseek(f,o,w) _fseeki64(f,o,w) 100#define l_fseek(f,o,w) _fseeki64(f,o,w)
100#define l_ftell(f) _ftelli64(f) 101#define l_ftell(f) _ftelli64(f)
101#define l_seeknum __int64 102#define l_seeknum __int64
102 103
103#endif /* } */ 104#else /* }{ */
104
105#endif /* } */
106
107 105
108#if !defined(l_fseek) /* default definitions */ 106/* ANSI definitions */
109#define l_fseek(f,o,w) fseek(f,o,w) 107#define l_fseek(f,o,w) fseek(f,o,w)
110#define l_ftell(f) ftell(f) 108#define l_ftell(f) ftell(f)
111#define l_seeknum long 109#define l_seeknum long
112#endif 110
111#endif /* } */
112
113#endif /* } */
113 114
114/* }====================================================== */ 115/* }====================================================== */
115 116
diff --git a/lobject.c b/lobject.c
index 90e7d71a..66027585 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.72 2014/01/27 13:34:32 roberto Exp roberto $ 2** $Id: lobject.c,v 2.73 2014/02/06 15:59:24 roberto Exp $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -159,22 +159,26 @@ static int isneg (const char **s) {
159 159
160 160
161/* 161/*
162** {======================================================
162** lua_strx2number converts an hexadecimal numeric string to a number. 163** lua_strx2number converts an hexadecimal numeric string to a number.
163** In C99, 'strtod' does both conversions. C89, however, has no function 164** In C99, 'strtod' does both conversions. C89, however, has no function
164** to convert floating hexadecimal strings to numbers. For these 165** to convert floating hexadecimal strings to numbers. For these
165** systems, you can leave 'lua_strx2number' undefined and Lua will 166** systems, you can leave 'lua_strx2number' undefined and Lua will
166** provide its own implementation. 167** provide its own implementation.
168** =======================================================
167*/ 169*/
168#if defined(LUA_USE_STRTODHEX) 170#if !defined(lua_strx2number) /* { */
171
172#if defined(LUA_USE_C99) /* { */
173
169#define lua_strx2number(s,p) lua_str2number(s,p) 174#define lua_strx2number(s,p) lua_str2number(s,p)
170#endif
171 175
176#else /* }{ */
172 177
173#if !defined(lua_strx2number) 178/* Lua's implementation for 'lua_strx2number' */
174 179
175#include <math.h> 180#include <math.h>
176 181
177
178/* maximum number of significant digits to read (to avoid overflows 182/* maximum number of significant digits to read (to avoid overflows
179 even with single floats) */ 183 even with single floats) */
180#define MAXSIGDIG 30 184#define MAXSIGDIG 30
@@ -237,7 +241,11 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
237 return l_mathop(ldexp)(r, e); 241 return l_mathop(ldexp)(r, e);
238} 242}
239 243
240#endif 244#endif /* } */
245
246#endif /* } */
247
248/* }====================================================== */
241 249
242 250
243int luaO_str2d (const char *s, size_t len, lua_Number *result) { 251int luaO_str2d (const char *s, size_t len, lua_Number *result) {
diff --git a/loslib.c b/loslib.c
index 22f9ea43..7282c1cb 100644
--- a/loslib.c
+++ b/loslib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loslib.c,v 1.40 2012/10/19 15:54:02 roberto Exp roberto $ 2** $Id: loslib.c,v 1.41 2013/05/14 15:57:11 roberto Exp roberto $
3** Standard Operating System library 3** Standard Operating System library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -42,7 +42,10 @@
42** By default, Lua uses tmpnam except when POSIX is available, where it 42** By default, Lua uses tmpnam except when POSIX is available, where it
43** uses mkstemp. 43** uses mkstemp.
44*/ 44*/
45#if defined(LUA_USE_MKSTEMP) 45#if !defined(lua_tmpnam) /* { */
46
47#if defined(LUA_USE_POSIX) /* { */
48
46#include <unistd.h> 49#include <unistd.h>
47#define LUA_TMPNAMBUFSIZE 32 50#define LUA_TMPNAMBUFSIZE 32
48#define lua_tmpnam(b,e) { \ 51#define lua_tmpnam(b,e) { \
@@ -51,29 +54,37 @@
51 if (e != -1) close(e); \ 54 if (e != -1) close(e); \
52 e = (e == -1); } 55 e = (e == -1); }
53 56
54#elif !defined(lua_tmpnam) 57#else /* }{ */
55 58
59/* ANSI definitions */
56#define LUA_TMPNAMBUFSIZE L_tmpnam 60#define LUA_TMPNAMBUFSIZE L_tmpnam
57#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } 61#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
58 62
59#endif 63#endif /* } */
64
65#endif /* } */
60 66
61 67
62/* 68/*
63** By default, Lua uses gmtime/localtime, except when POSIX is available, 69** By default, Lua uses gmtime/localtime, except when POSIX is available,
64** where it uses gmtime_r/localtime_r 70** where it uses gmtime_r/localtime_r
65*/ 71*/
66#if defined(LUA_USE_GMTIME_R) 72#if !defined(l_gmtime) /* { */
73
74#if defined(LUA_USE_POSIX) /* { */
67 75
68#define l_gmtime(t,r) gmtime_r(t,r) 76#define l_gmtime(t,r) gmtime_r(t,r)
69#define l_localtime(t,r) localtime_r(t,r) 77#define l_localtime(t,r) localtime_r(t,r)
70 78
71#elif !defined(l_gmtime) 79#else /* }{ */
72 80
81/* ANSI definitions */
73#define l_gmtime(t,r) ((void)r, gmtime(t)) 82#define l_gmtime(t,r) ((void)r, gmtime(t))
74#define l_localtime(t,r) ((void)r, localtime(t)) 83#define l_localtime(t,r) ((void)r, localtime(t))
75 84
76#endif 85#endif /* } */
86
87#endif /* } */
77 88
78 89
79 90
diff --git a/lua.c b/lua.c
index e0ca0669..dfb5d1d1 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.208 2013/12/16 14:27:17 roberto Exp roberto $ 2** $Id: lua.c,v 1.209 2014/02/05 14:22:55 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -43,16 +43,26 @@
43** lua_stdin_is_tty detects whether the standard input is a 'tty' (that 43** lua_stdin_is_tty detects whether the standard input is a 'tty' (that
44** is, whether we're running lua interactively). 44** is, whether we're running lua interactively).
45*/ 45*/
46#if defined(LUA_USE_ISATTY) 46#if !defined(lua_stdin_is_tty) /* { */
47
48#if defined(LUA_USE_POSIX) /* { */
49
47#include <unistd.h> 50#include <unistd.h>
48#define lua_stdin_is_tty() isatty(0) 51#define lua_stdin_is_tty() isatty(0)
49#elif defined(LUA_WIN) 52
53#elif defined(LUA_WIN) /* }{ */
54
50#include <io.h> 55#include <io.h>
51#include <stdio.h>
52#define lua_stdin_is_tty() _isatty(_fileno(stdin)) 56#define lua_stdin_is_tty() _isatty(_fileno(stdin))
53#else 57
58#else /* }{ */
59
60/* ANSI definition */
54#define lua_stdin_is_tty() 1 /* assume stdin is a tty */ 61#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
55#endif 62
63#endif /* } */
64
65#endif /* } */
56 66
57 67
58/* 68/*
@@ -61,9 +71,10 @@
61** lua_saveline defines how to "save" a read line in a "history". 71** lua_saveline defines how to "save" a read line in a "history".
62** lua_freeline defines how to free a line read by lua_readline. 72** lua_freeline defines how to free a line read by lua_readline.
63*/ 73*/
64#if defined(LUA_USE_READLINE) 74#if !defined(lua_readline) /* { */
75
76#if defined(LUA_USE_READLINE) /* { */
65 77
66#include <stdio.h>
67#include <readline/readline.h> 78#include <readline/readline.h>
68#include <readline/history.h> 79#include <readline/history.h>
69#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL) 80#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
@@ -72,7 +83,7 @@
72 add_history(lua_tostring(L, idx)); /* add it to history */ 83 add_history(lua_tostring(L, idx)); /* add it to history */
73#define lua_freeline(L,b) ((void)L, free(b)) 84#define lua_freeline(L,b) ((void)L, free(b))
74 85
75#elif !defined(lua_readline) 86#else /* }{ */
76 87
77#define lua_readline(L,b,p) \ 88#define lua_readline(L,b,p) \
78 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \ 89 ((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
@@ -80,7 +91,9 @@
80#define lua_saveline(L,idx) { (void)L; (void)idx; } 91#define lua_saveline(L,idx) { (void)L; (void)idx; }
81#define lua_freeline(L,b) { (void)L; (void)b; } 92#define lua_freeline(L,b) { (void)L; (void)b; }
82 93
83#endif 94#endif /* } */
95
96#endif /* } */
84 97
85 98
86 99
diff --git a/luaconf.h b/luaconf.h
index 39293e29..5b579bbf 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.188 2013/11/21 17:23:14 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.189 2014/01/27 13:34:32 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -41,24 +41,28 @@
41 41
42 42
43#if defined(LUA_USE_LINUX) 43#if defined(LUA_USE_LINUX)
44#define LUA_USE_C99
44#define LUA_USE_POSIX 45#define LUA_USE_POSIX
45#define LUA_USE_DLOPEN /* needs an extra library: -ldl */ 46#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
46#define LUA_USE_READLINE /* needs some extra libraries */ 47#define LUA_USE_READLINE /* needs some extra libraries */
47#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
48#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
49#define LUA_USE_LONGLONG /* assume support for long long */
50#endif 48#endif
51 49
52#if defined(LUA_USE_MACOSX) 50#if defined(LUA_USE_MACOSX)
51#define LUA_USE_C99
53#define LUA_USE_POSIX 52#define LUA_USE_POSIX
54#define LUA_USE_DLOPEN /* does not need -ldl */ 53#define LUA_USE_DLOPEN /* does not need -ldl */
55#define LUA_USE_READLINE /* needs an extra library: -lreadline */ 54#define LUA_USE_READLINE /* needs an extra library: -lreadline */
56#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
57#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
58#define LUA_USE_LONGLONG /* assume support for long long */
59#endif 55#endif
60 56
61 57
58/*
59@@ LUA_USE_C99 includes all functionality from C 99.
60** CHANGE it (define it) if your system is compatible.
61*/
62#if defined(LUA_USE_C99)
63#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
64#endif
65
62 66
63/* 67/*
64@@ LUA_USE_POSIX includes all functionality listed as X/Open System 68@@ LUA_USE_POSIX includes all functionality listed as X/Open System
@@ -66,11 +70,6 @@
66** CHANGE it (define it) if your system is XSI compatible. 70** CHANGE it (define it) if your system is XSI compatible.
67*/ 71*/
68#if defined(LUA_USE_POSIX) 72#if defined(LUA_USE_POSIX)
69#define LUA_USE_MKSTEMP
70#define LUA_USE_ISATTY
71#define LUA_USE_POPEN
72#define LUA_USE_ULONGJMP
73#define LUA_USE_GMTIME_R
74#endif 73#endif
75 74
76 75
@@ -381,7 +380,8 @@
381** The following definitions set the numeric types for Lua. 380** The following definitions set the numeric types for Lua.
382** Lua should work fine with 32-bit or 64-bit integers mixed with 381** Lua should work fine with 32-bit or 64-bit integers mixed with
383** 32-bit or 64-bit floats. The usual configurations are 64-bit 382** 32-bit or 64-bit floats. The usual configurations are 64-bit
384** integers and floats (the default) and 32-bit integers and floats. 383** integers and floats (the default) and 32-bit integers and floats
384** (for restricted hardware).
385** =================================================================== 385** ===================================================================
386*/ 386*/
387 387