luaconf.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. /*
  2. ** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
  3. ** Configuration file for Lua
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lconfig_h
  7. #define lconfig_h
  8. #ifdef LUA_CROSS_COMPILER
  9. #include <limits.h>
  10. #include <stddef.h>
  11. #else
  12. #include "c_limits.h"
  13. #include "c_stddef.h"
  14. #endif
  15. #include "user_config.h"
  16. /*
  17. ** ==================================================================
  18. ** Search for "@@" to find all configurable definitions.
  19. ** ===================================================================
  20. */
  21. /*
  22. @@ LUA_ANSI controls the use of non-ansi features.
  23. ** CHANGE it (define it) if you want Lua to avoid the use of any
  24. ** non-ansi feature or library.
  25. */
  26. #if defined(__STRICT_ANSI__)
  27. #define LUA_ANSI
  28. #endif
  29. #if !defined(LUA_ANSI) && defined(_WIN32)
  30. #define LUA_WIN
  31. #endif
  32. #if defined(LUA_USE_LINUX)
  33. #define LUA_USE_POSIX
  34. #define LUA_USE_DLOPEN /* needs an extra library: -ldl */
  35. #define LUA_USE_READLINE /* needs some extra libraries */
  36. #endif
  37. #if defined(LUA_USE_MACOSX)
  38. #define LUA_USE_POSIX
  39. #define LUA_DL_DYLD /* does not need extra library */
  40. #endif
  41. /*
  42. @@ LUA_USE_POSIX includes all functionallity listed as X/Open System
  43. @* Interfaces Extension (XSI).
  44. ** CHANGE it (define it) if your system is XSI compatible.
  45. */
  46. #if defined(LUA_USE_POSIX)
  47. #define LUA_USE_MKSTEMP
  48. #define LUA_USE_ISATTY
  49. #define LUA_USE_POPEN
  50. #define LUA_USE_ULONGJMP
  51. #endif
  52. /*
  53. @@ LUA_PATH and LUA_CPATH are the names of the environment variables that
  54. @* Lua check to set its paths.
  55. @@ LUA_INIT is the name of the environment variable that Lua
  56. @* checks for initialization code.
  57. ** CHANGE them if you want different names.
  58. */
  59. #define LUA_PATH "LUA_PATH"
  60. #define LUA_CPATH "LUA_CPATH"
  61. #define LUA_INIT "LUA_INIT"
  62. /*
  63. @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
  64. @* Lua libraries.
  65. @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
  66. @* C libraries.
  67. ** CHANGE them if your machine has a non-conventional directory
  68. ** hierarchy or if you want to install your libraries in
  69. ** non-conventional directories.
  70. */
  71. #if defined(_WIN32)
  72. /*
  73. ** In Windows, any exclamation mark ('!') in the path is replaced by the
  74. ** path of the directory of the executable file of the current process.
  75. */
  76. #define LUA_LDIR "!\\lua\\"
  77. #define LUA_CDIR "!\\"
  78. //## Modified for eLua
  79. //## Defaults search modules path to our ROM File System
  80. #ifndef LUA_RPC
  81. #define LUA_PATH_DEFAULT "/rfs/?.lua;/rfs/?.lc;/mmc/?.lua;/mmc/?.lc;/rom/?.lua;/rom/?.lc"
  82. #define LUA_CPATH_DEFAULT ""
  83. #else // #ifndef LUA_RPC
  84. #define LUA_PATH_DEFAULT \
  85. ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
  86. LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua"
  87. #define LUA_CPATH_DEFAULT \
  88. ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
  89. #endif // #ifndef LUA_RPC
  90. #else // #if defined(_WIN32)
  91. #define LUA_ROOT "/usr/local/"
  92. #define LUA_LDIR LUA_ROOT "share/lua/5.1/"
  93. #define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
  94. #ifndef LUA_RPC
  95. #define LUA_PATH_DEFAULT "?.lc;?.lua"
  96. #define LUA_CPATH_DEFAULT ""
  97. #else // #ifndef LUA_RPC
  98. #define LUA_PATH_DEFAULT \
  99. "./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
  100. LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
  101. #define LUA_CPATH_DEFAULT \
  102. "./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so"
  103. #endif // #ifndef LUA_RPC
  104. #endif // #if defined(_WIN32)
  105. /*
  106. @@ LUA_DIRSEP is the directory separator (for submodules).
  107. ** CHANGE it if your machine does not use "/" as the directory separator
  108. ** and is not Windows. (On Windows Lua automatically uses "\".)
  109. */
  110. #if defined(_WIN32)
  111. #define LUA_DIRSEP "\\"
  112. #else
  113. #define LUA_DIRSEP "/"
  114. #endif
  115. /*
  116. @@ LUA_PATHSEP is the character that separates templates in a path.
  117. @@ LUA_PATH_MARK is the string that marks the substitution points in a
  118. @* template.
  119. @@ LUA_EXECDIR in a Windows path is replaced by the executable's
  120. @* directory.
  121. @@ LUA_IGMARK is a mark to ignore all before it when bulding the
  122. @* luaopen_ function name.
  123. ** CHANGE them if for some reason your system cannot use those
  124. ** characters. (E.g., if one of those characters is a common character
  125. ** in file/directory names.) Probably you do not need to change them.
  126. */
  127. #define LUA_PATHSEP ";"
  128. #define LUA_PATH_MARK "?"
  129. #define LUA_EXECDIR "!"
  130. #define LUA_IGMARK "-"
  131. /*
  132. @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
  133. ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
  134. ** machines, ptrdiff_t gives a good choice between int or long.)
  135. */
  136. /* Changed to long for use with integral Lua numbers. */
  137. #if !defined LUA_NUMBER_INTEGRAL
  138. #define LUA_INTEGER ptrdiff_t
  139. #else
  140. #if !defined LUA_INTEGRAL_LONGLONG
  141. #define LUA_INTEGER long
  142. #else
  143. #define LUA_INTEGER long long
  144. #endif // #if !defined LUA_INTEGRAL_LONGLONG
  145. #endif // #if !defined LUA_NUMBER_INTEGRAL
  146. /*
  147. @@ LUA_API is a mark for all core API functions.
  148. @@ LUALIB_API is a mark for all standard library functions.
  149. ** CHANGE them if you need to define those functions in some special way.
  150. ** For instance, if you want to create one Windows DLL with the core and
  151. ** the libraries, you may want to use the following definition (define
  152. ** LUA_BUILD_AS_DLL to get it).
  153. */
  154. #if defined(LUA_BUILD_AS_DLL)
  155. #if defined(LUA_CORE) || defined(LUA_LIB)
  156. #define LUA_API __declspec(dllexport)
  157. #else
  158. #define LUA_API __declspec(dllimport)
  159. #endif
  160. #else
  161. #define LUA_API extern
  162. #endif
  163. /* more often than not the libs go together with the core */
  164. #define LUALIB_API LUA_API
  165. /*
  166. @@ LUAI_FUNC is a mark for all extern functions that are not to be
  167. @* exported to outside modules.
  168. @@ LUAI_DATA is a mark for all extern (const) variables that are not to
  169. @* be exported to outside modules.
  170. ** CHANGE them if you need to mark them in some special way. Elf/gcc
  171. ** (versions 3.2 and later) mark them as "hidden" to optimize access
  172. ** when Lua is compiled as a shared library.
  173. */
  174. #if defined(luaall_c)
  175. #define LUAI_FUNC static
  176. #define LUAI_DATA /* empty */
  177. #elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
  178. defined(__ELF__)
  179. #define LUAI_FUNC __attribute__((visibility("hidden"))) extern
  180. #define LUAI_DATA LUAI_FUNC
  181. #else
  182. #define LUAI_FUNC extern
  183. #define LUAI_DATA extern
  184. #endif
  185. /*
  186. @@ LUA_QL describes how error messages quote program elements.
  187. ** CHANGE it if you want a different appearance.
  188. */
  189. #define LUA_QL(x) "'" x "'"
  190. #define LUA_QS LUA_QL("%s")
  191. /*
  192. @@ LUA_IDSIZE gives the maximum size for the description of the source
  193. @* of a function in debug information.
  194. ** CHANGE it if you want a different size.
  195. */
  196. #define LUA_IDSIZE 60
  197. /*
  198. ** {==================================================================
  199. ** Stand-alone configuration
  200. ** ===================================================================
  201. */
  202. /*
  203. @@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
  204. @* is, whether we're running lua interactively).
  205. ** CHANGE it if you have a better definition for non-POSIX/non-Windows
  206. ** systems.
  207. */
  208. #if defined(LUA_USE_ISATTY)
  209. #include <unistd.h>
  210. #define lua_stdin_is_tty() isatty(0)
  211. #elif defined(LUA_WIN)
  212. #include <io.h>
  213. #ifdef LUA_CROSS_COMPILER
  214. #include <stdio.h>
  215. else
  216. #include "c_stdio.h"
  217. #endif
  218. #define lua_stdin_is_tty() _isatty(_fileno(stdin))
  219. #else
  220. #define lua_stdin_is_tty() 1 /* assume stdin is a tty */
  221. #endif
  222. /*
  223. @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
  224. @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
  225. ** CHANGE them if you want different prompts. (You can also change the
  226. ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
  227. */
  228. #define LUA_PROMPT "> "
  229. #define LUA_PROMPT2 ">> "
  230. /*
  231. @@ LUA_PROGNAME is the default name for the stand-alone Lua program.
  232. ** CHANGE it if your stand-alone interpreter has a different name and
  233. ** your system is not able to detect that name automatically.
  234. */
  235. #define LUA_PROGNAME "lua"
  236. /*
  237. @@ LUA_MAXINPUT is the maximum length for an input line in the
  238. @* stand-alone interpreter.
  239. ** CHANGE it if you need longer lines.
  240. */
  241. #define LUA_MAXINPUT 256
  242. /*
  243. @@ lua_readline defines how to show a prompt and then read a line from
  244. @* the standard input.
  245. @@ lua_saveline defines how to "save" a read line in a "history".
  246. @@ lua_freeline defines how to free a line read by lua_readline.
  247. ** CHANGE them if you want to improve this functionality (e.g., by using
  248. ** GNU readline and history facilities).
  249. */
  250. #if defined(LUA_USE_STDIO)
  251. #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
  252. #include <stdio.h>
  253. #include <readline/readline.h>
  254. #include <readline/history.h>
  255. #define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
  256. #define lua_saveline(L,idx) \
  257. if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
  258. add_history(lua_tostring(L, idx)); /* add it to history */
  259. #define lua_freeline(L,b) ((void)L, c_free(b))
  260. #else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
  261. #define lua_readline(L,b,p) \
  262. ((void)L, c_fputs(p, c_stdout), c_fflush(c_stdout), /* show prompt */ \
  263. c_fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */
  264. #define lua_saveline(L,idx) { (void)L; (void)idx; }
  265. #define lua_freeline(L,b) { (void)L; (void)b; }
  266. #endif // #if defined(LUA_USE_READLINE)
  267. #else // #if defined(LUA_USE_STDIO)
  268. #define lua_readline(L,b,p) (readline4lua(p, b, LUA_MAXINPUT))
  269. #define lua_saveline(L,idx) { (void)L; (void)idx; }
  270. #define lua_freeline(L,b) { (void)L; (void)b; }
  271. extern int readline4lua(const char *prompt, char *buffer, int length);
  272. #endif // #if defined(LUA_USE_STDIO)
  273. /*
  274. @@ luai_writestring/luai_writeline define how 'print' prints its results.
  275. ** They are only used in libraries and the stand-alone program. (The #if
  276. ** avoids including 'stdio.h' everywhere.)
  277. */
  278. #if !defined(LUA_USE_STDIO)
  279. #define luai_writestring(s, l) c_puts(s)
  280. #define luai_writeline() c_puts("\n")
  281. #endif // defined(LUA_USE_STDIO)
  282. /*
  283. @@ luai_writestringerror defines how to print error messages.
  284. ** (A format string with one argument is enough for Lua...)
  285. */
  286. #if !defined(LUA_USE_STDIO)
  287. #define luai_writestringerror(s,p) dbg_printf((s), (p))
  288. #endif // defined(LUA_USE_STDIO)
  289. /* }================================================================== */
  290. /*
  291. @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
  292. @* as a percentage.
  293. ** CHANGE it if you want the GC to run faster or slower (higher values
  294. ** mean larger pauses which mean slower collection.) You can also change
  295. ** this value dynamically.
  296. */
  297. #define LUAI_GCPAUSE 110 /* 110% (wait memory to grow 10% before next gc) */
  298. /*
  299. @@ LUAI_GCMUL defines the default speed of garbage collection relative to
  300. @* memory allocation as a percentage.
  301. ** CHANGE it if you want to change the granularity of the garbage
  302. ** collection. (Higher values mean coarser collections. 0 represents
  303. ** infinity, where each step performs a full collection.) You can also
  304. ** change this value dynamically.
  305. */
  306. #define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
  307. /*
  308. @@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
  309. ** CHANGE it (define it) if you want exact compatibility with the
  310. ** behavior of setn/getn in Lua 5.0.
  311. */
  312. #undef LUA_COMPAT_GETN
  313. /*
  314. @@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
  315. ** CHANGE it to undefined as soon as you do not need a global 'loadlib'
  316. ** function (the function is still available as 'package.loadlib').
  317. */
  318. #undef LUA_COMPAT_LOADLIB
  319. /*
  320. @@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
  321. ** CHANGE it to undefined as soon as your programs use only '...' to
  322. ** access vararg parameters (instead of the old 'arg' table).
  323. */
  324. #define LUA_COMPAT_VARARG
  325. /*
  326. @@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
  327. ** CHANGE it to undefined as soon as your programs use 'math.fmod' or
  328. ** the new '%' operator instead of 'math.mod'.
  329. */
  330. #define LUA_COMPAT_MOD
  331. /*
  332. @@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
  333. @* facility.
  334. ** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
  335. ** off the advisory error when nesting [[...]].
  336. */
  337. #define LUA_COMPAT_LSTR 1
  338. /*
  339. @@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
  340. ** CHANGE it to undefined as soon as you rename 'string.gfind' to
  341. ** 'string.gmatch'.
  342. */
  343. #define LUA_COMPAT_GFIND
  344. /*
  345. @@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
  346. @* behavior.
  347. ** CHANGE it to undefined as soon as you replace to 'luaL_register'
  348. ** your uses of 'luaL_openlib'
  349. */
  350. #define LUA_COMPAT_OPENLIB
  351. /*
  352. @@ LUA_STRESS_EMERGENCY_GC enables stress testing code for the Emergency GC.
  353. ** CHANGE it to defined if you want to test for Emergency GC related bugs.
  354. ** Note that this will make the Lua vm very slow, since it will force a
  355. ** full GC on every new allocation.
  356. */
  357. #undef LUA_STRESS_EMERGENCY_GC
  358. /*
  359. @@ luai_apicheck is the assert macro used by the Lua-C API.
  360. ** CHANGE luai_apicheck if you want Lua to perform some checks in the
  361. ** parameters it gets from API calls. This may slow down the interpreter
  362. ** a bit, but may be quite useful when debugging C code that interfaces
  363. ** with Lua. A useful redefinition is to use assert.h.
  364. */
  365. #if defined(LUA_USE_APICHECK)
  366. #include <assert.h>
  367. #define luai_apicheck(L,o) { (void)L; assert(o); }
  368. #else
  369. #define luai_apicheck(L,o) { (void)L; }
  370. #endif
  371. /*
  372. @@ LUAI_BITSINT defines the number of bits in an int.
  373. ** CHANGE here if Lua cannot automatically detect the number of bits of
  374. ** your machine. Probably you do not need to change this.
  375. */
  376. /* avoid overflows in comparison */
  377. #if INT_MAX-20 < 32760
  378. #define LUAI_BITSINT 16
  379. #elif INT_MAX > 2147483640L
  380. /* int has at least 32 bits */
  381. #define LUAI_BITSINT 32
  382. #else
  383. #error "you must define LUA_BITSINT with number of bits in an integer"
  384. #endif
  385. /*
  386. @@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
  387. @@ LUAI_INT32 is an signed integer with at least 32 bits.
  388. @@ LUAI_UMEM is an unsigned integer big enough to count the total
  389. @* memory used by Lua.
  390. @@ LUAI_MEM is a signed integer big enough to count the total memory
  391. @* used by Lua.
  392. ** CHANGE here if for some weird reason the default definitions are not
  393. ** good enough for your machine. (The definitions in the 'else'
  394. ** part always works, but may waste space on machines with 64-bit
  395. ** longs.) Probably you do not need to change this.
  396. */
  397. #if LUAI_BITSINT >= 32
  398. #define LUAI_UINT32 unsigned int
  399. #define LUAI_INT32 int
  400. #define LUAI_MAXINT32 INT_MAX
  401. #define LUAI_UMEM size_t
  402. #define LUAI_MEM ptrdiff_t
  403. #else
  404. /* 16-bit ints */
  405. #define LUAI_UINT32 unsigned long
  406. #define LUAI_INT32 long
  407. #define LUAI_MAXINT32 LONG_MAX
  408. #define LUAI_UMEM unsigned long
  409. #define LUAI_MEM long
  410. #endif
  411. /*
  412. @@ LUAI_MAXCALLS limits the number of nested calls.
  413. ** CHANGE it if you need really deep recursive calls. This limit is
  414. ** arbitrary; its only purpose is to stop infinite recursion before
  415. ** exhausting memory.
  416. */
  417. #define LUAI_MAXCALLS 20000
  418. /*
  419. @@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
  420. @* can use.
  421. ** CHANGE it if you need lots of (Lua) stack space for your C
  422. ** functions. This limit is arbitrary; its only purpose is to stop C
  423. ** functions to consume unlimited stack space. (must be smaller than
  424. ** -LUA_REGISTRYINDEX)
  425. */
  426. #define LUAI_MAXCSTACK 8000
  427. /*
  428. ** {==================================================================
  429. ** CHANGE (to smaller values) the following definitions if your system
  430. ** has a small C stack. (Or you may want to change them to larger
  431. ** values if your system has a large C stack and these limits are
  432. ** too rigid for you.) Some of these constants control the size of
  433. ** stack-allocated arrays used by the compiler or the interpreter, while
  434. ** others limit the maximum number of recursive calls that the compiler
  435. ** or the interpreter can perform. Values too large may cause a C stack
  436. ** overflow for some forms of deep constructs.
  437. ** ===================================================================
  438. */
  439. /*
  440. @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
  441. @* syntactical nested non-terminals in a program.
  442. */
  443. #define LUAI_MAXCCALLS 200
  444. /*
  445. @@ LUAI_MAXVARS is the maximum number of local variables per function
  446. @* (must be smaller than 250).
  447. */
  448. #define LUAI_MAXVARS 50
  449. /*
  450. @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
  451. @* (must be smaller than 250).
  452. */
  453. #define LUAI_MAXUPVALUES 60
  454. /*
  455. @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
  456. ** Attention: This value should probably not be set higher than 1K.
  457. ** The size has direct impact on the C stack size needed be auxlib functions.
  458. ** For example: If set to 4K a call to string.gsub will need more than
  459. ** 5k C stack space.
  460. */
  461. #define LUAL_BUFFERSIZE 256
  462. /* }================================================================== */
  463. /*
  464. ** {==================================================================
  465. @@ LUA_NUMBER is the type of numbers in Lua.
  466. ** CHANGE the following definitions only if you want to build Lua
  467. ** with a number type different from double. You may also need to
  468. ** change lua_number2int & lua_number2integer.
  469. ** ===================================================================
  470. */
  471. /* Define LUA_NUMBER_INTEGRAL to produce a system that uses no
  472. floating point operations by changing the type of Lua numbers from
  473. double to long. It implements division and modulus so that
  474. x == (x / y) * y + x % y.
  475. The exponentiation function returns zero for negative exponents.
  476. Defining LUA_NUMBER_INTEGRAL also removes the difftime function,
  477. and the math module should not be used. The string.format function
  478. no longer handles the floating point directives %e, %E, %f, %g, and
  479. %G. */
  480. #if defined LUA_NUMBER_INTEGRAL
  481. #define LUA_NUMBER LUA_INTEGER
  482. #else
  483. #define LUA_NUMBER_DOUBLE
  484. #define LUA_NUMBER double
  485. #endif
  486. /*
  487. @@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
  488. @* over a number.
  489. */
  490. #define LUAI_UACNUMBER LUA_NUMBER
  491. /*
  492. @@ LUA_NUMBER_SCAN is the format for reading numbers.
  493. @@ LUA_NUMBER_FMT is the format for writing numbers.
  494. @@ lua_number2str converts a number to a string.
  495. @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
  496. @@ lua_str2number converts a string to a number.
  497. */
  498. #if defined LUA_NUMBER_INTEGRAL
  499. #if !defined LUA_INTEGRAL_LONGLONG
  500. #define LUA_NUMBER_SCAN "%ld"
  501. #define LUA_NUMBER_FMT "%ld"
  502. #else
  503. #define LUA_NUMBER_SCAN "%lld"
  504. #define LUA_NUMBER_FMT "%lld"
  505. #endif // #if !defined LUA_INTEGRAL_LONGLONG
  506. #else
  507. #define LUA_NUMBER_SCAN "%lf"
  508. #define LUA_NUMBER_FMT "%.14g"
  509. #endif // #if defined LUA_NUMBER_INTEGRAL
  510. #define lua_number2str(s,n) c_sprintf((s), LUA_NUMBER_FMT, (n))
  511. #define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
  512. #if defined LUA_NUMBER_INTEGRAL
  513. #if !defined LUA_INTEGRAL_LONGLONG
  514. #define lua_str2number(s,p) c_strtol((s), (p), 10)
  515. #else
  516. #define lua_str2number(s,p) c_strtoll((s), (p), 10)
  517. #endif // #if !defined LUA_INTEGRAL_LONGLONG
  518. #else
  519. #define lua_str2number(s,p) c_strtod((s), (p))
  520. #endif // #if defined LUA_NUMBER_INTEGRAL
  521. /*
  522. @@ The luai_num* macros define the primitive operations over numbers.
  523. */
  524. #if defined(LUA_CORE) || defined(LUA_LIB)
  525. #ifdef LUA_CROSS_COMPILER
  526. #include <math.h>
  527. #else
  528. #include "c_math.h"
  529. #endif
  530. #define luai_numadd(a,b) ((a)+(b))
  531. #define luai_numsub(a,b) ((a)-(b))
  532. #define luai_nummul(a,b) ((a)*(b))
  533. #if defined LUA_NUMBER_INTEGRAL
  534. #define luai_numdiv(a,b) \
  535. (-1/2? \
  536. (a)/(b): \
  537. ((((a)<0)==((b)<0))||(((a)%(b))==0)? \
  538. (a)/(b): \
  539. (a)/(b)-1))
  540. #define luai_nummod(a,b) \
  541. (-1/2? \
  542. (a)%(b): \
  543. ((((a)<0)==((b)<0))||(((a)%(b))==0)? \
  544. (a)%(b): \
  545. (a)%(b)+(b)))
  546. #define luai_lnumdiv(a,b) \
  547. ((b)==0? \
  548. (luaG_runerror(L,"divide by zero"),0): \
  549. luai_numdiv(a,b))
  550. #define luai_lnummod(a,b) \
  551. ((b)==0? \
  552. (luaG_runerror(L,"modulo by zero"),0): \
  553. luai_nummod(a,b))
  554. LUA_NUMBER luai_ipow(LUA_NUMBER, LUA_NUMBER);
  555. #define luai_numpow(a,b) (luai_ipow(a,b))
  556. #else
  557. #define luai_numdiv(a,b) ((a)/(b))
  558. #define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
  559. #define luai_lnumdiv(a,b) (luai_numdiv(a,b))
  560. #define luai_lnummod(a,b) (luai_nummod(a,b))
  561. #define luai_numpow(a,b) (pow(a,b))
  562. #endif
  563. #define luai_numunm(a) (-(a))
  564. #define luai_numeq(a,b) ((a)==(b))
  565. #define luai_numlt(a,b) ((a)<(b))
  566. #define luai_numle(a,b) ((a)<=(b))
  567. #define luai_numisnan(a) (!luai_numeq((a), (a)))
  568. #endif
  569. /*
  570. @@ lua_number2int is a macro to convert lua_Number to int.
  571. @@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
  572. ** CHANGE them if you know a faster way to convert a lua_Number to
  573. ** int (with any rounding method and without throwing errors) in your
  574. ** system. In Pentium machines, a naive typecast from double to int
  575. ** in C is extremely slow, so any alternative is worth trying.
  576. */
  577. /* On a Pentium, resort to a trick */
  578. #if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
  579. (defined(__i386) || defined (_M_IX86) || defined(__i386__))
  580. /* On a Microsoft compiler, use assembler */
  581. #if defined(_MSC_VER)
  582. #define lua_number2int(i,d) __asm fld d __asm fistp i
  583. #define lua_number2integer(i,n) lua_number2int(i, n)
  584. /* the next trick should work on any Pentium, but sometimes clashes
  585. with a DirectX idiosyncrasy */
  586. #else
  587. union luai_Cast { double l_d; long l_l; };
  588. #define lua_number2int(i,d) \
  589. { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
  590. #define lua_number2integer(i,n) lua_number2int(i, n)
  591. #endif
  592. /* this option always works, but may be slow */
  593. #else
  594. #define lua_number2int(i,d) ((i)=(int)(d))
  595. #define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
  596. #endif
  597. /* }================================================================== */
  598. /*
  599. @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
  600. ** CHANGE it if your system requires alignments larger than double. (For
  601. ** instance, if your system supports long doubles and they must be
  602. ** aligned in 16-byte boundaries, then you should add long double in the
  603. ** union.) Probably you do not need to change this.
  604. */
  605. #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
  606. /*
  607. @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
  608. ** CHANGE them if you prefer to use longjmp/setjmp even with C++
  609. ** or if want/don't to use _longjmp/_setjmp instead of regular
  610. ** longjmp/setjmp. By default, Lua handles errors with exceptions when
  611. ** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
  612. ** and with longjmp/setjmp otherwise.
  613. */
  614. #if defined(__cplusplus)
  615. /* C++ exceptions */
  616. #define LUAI_THROW(L,c) throw(c)
  617. #define LUAI_TRY(L,c,a) try { a } catch(...) \
  618. { if ((c)->status == 0) (c)->status = -1; }
  619. #define luai_jmpbuf int /* dummy variable */
  620. #elif defined(LUA_USE_ULONGJMP)
  621. /* in Unix, try _longjmp/_setjmp (more efficient) */
  622. #define LUAI_THROW(L,c) _longjmp((c)->b, 1)
  623. #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
  624. #define luai_jmpbuf jmp_buf
  625. #else
  626. /* default handling with long jumps */
  627. #define LUAI_THROW(L,c) longjmp((c)->b, 1)
  628. #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
  629. #define luai_jmpbuf jmp_buf
  630. #endif
  631. /*
  632. @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
  633. @* can do during pattern-matching.
  634. ** CHANGE it if you need more captures. This limit is arbitrary.
  635. */
  636. #define LUA_MAXCAPTURES 10
  637. /*
  638. @@ lua_tmpnam is the function that the OS library uses to create a
  639. @* temporary name.
  640. @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
  641. ** CHANGE them if you have an alternative to tmpnam (which is considered
  642. ** insecure) or if you want the original tmpnam anyway. By default, Lua
  643. ** uses tmpnam except when POSIX is available, where it uses mkstemp.
  644. */
  645. #if defined(loslib_c) || defined(luaall_c)
  646. #if defined(LUA_USE_MKSTEMP)
  647. #include <unistd.h>
  648. #define LUA_TMPNAMBUFSIZE 32
  649. #define lua_tmpnam(b,e) { \
  650. c_strcpy(b, "/tmp/lua_XXXXXX"); \
  651. e = mkstemp(b); \
  652. if (e != -1) close(e); \
  653. e = (e == -1); }
  654. #else
  655. #define LUA_TMPNAMBUFSIZE L_tmpnam
  656. #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
  657. #endif
  658. #endif
  659. /*
  660. @@ lua_popen spawns a new process connected to the current one through
  661. @* the file streams.
  662. ** CHANGE it if you have a way to implement it in your system.
  663. */
  664. #if defined(LUA_USE_POPEN)
  665. #define lua_popen(L,c,m) ((void)L, c_fflush(NULL), popen(c,m))
  666. #define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
  667. #elif defined(LUA_WIN)
  668. #define lua_popen(L,c,m) ((void)L, _popen(c,m))
  669. #define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
  670. #else
  671. #define lua_popen(L,c,m) ((void)((void)c, m), \
  672. luaL_error(L, LUA_QL("popen") " not supported"), (int)0)
  673. #define lua_pclose(L,file) ((void)((void)L, file), 0)
  674. #endif
  675. /*
  676. @@ LUA_DL_* define which dynamic-library system Lua should use.
  677. ** CHANGE here if Lua has problems choosing the appropriate
  678. ** dynamic-library system for your platform (either Windows' DLL, Mac's
  679. ** dyld, or Unix's dlopen). If your system is some kind of Unix, there
  680. ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
  681. ** it. To use dlopen you also need to adapt the src/Makefile (probably
  682. ** adding -ldl to the linker options), so Lua does not select it
  683. ** automatically. (When you change the makefile to add -ldl, you must
  684. ** also add -DLUA_USE_DLOPEN.)
  685. ** If you do not want any kind of dynamic library, undefine all these
  686. ** options.
  687. ** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
  688. */
  689. #if defined(LUA_USE_DLOPEN)
  690. #define LUA_DL_DLOPEN
  691. #endif
  692. #if defined(LUA_WIN)
  693. #define LUA_DL_DLL
  694. #endif
  695. /*
  696. @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
  697. @* (the data goes just *before* the lua_State pointer).
  698. ** CHANGE (define) this if you really need that. This value must be
  699. ** a multiple of the maximum alignment required for your machine.
  700. */
  701. #define LUAI_EXTRASPACE 0
  702. /*
  703. @@ luai_userstate* allow user-specific actions on threads.
  704. ** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
  705. ** extra when a thread is created/deleted/resumed/yielded.
  706. */
  707. #define luai_userstateopen(L) ((void)L)
  708. #define luai_userstateclose(L) ((void)L)
  709. #define luai_userstatethread(L,L1) ((void)L)
  710. #define luai_userstatefree(L) ((void)L)
  711. #define luai_userstateresume(L,n) ((void)L)
  712. #define luai_userstateyield(L,n) ((void)L)
  713. /*
  714. @@ LUA_INTFRMLEN is the length modifier for integer conversions
  715. @* in 'string.format'.
  716. @@ LUA_INTFRM_T is the integer type correspoding to the previous length
  717. @* modifier.
  718. ** CHANGE them if your system supports long long or does not support long.
  719. */
  720. #if defined(LUA_USELONGLONG) || defined(LUA_INTEGRAL_LONGLONG)
  721. #define LUA_INTFRMLEN "ll"
  722. #define LUA_INTFRM_T long long
  723. #else
  724. #define LUA_INTFRMLEN "l"
  725. #define LUA_INTFRM_T long
  726. #endif
  727. /* =================================================================== */
  728. /*
  729. ** Local configuration. You can use this space to add your redefinitions
  730. ** without modifying the main part of the file.
  731. */
  732. /* If you define the next macro you'll get the ability to set rotables as
  733. metatables for tables/userdata/types (but the VM might run slower)
  734. */
  735. #if (LUA_OPTIMIZE_MEMORY == 2) && !defined(LUA_CROSS_COMPILER)
  736. #define LUA_META_ROTABLES
  737. #endif
  738. #if LUA_OPTIMIZE_MEMORY == 2 && defined(LUA_USE_POPEN)
  739. #error "Pipes not supported in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)"
  740. #endif
  741. #endif