]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/lua/lib/contrib/src/luaconf_internal.h
update
[l4.git] / l4 / pkg / lua / lib / contrib / src / luaconf_internal.h
1 /*
2 ** $Id: luaconf_internal.h,v ... $
3 ** Configuration file for Lua (internal)
4 ** See Copyright Notice in lua.h
5 */
6
7
8 #ifndef lconfig_internal_h
9 #define lconfig_internal_h
10
11 #ifdef lua_assert
12 # include <assert.h>
13 #endif
14
15 /*
16 ** ==================================================================
17 ** Search for "@@" to find all configurable definitions.
18 ** ===================================================================
19 */
20
21
22 /*
23 @@ LUA_ANSI controls the use of non-ansi features.
24 ** CHANGE it (define it) if you want Lua to avoid the use of any
25 ** non-ansi feature or library.
26 */
27 #if defined(__STRICT_ANSI__)
28 #define LUA_ANSI
29 #endif
30
31
32 #if !defined(LUA_ANSI) && defined(_WIN32)
33 #define LUA_WIN
34 #endif
35
36 #if defined(LUA_USE_LINUX)
37 #define LUA_USE_POSIX
38 #define LUA_USE_DLOPEN          /* needs an extra library: -ldl */
39 #define LUA_USE_READLINE        /* needs some extra libraries */
40 #endif
41
42 #if defined(LUA_USE_MACOSX)
43 #define LUA_USE_POSIX
44 #define LUA_DL_DYLD             /* does not need extra library */
45 #endif
46
47
48
49 /*
50 @@ LUA_USE_POSIX includes all functionallity listed as X/Open System
51 @* Interfaces Extension (XSI).
52 ** CHANGE it (define it) if your system is XSI compatible.
53 */
54 #if defined(LUA_USE_POSIX)
55 #define LUA_USE_MKSTEMP
56 #define LUA_USE_ISATTY
57 #define LUA_USE_POPEN
58 #define LUA_USE_ULONGJMP
59 #endif
60
61
62 /*
63 @@ LUA_DIRSEP is the directory separator (for submodules).
64 ** CHANGE it if your machine does not use "/" as the directory separator
65 ** and is not Windows. (On Windows Lua automatically uses "\".)
66 */
67 #if defined(_WIN32)
68 #define LUA_DIRSEP      "\\"
69 #else
70 #define LUA_DIRSEP      "/"
71 #endif
72
73
74 /*
75 @@ LUA_PATHSEP is the character that separates templates in a path.
76 @@ LUA_PATH_MARK is the string that marks the substitution points in a
77 @* template.
78 @@ LUA_EXECDIR in a Windows path is replaced by the executable's
79 @* directory.
80 @@ LUA_IGMARK is a mark to ignore all before it when bulding the
81 @* luaopen_ function name.
82 ** CHANGE them if for some reason your system cannot use those
83 ** characters. (E.g., if one of those characters is a common character
84 ** in file/directory names.) Probably you do not need to change them.
85 */
86 #define LUA_PATHSEP     ";"
87 #define LUA_PATH_MARK   "?"
88 #define LUA_EXECDIR     "!"
89 #define LUA_IGMARK      "-"
90
91
92 /*
93 ** Default number mode
94 */
95 #if (!defined LNUM_DOUBLE) && (!defined LNUM_FLOAT) && (!defined LNUM_LDOUBLE)
96 # define LNUM_DOUBLE
97 #endif
98
99 /*
100 ** Require C99 mode for COMPLEX, FLOAT and LDOUBLE (only DOUBLE is ANSI C).
101 */
102 #if defined(LNUM_COMPLEX) && (__STDC_VERSION__ < 199901L)
103 # error "Need C99 for complex (use '--std=c99' or similar)"
104 #elif defined(LNUM_LDOUBLE) && (__STDC_VERSION__ < 199901L) && !defined(_MSC_VER)
105 # error "Need C99 for 'long double' (use '--std=c99' or similar)"
106 #elif defined(LNUM_FLOAT) && (__STDC_VERSION__ < 199901L)
107 /* LNUM_FLOAT not supported on Windows */
108 # error "Need C99 for 'float' (use '--std=c99' or similar)"
109 #endif
110
111 /*
112 ** COMPLEX mode currently only with integer optimization
113 */
114 #if defined(LNUM_COMPLEX) && !(defined(LNUM_INT32) || defined(LNUM_INT64))
115 # error "LNUM_COMPLEX needs to be used together with LNUM_INTxx"
116 #endif
117  
118 /*
119 ** Number mode identifier to accompany the version string.
120 */
121 #ifdef LNUM_COMPLEX
122 # define _LNUM1 "complex "
123 #else
124 # define _LNUM1 ""
125 #endif
126 #ifdef LNUM_DOUBLE
127 # define _LNUM2 "double"
128 #elif defined(LNUM_FLOAT)
129 # define _LNUM2 "float"
130 #elif defined(LNUM_LDOUBLE)
131 # define _LNUM2 "ldouble"
132 #endif
133 #ifdef LNUM_INT32
134 # define _LNUM3 " int32"
135 #elif defined(LNUM_INT64)
136 # define _LNUM3 " int64"
137 #else
138 # define _LNUM3 ""
139 #endif
140 #ifdef __FAST_MATH__
141 # define _LNUM4 "fastmath"
142 #else
143 # define _LNUM4 ""
144 #endif
145 #define LUA_LNUM _LNUM1 _LNUM2 _LNUM3 _LNUM4
146
147
148 /* 
149 ** LUAI_MAXNUMBER2STR: size of a buffer fitting any number->string result.
150 **
151 **  double:  24 (sign, x.xxxxxxxxxxxxxxe+nnnn, and \0)
152 **  int64:   21 (19 digits, sign, and \0)
153 **  long double: 43 for 128-bit (sign, x.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxe+nnnn, and \0)
154 **           30 for 80-bit (sign, x.xxxxxxxxxxxxxxxxxxxxe+nnnn, and \0)
155 */
156 #ifdef LNUM_LDOUBLE
157 # define _LUAI_MN2S 44
158 #else
159 # define _LUAI_MN2S 24
160 #endif
161
162 #ifdef LNUM_COMPLEX
163 # define LUAI_MAXNUMBER2STR (2*_LUAI_MN2S)
164 #else
165 # define LUAI_MAXNUMBER2STR _LUAI_MN2S
166 #endif
167
168 /*
169 @@ lua_number2int is a macro to convert lua_Number to int.
170 @@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
171 ** CHANGE them if you know a faster way to convert a lua_Number to
172 ** int (with any rounding method and without throwing errors) in your
173 ** system. In Pentium machines, a naive typecast from double to int
174 ** in C is extremely slow, so any alternative is worth trying.
175 **
176 ** Note: Using '-msse' or '-msse3' is highly recommended for newer x86
177 **      processors. They have fast instructions to bypass the Pentium FP->int
178 **      efficiency problem altogether.  --AKa 6-Apr-2009
179 */
180
181 /* On old Pentium (SSE not enabled), resort to a trick */
182 #if defined(LNUM_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
183     (defined(__i386) || defined (_M_IX86) || defined(__i386__))
184
185 /* On a Microsoft compiler, use assembler */
186 # if defined(_MSC_VER)
187 #  define lua_number2int(i,d)   __asm fld d   __asm fistp i
188 # else
189
190 /* the next trick should work on any Pentium, but sometimes clashes
191    with a DirectX idiosyncrasy */
192 union luai_Cast { double l_d; long l_l; };
193 #  define lua_number2int(i,d) \
194   { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
195 # endif
196
197 # ifndef LNUM_INT64
198 #  define lua_number2integer    lua_number2int
199 # endif
200
201 /* this option always works (and is fast on most platforms) */
202 #else
203 # define lua_number2int(i,d)        ((i)=(int)(d))
204 #endif
205
206 /* Note: Some compilers (OS X gcc 4.0?) may choke on double->long long conversion 
207  *       since it can lose precision. Others do require 'long long' there.  
208  */
209 #ifndef lua_number2integer
210 # define lua_number2integer(i,d)    ((i)=(lua_Integer)(d))
211 #endif
212
213 /*
214 ** 'luai_abs()' to give absolute value of 'lua_Integer'
215 */
216 #ifdef LNUM_INT64
217 # if (__STDC_VERSION__ >= 199901L)
218 #  define luai_abs llabs
219 # else
220 #  define luai_abs(v) ((v) >= 0 ? (v) : -(v))
221 # endif
222 #else
223 # define luai_abs abs
224 #endif
225
226 /*
227 ** LUAI_UACNUMBER is the result of an 'usual argument conversion' over a number.
228 ** LUAI_UACINTEGER the same, over an integer.
229 */
230 #define LUAI_UACNUMBER  double
231 #define LUAI_UACINTEGER long
232
233 /* ANSI C only has math funcs for 'double. C99 required for float and long double
234  * variants.
235  */
236 #ifdef LNUM_DOUBLE
237 # define _LF(name) name
238 #elif defined(LNUM_FLOAT)
239 # define _LF(name) name ## f
240 #elif defined(LNUM_LDOUBLE)
241 # define _LF(name) name ## l
242 #endif
243
244
245 /*
246 @@ LUAI_FUNC is a mark for all extern functions that are not to be
247 @* exported to outside modules.
248 @@ LUAI_DATA is a mark for all extern (const) variables that are not to
249 @* be exported to outside modules.
250 ** CHANGE them if you need to mark them in some special way. Elf/gcc
251 ** (versions 3.2 and later) mark them as "hidden" to optimize access
252 ** when Lua is compiled as a shared library.
253 */
254 #if defined(luaall_c)
255 #define LUAI_FUNC       static
256 #define LUAI_DATA       /* empty */
257
258 #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
259       defined(__ELF__)
260 #define LUAI_FUNC       __attribute__((visibility("hidden"))) extern
261 #define LUAI_DATA       LUAI_FUNC
262
263 #else
264 #define LUAI_FUNC       extern
265 #define LUAI_DATA       extern
266 #endif
267
268
269
270 /*
271 @@ LUA_QL describes how error messages quote program elements.
272 ** CHANGE it if you want a different appearance.
273 */
274 #define LUA_QL(x)       "'" x "'"
275 #define LUA_QS          LUA_QL("%s")
276
277
278 /*
279 ** {==================================================================
280 ** Stand-alone configuration
281 ** ===================================================================
282 */
283
284 #if defined(lua_c) || defined(luaall_c)
285
286 /*
287 @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
288 @* is, whether we're running lua interactively).
289 ** CHANGE it if you have a better definition for non-POSIX/non-Windows
290 ** systems.
291 */
292 #if defined(LUA_USE_ISATTY)
293 #include <unistd.h>
294 #define lua_stdin_is_tty()      isatty(0)
295 #elif defined(LUA_WIN)
296 #include <io.h>
297 #include <stdio.h>
298 #define lua_stdin_is_tty()      _isatty(_fileno(stdin))
299 #else
300 #define lua_stdin_is_tty()      1  /* assume stdin is a tty */
301 #endif
302
303
304 /*
305 @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
306 @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
307 ** CHANGE them if you want different prompts. (You can also change the
308 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
309 */
310 #define LUA_PROMPT              "> "
311 #define LUA_PROMPT2             ">> "
312
313
314 /*
315 @@ LUA_PROGNAME is the default name for the stand-alone Lua program.
316 ** CHANGE it if your stand-alone interpreter has a different name and
317 ** your system is not able to detect that name automatically.
318 */
319 #define LUA_PROGNAME            "lua"
320
321
322 /*
323 @@ LUA_MAXINPUT is the maximum length for an input line in the
324 @* stand-alone interpreter.
325 ** CHANGE it if you need longer lines.
326 */
327 #define LUA_MAXINPUT    512
328
329
330 /*
331 @@ lua_readline defines how to show a prompt and then read a line from
332 @* the standard input.
333 @@ lua_saveline defines how to "save" a read line in a "history".
334 @@ lua_freeline defines how to free a line read by lua_readline.
335 ** CHANGE them if you want to improve this functionality (e.g., by using
336 ** GNU readline and history facilities).
337 */
338 #if defined(LUA_USE_READLINE)
339 #include <stdio.h>
340 #include <readline/readline.h>
341 #include <readline/history.h>
342 #define lua_readline(L,b,p)     ((void)L, ((b)=readline(p)) != NULL)
343 #define lua_saveline(L,idx) \
344         if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
345           add_history(lua_tostring(L, idx));  /* add it to history */
346 #define lua_freeline(L,b)       ((void)L, free(b))
347 #else
348 #define lua_readline(L,b,p)     \
349         ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
350         fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */
351 #define lua_saveline(L,idx)     { (void)L; (void)idx; }
352 #define lua_freeline(L,b)       { (void)L; (void)b; }
353 #endif
354
355 #endif
356
357 /* }================================================================== */
358
359
360 /*
361 @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
362 @* as a percentage.
363 ** CHANGE it if you want the GC to run faster or slower (higher values
364 ** mean larger pauses which mean slower collection.) You can also change
365 ** this value dynamically.
366 */
367 #define LUAI_GCPAUSE    200  /* 200% (wait memory to double before next GC) */
368
369
370 /*
371 @@ LUAI_GCMUL defines the default speed of garbage collection relative to
372 @* memory allocation as a percentage.
373 ** CHANGE it if you want to change the granularity of the garbage
374 ** collection. (Higher values mean coarser collections. 0 represents
375 ** infinity, where each step performs a full collection.) You can also
376 ** change this value dynamically.
377 */
378 #define LUAI_GCMUL      200 /* GC runs 'twice the speed' of memory allocation */
379
380
381 /*
382 @@ luai_apicheck is the assert macro used by the Lua-C API.
383 ** CHANGE luai_apicheck if you want Lua to perform some checks in the
384 ** parameters it gets from API calls. This may slow down the interpreter
385 ** a bit, but may be quite useful when debugging C code that interfaces
386 ** with Lua. A useful redefinition is to use assert.h.
387 */
388 #if defined(LUA_USE_APICHECK)
389 #include <assert.h>
390 #define luai_apicheck(L,o)      { (void)L; assert(o); }
391 #else
392 #define luai_apicheck(L,o)      { (void)L; }
393 #endif
394
395
396 /*
397 @@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
398 @@ LUAI_INT32 is an signed integer with at least 32 bits.
399 @@ LUAI_UMEM is an unsigned integer big enough to count the total
400 @* memory used by Lua.
401 @@ LUAI_MEM is a signed integer big enough to count the total memory
402 @* used by Lua.
403 ** CHANGE here if for some weird reason the default definitions are not
404 ** good enough for your machine. (The definitions in the 'else'
405 ** part always works, but may waste space on machines with 64-bit
406 ** longs.) Probably you do not need to change this.
407 */
408 #if LUAI_BITSINT >= 32
409 #define LUAI_UINT32     unsigned int
410 #define LUAI_INT32      int
411 #define LUAI_MAXINT32   INT_MAX
412 #define LUAI_UMEM       size_t
413 #define LUAI_MEM        ptrdiff_t
414 #else
415 /* 16-bit ints */
416 #define LUAI_UINT32     unsigned long
417 #define LUAI_INT32      long
418 #define LUAI_MAXINT32   LONG_MAX
419 #define LUAI_UMEM       unsigned long
420 #define LUAI_MEM        long
421 #endif
422
423 /*
424 @@ LUAI_MAXCALLS limits the number of nested calls.
425 ** CHANGE it if you need really deep recursive calls. This limit is
426 ** arbitrary; its only purpose is to stop infinite recursion before
427 ** exhausting memory.
428 */
429 #define LUAI_MAXCALLS   20000
430
431
432 /*
433 @@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
434 @* can use.
435 ** CHANGE it if you need lots of (Lua) stack space for your C
436 ** functions. This limit is arbitrary; its only purpose is to stop C
437 ** functions to consume unlimited stack space. (must be smaller than
438 ** -LUA_REGISTRYINDEX)
439 */
440 #define LUAI_MAXCSTACK  8000
441
442
443
444 /*
445 ** {==================================================================
446 ** CHANGE (to smaller values) the following definitions if your system
447 ** has a small C stack. (Or you may want to change them to larger
448 ** values if your system has a large C stack and these limits are
449 ** too rigid for you.) Some of these constants control the size of
450 ** stack-allocated arrays used by the compiler or the interpreter, while
451 ** others limit the maximum number of recursive calls that the compiler
452 ** or the interpreter can perform. Values too large may cause a C stack
453 ** overflow for some forms of deep constructs.
454 ** ===================================================================
455 */
456
457
458 /*
459 @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
460 @* syntactical nested non-terminals in a program.
461 */
462 #define LUAI_MAXCCALLS          200
463
464
465 /*
466 @@ LUAI_MAXVARS is the maximum number of local variables per function
467 @* (must be smaller than 250).
468 */
469 #define LUAI_MAXVARS            200
470
471
472 /*
473 @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
474 @* (must be smaller than 250).
475 */
476 #define LUAI_MAXUPVALUES        60
477
478
479 /* }================================================================== */
480
481
482 /*
483 @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
484 */
485 #define LUAI_USER_ALIGNMENT_T   union { LUA_NUMBER u; void *s; long l; }
486
487
488 /*
489 @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
490 ** CHANGE them if you prefer to use longjmp/setjmp even with C++
491 ** or if want/don't to use _longjmp/_setjmp instead of regular
492 ** longjmp/setjmp. By default, Lua handles errors with exceptions when
493 ** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
494 ** and with longjmp/setjmp otherwise.
495 */
496 #if defined(__cplusplus)
497 /* C++ exceptions */
498 #define LUAI_THROW(L,c) throw(c)
499 #define LUAI_TRY(L,c,a) try { a } catch(...) \
500         { if ((c)->status == 0) (c)->status = -1; }
501 #define luai_jmpbuf     int  /* dummy variable */
502
503 #elif defined(LUA_USE_ULONGJMP)
504 /* in Unix, try _longjmp/_setjmp (more efficient) */
505 #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
506 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
507 #define luai_jmpbuf     jmp_buf
508
509 #else
510 /* default handling with long jumps */
511 #define LUAI_THROW(L,c) longjmp((c)->b, 1)
512 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
513 #define luai_jmpbuf     jmp_buf
514
515 #endif
516
517
518 /*
519 @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
520 @* can do during pattern-matching.
521 ** CHANGE it if you need more captures. This limit is arbitrary.
522 */
523 #define LUA_MAXCAPTURES         32
524
525
526 /*
527 @@ lua_tmpnam is the function that the OS library uses to create a
528 @* temporary name.
529 @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
530 ** CHANGE them if you have an alternative to tmpnam (which is considered
531 ** insecure) or if you want the original tmpnam anyway.  By default, Lua
532 ** uses tmpnam except when POSIX is available, where it uses mkstemp.
533 */
534 #if defined(loslib_c) || defined(luaall_c)
535
536 #if defined(LUA_USE_MKSTEMP)
537 #include <unistd.h>
538 #define LUA_TMPNAMBUFSIZE       32
539 #define lua_tmpnam(b,e) { \
540         strcpy(b, "/tmp/lua_XXXXXX"); \
541         e = mkstemp(b); \
542         if (e != -1) close(e); \
543         e = (e == -1); }
544
545 #else
546 #define LUA_TMPNAMBUFSIZE       L_tmpnam
547 #define lua_tmpnam(b,e)         { e = (tmpnam(b) == NULL); }
548 #endif
549
550 #endif
551
552
553 /*
554 @@ lua_popen spawns a new process connected to the current one through
555 @* the file streams.
556 ** CHANGE it if you have a way to implement it in your system.
557 */
558 #if defined(LUA_USE_POPEN)
559
560 #define lua_popen(L,c,m)        ((void)L, fflush(NULL), popen(c,m))
561 #define lua_pclose(L,file)      ((void)L, (pclose(file) != -1))
562
563 #elif defined(LUA_WIN)
564
565 #define lua_popen(L,c,m)        ((void)L, _popen(c,m))
566 #define lua_pclose(L,file)      ((void)L, (_pclose(file) != -1))
567
568 #else
569
570 #define lua_popen(L,c,m)        ((void)((void)c, m),  \
571                 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
572 #define lua_pclose(L,file)              ((void)((void)L, file), 0)
573
574 #endif
575
576 /*
577 @@ LUA_DL_* define which dynamic-library system Lua should use.
578 ** CHANGE here if Lua has problems choosing the appropriate
579 ** dynamic-library system for your platform (either Windows' DLL, Mac's
580 ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
581 ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
582 ** it.  To use dlopen you also need to adapt the src/Makefile (probably
583 ** adding -ldl to the linker options), so Lua does not select it
584 ** automatically.  (When you change the makefile to add -ldl, you must
585 ** also add -DLUA_USE_DLOPEN.)
586 ** If you do not want any kind of dynamic library, undefine all these
587 ** options.
588 ** By default, _WIN32 gets LUA_DL_DLL and Mac OS X gets LUA_DL_DYLD.
589 */
590 #if defined(LUA_USE_DLOPEN)
591 #define LUA_DL_DLOPEN
592 #endif
593
594 #if defined(LUA_WIN)
595 #define LUA_DL_DLL
596 #endif
597
598
599 /*
600 @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
601 @* (the data goes just *before* the lua_State pointer).
602 ** CHANGE (define) this if you really need that. This value must be
603 ** a multiple of the maximum alignment required for your machine.
604 */
605 #define LUAI_EXTRASPACE         0
606
607
608 /*
609 @@ luai_userstate* allow user-specific actions on threads.
610 ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
611 ** extra when a thread is created/deleted/resumed/yielded.
612 */
613 #define luai_userstateopen(L)           ((void)L)
614 #define luai_userstateclose(L)          ((void)L)
615 #define luai_userstatethread(L,L1)      ((void)L)
616 #define luai_userstatefree(L)           ((void)L)
617 #define luai_userstateresume(L,n)       ((void)L)
618 #define luai_userstateyield(L,n)        ((void)L)
619
620
621 /* =================================================================== */
622
623 /*
624 ** Local configuration. You can use this space to add your redefinitions
625 ** without modifying the main part of the file.
626 */
627
628
629
630 #endif
631