- Main Page
- Classes
- Files

# luaconf.h

Go to the documentation of this file.

    00001 /*
    00002 ** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
    00003 ** Configuration file for Lua
    00004 ** See Copyright Notice in lua.h
    00005 */
    00006
    00007
    00008 #ifndef lconfig_h
    00009 #define lconfig_h
    00010
    00011 #include <limits.h>
    00012 #include <stddef.h>
    00013
    00014
    00015 /*
    00016 ** ==================================================================
    00017 ** Search for "@@" to find all configurable definitions.
    00018 ** ===================================================================
    00019 */
    00020
    00021
    00022 /*
    00023 @@ LUA_ANSI controls the use of non-ansi features.
    00024 ** CHANGE it (define it) if you want Lua to avoid the use of any
    00025 ** non-ansi feature or library.
    00026 */
    00027 #if defined(__STRICT_ANSI__)
    00028 #define LUA_ANSI
    00029 #endif
    00030
    00031
    00032 #if !defined(LUA_ANSI) && defined(_WIN32)
    00033 #define LUA_WIN
    00034 #endif
    00035
    00036 #if defined(LUA_USE_LINUX)
    00037 #define LUA_USE_POSIX
    00038 #define LUA_USE_DLOPEN          /* needs an extra library: -ldl */
    00039 #define LUA_USE_READLINE        /* needs some extra libraries */
    00040 #endif
    00041
    00042 #if defined(LUA_USE_MACOSX)
    00043 #define LUA_USE_POSIX
    00044 #define LUA_DL_DYLD             /* does not need extra library */
    00045 #endif
    00046
    00047
    00048
    00049 /*
    00050 @@ LUA_USE_POSIX includes all functionallity listed as X/Open System
    00051 @* Interfaces Extension (XSI).
    00052 ** CHANGE it (define it) if your system is XSI compatible.
    00053 */
    00054 #if defined(LUA_USE_POSIX)
    00055 #define LUA_USE_MKSTEMP
    00056 #define LUA_USE_ISATTY
    00057 #define LUA_USE_POPEN
    00058 #define LUA_USE_ULONGJMP
    00059 #endif
    00060
    00061
    00062 /*
    00063 @@ LUA_PATH and LUA_CPATH are the names of the environment variables that
    00064 @* Lua check to set its paths.
    00065 @@ LUA_INIT is the name of the environment variable that Lua
    00066 @* checks for initialization code.
    00067 ** CHANGE them if you want different names.
    00068 */
    00069 #define LUA_PATH        "LUA_PATH"
    00070 #define LUA_CPATH       "LUA_CPATH"
    00071 #define LUA_INIT        "LUA_INIT"
    00072
    00073
    00074 /*
    00075 @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
    00076 @* Lua libraries.
    00077 @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
    00078 @* C libraries.
    00079 ** CHANGE them if your machine has a non-conventional directory
    00080 ** hierarchy or if you want to install your libraries in
    00081 ** non-conventional directories.
    00082 */
    00083 #if defined(_WIN32)
    00084 /*
    00085 ** In Windows, any exclamation mark ('!') in the path is replaced by the
    00086 ** path of the directory of the executable file of the current process.
    00087 */
    00088 #define LUA_LDIR        "!\\lua\\"
    00089 #define LUA_CDIR        "!\\"
    00090 #define LUA_PATH_DEFAULT  \
    00091                 ".\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
    00092                              LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
    00093 #define LUA_CPATH_DEFAULT \
    00094         ".\\?.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
    00095
    00096 #else
    00097 #define LUA_ROOT        "/usr/local/"
    00098 #define LUA_LDIR        LUA_ROOT "share/lua/5.1/"
    00099 #define LUA_CDIR        LUA_ROOT "lib/lua/5.1/"
    00100 #define LUA_PATH_DEFAULT  \
    00101                 "./?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?/init.lua;" \
    00102                             LUA_CDIR"?.lua;"  LUA_CDIR"?/init.lua"
    00103 #define LUA_CPATH_DEFAULT \
    00104         "./?.so;"  LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
    00105 #endif
    00106
    00107
    00108 /*
    00109 @@ LUA_DIRSEP is the directory separator (for submodules).
    00110 ** CHANGE it if your machine does not use "/" as the directory separator
    00111 ** and is not Windows. (On Windows Lua automatically uses "\".)
    00112 */
    00113 #if defined(_WIN32)
    00114 #define LUA_DIRSEP      "\\"
    00115 #else
    00116 #define LUA_DIRSEP      "/"
    00117 #endif
    00118
    00119
    00120 /*
    00121 @@ LUA_PATHSEP is the character that separates templates in a path.
    00122 @@ LUA_PATH_MARK is the string that marks the substitution points in a
    00123 @* template.
    00124 @@ LUA_EXECDIR in a Windows path is replaced by the executable's
    00125 @* directory.
    00126 @@ LUA_IGMARK is a mark to ignore all before it when bulding the
    00127 @* luaopen_ function name.
    00128 ** CHANGE them if for some reason your system cannot use those
    00129 ** characters. (E.g., if one of those characters is a common character
    00130 ** in file/directory names.) Probably you do not need to change them.
    00131 */
    00132 #define LUA_PATHSEP     ";"
    00133 #define LUA_PATH_MARK   "?"
    00134 #define LUA_EXECDIR     "!"
    00135 #define LUA_IGMARK      "-"
    00136
    00137
    00138 /*
    00139 @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
    00140 ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
    00141 ** machines, ptrdiff_t gives a good choice between int or long.)
    00142 */
    00143 #define LUA_INTEGER     ptrdiff_t
    00144
    00145
    00146 /*
    00147 @@ LUA_API is a mark for all core API functions.
    00148 @@ LUALIB_API is a mark for all standard library functions.
    00149 ** CHANGE them if you need to define those functions in some special way.
    00150 ** For instance, if you want to create one Windows DLL with the core and
    00151 ** the libraries, you may want to use the following definition (define
    00152 ** LUA_BUILD_AS_DLL to get it).
    00153 */
    00154 #if defined(LUA_BUILD_AS_DLL)
    00155
    00156 #if defined(LUA_CORE) || defined(LUA_LIB)
    00157 #define LUA_API __declspec(dllexport)
    00158 #else
    00159 #define LUA_API __declspec(dllimport)
    00160 #endif
    00161
    00162 #else
    00163
    00164 #define LUA_API         extern
    00165
    00166 #endif
    00167
    00168 /* more often than not the libs go together with the core */
    00169 #define LUALIB_API      LUA_API
    00170
    00171
    00172 /*
    00173 @@ LUAI_FUNC is a mark for all extern functions that are not to be
    00174 @* exported to outside modules.
    00175 @@ LUAI_DATA is a mark for all extern (const) variables that are not to
    00176 @* be exported to outside modules.
    00177 ** CHANGE them if you need to mark them in some special way. Elf/gcc
    00178 ** (versions 3.2 and later) mark them as "hidden" to optimize access
    00179 ** when Lua is compiled as a shared library.
    00180 */
    00181 #if defined(luaall_c)
    00182 #define LUAI_FUNC       static
    00183 #define LUAI_DATA       /* empty */
    00184
    00185 #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
    00186       defined(__ELF__)
    00187 #define LUAI_FUNC       __attribute__((visibility("hidden"))) extern
    00188 #define LUAI_DATA       LUAI_FUNC
    00189
    00190 #else
    00191 #define LUAI_FUNC       "hidden"
    00192 #define LUAI_DATA       "hidden"
    00193 #endif
    00194
    00195
    00196
    00197 /*
    00198 @@ LUA_QL describes how error messages quote program elements.
    00199 ** CHANGE it if you want a different appearance.
    00200 */
    00201 #define LUA_QL(x)       "'" x "'"
    00202 #define LUA_QS          LUA_QL("%s")
    00203
    00204
    00205 /*
    00206 @@ LUA_IDSIZE gives the maximum size for the description of the source
    00207 @* of a function in debug information.
    00208 ** CHANGE it if you want a different size.
    00209 */
    00210 #define LUA_IDSIZE      60
    00211
    00212
    00213 /*
    00214 ** {==================================================================
    00215 ** Stand-alone configuration
    00216 ** ===================================================================
    00217 */
    00218
    00219 #if defined(lua_c) || defined(luaall_c)
    00220
    00221 /*
    00222 @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
    00223 @* is, whether we're running lua interactively).
    00224 ** CHANGE it if you have a better definition for non-POSIX/non-Windows
    00225 ** systems.
    00226 */
    00227 #if defined(LUA_USE_ISATTY)
    00228 #include <unistd.h>
    00229 #define lua_stdin_is_tty()      isatty(0)
    00230 #elif defined(LUA_WIN)
    00231 #include <io.h>
    00232 #include <stdio.h>
    00233 #define lua_stdin_is_tty()      _isatty(_fileno(stdin))
    00234 #else
    00235 #define lua_stdin_is_tty()      1  /* assume stdin is a tty */
    00236 #endif
    00237
    00238
    00239 /*
    00240 @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
    00241 @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
    00242 ** CHANGE them if you want different prompts. (You can also change the
    00243 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
    00244 */
    00245 #define LUA_PROMPT              "> "
    00246 #define LUA_PROMPT2             ">> "
    00247
    00248
    00249 /*
    00250 @@ LUA_PROGNAME is the default name for the stand-alone Lua program.
    00251 ** CHANGE it if your stand-alone interpreter has a different name and
    00252 ** your system is not able to detect that name automatically.
    00253 */
    00254 #define LUA_PROGNAME            "lua"
    00255
    00256
    00257 /*
    00258 @@ LUA_MAXINPUT is the maximum length for an input line in the
    00259 @* stand-alone interpreter.
    00260 ** CHANGE it if you need longer lines.
    00261 */
    00262 #define LUA_MAXINPUT    512
    00263
    00264
    00265 /*
    00266 @@ lua_readline defines how to show a prompt and then read a line from
    00267 @* the standard input.
    00268 @@ lua_saveline defines how to "save" a read line in a "history".
    00269 @@ lua_freeline defines how to free a line read by lua_readline.
    00270 ** CHANGE them if you want to improve this functionality (e.g., by using
    00271 ** GNU readline and history facilities).
    00272 */
    00273 #if defined(LUA_USE_READLINE)
    00274 #include <stdio.h>
    00275 #include <readline/readline.h>
    00276 #include <readline/history.h>
    00277 #define lua_readline(L,b,p)     ((void)L, ((b)=readline(p)) != NULL)
    00278 #define lua_saveline(L,idx) \
    00279         if (lua_strlen(L,idx) > 0)  /* non-empty line? */ \
    00280           add_history(lua_tostring(L, idx));  /* add it to history */
    00281 #define lua_freeline(L,b)       ((void)L, free(b))
    00282 #else
    00283 #define lua_readline(L,b,p)     \
    00284         ((void)L, fputs(p, stdout), fflush(stdout),  /* show prompt */ \
    00285         fgets(b, LUA_MAXINPUT, stdin) != NULL)  /* get line */
    00286 #define lua_saveline(L,idx)     { (void)L; (void)idx; }
    00287 #define lua_freeline(L,b)       { (void)L; (void)b; }
    00288 #endif
    00289
    00290 #endif
    00291
    00292 /* }================================================================== */
    00293
    00294
    00295 /*
    00296 @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
    00297 @* as a percentage.
    00298 ** CHANGE it if you want the GC to run faster or slower (higher values
    00299 ** mean larger pauses which mean slower collection.) You can also change
    00300 ** this value dynamically.
    00301 */
    00302 #define LUAI_GCPAUSE    1000  /* 200% (wait memory to double before next GC) */
    00303
    00304
    00305 /*
    00306 @@ LUAI_GCMUL defines the default speed of garbage collection relative to
    00307 @* memory allocation as a percentage.
    00308 ** CHANGE it if you want to change the granularity of the garbage
    00309 ** collection. (Higher values mean coarser collections. 0 represents
    00310 ** infinity, where each step performs a full collection.) You can also
    00311 ** change this value dynamically.
    00312 */
    00313 #define LUAI_GCMUL      100 /* GC runs 'twice the speed' of memory allocation 200*/
    00314
    00315
    00316
    00317 /*
    00318 @@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
    00319 ** CHANGE it (define it) if you want exact compatibility with the
    00320 ** behavior of setn/getn in Lua 5.0.
    00321 */
    00322 #undef LUA_COMPAT_GETN
    00323
    00324 /*
    00325 @@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
    00326 ** CHANGE it to undefined as soon as you do not need a global 'loadlib'
    00327 ** function (the function is still available as 'package.loadlib').
    00328 */
    00329 #undef LUA_COMPAT_LOADLIB
    00330
    00331 /*
    00332 @@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
    00333 ** CHANGE it to undefined as soon as your programs use only '...' to
    00334 ** access vararg parameters (instead of the old 'arg' table).
    00335 */
    00336 #define LUA_COMPAT_VARARG
    00337
    00338 /*
    00339 @@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
    00340 ** CHANGE it to undefined as soon as your programs use 'math.fmod' or
    00341 ** the new '%' operator instead of 'math.mod'.
    00342 */
    00343 #undef LUA_COMPAT_MOD
    00344
    00345 /*
    00346 @@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
    00347 @* facility.
    00348 ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
    00349 ** off the advisory error when nesting [[...]].
    00350 */
    00351 #define LUA_COMPAT_LSTR         1
    00352
    00353 /*
    00354 @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
    00355 ** CHANGE it to undefined as soon as you rename 'string.gfind' to
    00356 ** 'string.gmatch'.
    00357 */
    00358 #define LUA_COMPAT_GFIND
    00359
    00360 /*
    00361 @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
    00362 @* behavior.
    00363 ** CHANGE it to undefined as soon as you replace to 'luaL_register'
    00364 ** your uses of 'luaL_openlib'
    00365 */
    00366 #define LUA_COMPAT_OPENLIB
    00367
    00368
    00369
    00370 /*
    00371 @@ luai_apicheck is the assert macro used by the Lua-C API.
    00372 ** CHANGE luai_apicheck if you want Lua to perform some checks in the
    00373 ** parameters it gets from API calls. This may slow down the interpreter
    00374 ** a bit, but may be quite useful when debugging C code that interfaces
    00375 ** with Lua. A useful redefinition is to use assert.h.
    00376 */
    00377 #if defined(LUA_USE_APICHECK)
    00378 #include <assert.h>
    00379 #define luai_apicheck(L,o)      { (void)L; assert(o); }
    00380 #else
    00381 #define luai_apicheck(L,o)      { (void)L; }
    00382 #endif
    00383
    00384
    00385 /*
    00386 @@ LUAI_BITSINT defines the number of bits in an int.
    00387 ** CHANGE here if Lua cannot automatically detect the number of bits of
    00388 ** your machine. Probably you do not need to change this.
    00389 */
    00390 /* avoid overflows in comparison */
    00391 #if INT_MAX-20 < 32760
    00392 #define LUAI_BITSINT    16
    00393 #elif INT_MAX > 2147483640L
    00394 /* int has at least 32 bits */
    00395 #define LUAI_BITSINT    32
    00396 #else
    00397 #error "you must define LUA_BITSINT with number of bits in an integer"
    00398 #endif
    00399
    00400
    00401 /*
    00402 @@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
    00403 @@ LUAI_INT32 is an signed integer with at least 32 bits.
    00404 @@ LUAI_UMEM is an unsigned integer big enough to count the total
    00405 @* memory used by Lua.
    00406 @@ LUAI_MEM is a signed integer big enough to count the total memory
    00407 @* used by Lua.
    00408 ** CHANGE here if for some weird reason the default definitions are not
    00409 ** good enough for your machine. (The definitions in the 'else'
    00410 ** part always works, but may waste space on machines with 64-bit
    00411 ** longs.) Probably you do not need to change this.
    00412 */
    00413 #if LUAI_BITSINT >= 32
    00414 #define LUAI_UINT32     unsigned int
    00415 #define LUAI_INT32      int
    00416 #define LUAI_MAXINT32   INT_MAX
    00417 #define LUAI_UMEM       size_t
    00418 #define LUAI_MEM        ptrdiff_t
    00419 #else
    00420 /* 16-bit ints */
    00421 #define LUAI_UINT32     unsigned long
    00422 #define LUAI_INT32      long
    00423 #define LUAI_MAXINT32   LONG_MAX
    00424 #define LUAI_UMEM       unsigned long
    00425 #define LUAI_MEM        long
    00426 #endif
    00427
    00428
    00429 /*
    00430 @@ LUAI_MAXCALLS limits the number of nested calls.
    00431 ** CHANGE it if you need really deep recursive calls. This limit is
    00432 ** arbitrary; its only purpose is to stop infinite recursion before
    00433 ** exhausting memory.
    00434 */
    00435 #define LUAI_MAXCALLS   20000
    00436
    00437
    00438 /*
    00439 @@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
    00440 @* can use.
    00441 ** CHANGE it if you need lots of (Lua) stack space for your C
    00442 ** functions. This limit is arbitrary; its only purpose is to stop C
    00443 ** functions to consume unlimited stack space. (must be smaller than
    00444 ** -LUA_REGISTRYINDEX)
    00445 */
    00446 #define LUAI_MAXCSTACK  8000
    00447
    00448
    00449
    00450 /*
    00451 ** {==================================================================
    00452 ** CHANGE (to smaller values) the following definitions if your system
    00453 ** has a small C stack. (Or you may want to change them to larger
    00454 ** values if your system has a large C stack and these limits are
    00455 ** too rigid for you.) Some of these constants control the size of
    00456 ** stack-allocated arrays used by the compiler or the interpreter, while
    00457 ** others limit the maximum number of recursive calls that the compiler
    00458 ** or the interpreter can perform. Values too large may cause a C stack
    00459 ** overflow for some forms of deep constructs.
    00460 ** ===================================================================
    00461 */
    00462
    00463
    00464 /*
    00465 @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
    00466 @* syntactical nested non-terminals in a program.
    00467 */
    00468 #define LUAI_MAXCCALLS          200
    00469
    00470
    00471 /*
    00472 @@ LUAI_MAXVARS is the maximum number of local variables per function
    00473 @* (must be smaller than 250).
    00474 */
    00475 #define LUAI_MAXVARS            200
    00476
    00477
    00478 /*
    00479 @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
    00480 @* (must be smaller than 250).
    00481 */
    00482 #define LUAI_MAXUPVALUES        60
    00483
    00484
    00485 /*
    00486 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
    00487 */
    00488 #define LUAL_BUFFERSIZE         BUFSIZ
    00489
    00490 /* }================================================================== */
    00491
    00492
    00493
    00494
    00495 /*
    00496 ** {==================================================================
    00497 @@ LUA_NUMBER is the type of numbers in Lua.
    00498 ** CHANGE the following definitions only if you want to build Lua
    00499 ** with a number type different from double. You may also need to
    00500 ** change lua_number2int & lua_number2integer.
    00501 ** ===================================================================
    00502 */
    00503
    00504 #define LUA_NUMBER_DOUBLE
    00505 #define LUA_NUMBER      float
    00506
    00507 /*
    00508 @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
    00509 @* over a number.
    00510 */
    00511 #define LUAI_UACNUMBER  float
    00512
    00513
    00514 /*
    00515 @@ LUA_NUMBER_SCAN is the format for reading numbers.
    00516 @@ LUA_NUMBER_FMT is the format for writing numbers.
    00517 @@ lua_number2str converts a number to a string.
    00518 @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
    00519 @@ lua_str2number converts a string to a number.
    00520 */
    00521 #define LUA_NUMBER_SCAN         "%f"
    00522 #define LUA_NUMBER_FMT          "%f" //%.14g
    00523 #define lua_number2str(s,n)     sprintf((s), LUA_NUMBER_FMT, (n))
    00524 #define LUAI_MAXNUMBER2STR      32 /* 16 digits, sign, point, and \0 */
    00525 #define lua_str2number(s,p)     strtod((s), (p))
    00526
    00527
    00528 /*
    00529 @@ The luai_num* macros define the primitive operations over numbers.
    00530 */
    00531 static float add_single(float a, float b)
    00532 {
    00533    float result;
    00534    __asm__ volatile (
    00535        "mtv    %1, S000\n"
    00536        "mtv    %2, S001\n"
    00537        "vadd.s S002, S000, S001\n"
    00538        "mfv    %0, S002\n"
    00539        : "=r"(result) : "r"(a), "r"(b));
    00540    return result;
    00541 }
    00542 static float sub_single(float a, float b)
    00543 {
    00544    float result;
    00545    __asm__ volatile (
    00546        "mtv    %1, S000\n"
    00547        "mtv    %2, S001\n"
    00548        "vsub.s S002, S000, S001\n"
    00549        "mfv    %0, S002\n"
    00550        : "=r"(result) : "r"(a), "r"(b));
    00551    return result;
    00552 }
    00553 static float mul_single(float a, float b)
    00554 {
    00555    float result;
    00556    __asm__ volatile (
    00557        "mtv    %1, S000\n"
    00558        "mtv    %2, S001\n"
    00559        "vmul.s S002, S000, S001\n"
    00560        "mfv    %0, S002\n"
    00561        : "=r"(result) : "r"(a), "r"(b));
    00562    return result;
    00563 }
    00564 static float div_single(float a, float b)
    00565 {
    00566    float result;
    00567    __asm__ volatile (
    00568        "mtv    %1, S000\n"
    00569        "mtv    %2, S001\n"
    00570        "vrcp.s  S001, S001\n"
    00571        "vmul.s  S000, S000, S001\n"
    00572        "mfv    %0, S000\n"
    00573        : "=r"(result) : "r"(a), "r"(b));
    00574    return result;
    00575 }
    00576 //#if defined(LUA_CORE)
    00577 #include <fastmath.h>
    00578 #define luai_numadd(a,b)        add_single(a, b)
    00579 #define luai_numsub(a,b)        sub_single(a, b)
    00580 #define luai_nummul(a,b)        mul_single(a, b)
    00581 #define luai_numdiv(a,b)        div_single(a, b)
    00582 //#define luai_nummod(a,b)      ((a) - floorf((a)/(b))*(b))
    00583 //#define luai_numpow(a,b)      (powf(a,b))
    00584 #define luai_numunm(a)          (-(a))
    00585 #define luai_numeq(a,b)         ((a)==(b))
    00586 #define luai_numlt(a,b)         ((a)<(b))
    00587 #define luai_numle(a,b)         ((a)<=(b))
    00588 #define luai_numisnan(a)        (!luai_numeq((a), (a)))
    00589 //#endif
    00590
    00591
    00592 /*
    00593 @@ lua_number2int is a macro to convert lua_Number to int.
    00594 @@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
    00595 ** CHANGE them if you know a faster way to convert a lua_Number to
    00596 ** int (with any rounding method and without throwing errors) in your
    00597 ** system. In Pentium machines, a naive typecast from double to int
    00598 ** in C is extremely slow, so any alternative is worth trying.
    00599 */
    00600
    00601 /* On a Pentium, resort to a trick */
    00602 #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
    00603     (defined(__i386) || defined (_M_IX86) || defined(__i386__))
    00604
    00605 /* On a Microsoft compiler, use assembler */
    00606 #if defined(_MSC_VER)
    00607
    00608 #define lua_number2int(i,d)   __asm fld d   __asm fistp i
    00609 #define lua_number2integer(i,n)         lua_number2int(i, n)
    00610
    00611 /* the next trick should work on any Pentium, but sometimes clashes
    00612    with a DirectX idiosyncrasy */
    00613 #else
    00614
    00615 union luai_Cast { float l_d; long l_l; };
    00616 #define lua_number2int(i,d) \
    00617   { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
    00618 #define lua_number2integer(i,n)         lua_number2int(i, n)
    00619
    00620 #endif
    00621
    00622
    00623 /* this option always works, but may be slow */
    00624 #else
    00625 #define lua_number2int(i,d)     ((i)=(int)(d))
    00626 #define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
    00627
    00628 #endif
    00629
    00630 /* }================================================================== */
    00631
    00632
    00633 /*
    00634 @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
    00635 ** CHANGE it if your system requires alignments larger than double. (For
    00636 ** instance, if your system supports long doubles and they must be
    00637 ** aligned in 16-byte boundaries, then you should add long double in the
    00638 ** union.) Probably you do not need to change this.
    00639 */
    00640 #define LUAI_USER_ALIGNMENT_T   union { float u; void *s; long l; }
    00641
    00642
    00643 /*
    00644 @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
    00645 ** CHANGE them if you prefer to use longjmp/setjmp even with C++
    00646 ** or if want/don't to use _longjmp/_setjmp instead of regular
    00647 ** longjmp/setjmp. By default, Lua handles errors with exceptions when
    00648 ** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
    00649 ** and with longjmp/setjmp otherwise.
    00650 */
    00651 #if defined(__cplusplus)
    00652 /* C++ exceptions */
    00653 #define LUAI_THROW(L,c) throw(c)
    00654 #define LUAI_TRY(L,c,a) try { a } catch(...) \
    00655         { if ((c)->status == 0) (c)->status = -1; }
    00656 #define luai_jmpbuf     int  /* dummy variable */
    00657
    00658 #elif defined(LUA_USE_ULONGJMP)
    00659 /* in Unix, try _longjmp/_setjmp (more efficient) */
    00660 #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
    00661 #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
    00662 #define luai_jmpbuf     jmp_buf
    00663
    00664 #else
    00665 /* default handling with long jumps */
    00666 #define LUAI_THROW(L,c) longjmp((c)->b, 1)
    00667 #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
    00668 #define luai_jmpbuf     jmp_buf
    00669
    00670 #endif
    00671
    00672
    00673 /*
    00674 @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
    00675 @* can do during pattern-matching.
    00676 ** CHANGE it if you need more captures. This limit is arbitrary.
    00677 */
    00678 #define LUA_MAXCAPTURES         32
    00679
    00680
    00681 /*
    00682 @@ lua_tmpnam is the function that the OS library uses to create a
    00683 @* temporary name.
    00684 @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
    00685 ** CHANGE them if you have an alternative to tmpnam (which is considered
    00686 ** insecure) or if you want the original tmpnam anyway.  By default, Lua
    00687 ** uses tmpnam except when POSIX is available, where it uses mkstemp.
    00688 */
    00689 #if defined(loslib_c) || defined(luaall_c)
    00690
    00691 #if defined(LUA_USE_MKSTEMP)
    00692 #include <unistd.h>
    00693 #define LUA_TMPNAMBUFSIZE       32
    00694 #define lua_tmpnam(b,e) { \
    00695         strcpy(b, "/tmp/lua_XXXXXX"); \
    00696         e = mkstemp(b); \
    00697         if (e != -1) close(e); \
    00698         e = (e == -1); }
    00699
    00700 #else
    00701 #define LUA_TMPNAMBUFSIZE       L_tmpnam
    00702 #define lua_tmpnam(b,e)         { e = (tmpnam(b) == NULL); }
    00703 #endif
    00704
    00705 #endif
    00706
    00707
    00708 /*
    00709 @@ lua_popen spawns a new process connected to the current one through
    00710 @* the file streams.
    00711 ** CHANGE it if you have a way to implement it in your system.
    00712 */
    00713 #if defined(LUA_USE_POPEN)
    00714
    00715 #define lua_popen(L,c,m)        ((void)L, fflush(NULL), popen(c,m))
    00716 #define lua_pclose(L,file)      ((void)L, (pclose(file) != -1))
    00717
    00718 #elif defined(LUA_WIN)
    00719
    00720 #define lua_popen(L,c,m)        ((void)L, _popen(c,m))
    00721 #define lua_pclose(L,file)      ((void)L, (_pclose(file) != -1))
    00722
    00723 #else
    00724
    00725 #define lua_popen(L,c,m)        ((void)((void)c, m),  \
    00726                 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
    00727 #define lua_pclose(L,file)              ((void)((void)L, file), 0)
    00728
    00729 #endif
    00730
    00731 /*
    00732 @@ LUA_DL_* define which dynamic-library system Lua should use.
    00733 ** CHANGE here if Lua has problems choosing the appropriate
    00734 ** dynamic-library system for your platform (either Windows' DLL, Mac's
    00735 ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
    00736 ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
    00737 ** it.  To use dlopen you also need to adapt the src/Makefile (probably
    00738 ** adding -ldl to the linker options), so Lua does not select it
    00739 ** automatically.  (When you change the makefile to add -ldl, you must
    00740 ** also add -DLUA_USE_DLOPEN.)
    00741 ** If you do not want any kind of dynamic library, undefine all these
    00742 ** options.
    00743 ** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
    00744 */
    00745 #if defined(LUA_USE_DLOPEN)
    00746 #define LUA_DL_DLOPEN
    00747 #endif
    00748
    00749 #if defined(LUA_WIN)
    00750 #define LUA_DL_DLL
    00751 #endif
    00752
    00753
    00754 /*
    00755 @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
    00756 @* (the data goes just *before* the lua_State pointer).
    00757 ** CHANGE (define) this if you really need that. This value must be
    00758 ** a multiple of the maximum alignment required for your machine.
    00759 */
    00760 #define LUAI_EXTRASPACE         0
    00761
    00762
    00763 /*
    00764 @@ luai_userstate* allow user-specific actions on threads.
    00765 ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
    00766 ** extra when a thread is created/deleted/resumed/yielded.
    00767 */
    00768 #define luai_userstateopen(L)           ((void)L)
    00769 #define luai_userstateclose(L)          ((void)L)
    00770 #define luai_userstatethread(L,L1)      ((void)L)
    00771 #define luai_userstatefree(L)           ((void)L)
    00772 #define luai_userstateresume(L,n)       ((void)L)
    00773 #define luai_userstateyield(L,n)        ((void)L)
    00774
    00775
    00776 /*
    00777 @@ LUA_INTFRMLEN is the length modifier for integer conversions
    00778 @* in 'string.format'.
    00779 @@ LUA_INTFRM_T is the integer type correspoding to the previous length
    00780 @* modifier.
    00781 ** CHANGE them if your system supports long long or does not support long.
    00782 */
    00783
    00784 #if defined(LUA_USELONGLONG)
    00785
    00786 #define LUA_INTFRMLEN           "ll"
    00787 #define LUA_INTFRM_T            long long
    00788
    00789 #else
    00790
    00791 #define LUA_INTFRMLEN           "l"
    00792 #define LUA_INTFRM_T            long
    00793
    00794 #endif
    00795
    00796
    00797
    00798 /* =================================================================== */
    00799
    00800 /*
    00801 ** Local configuration. You can use this space to add your redefinitions
    00802 ** without modifying the main part of the file.
    00803 */
    00804
    00805
    00806
    00807 #endif
    00808