luaconf.h 26 KB

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