luaconf.h 25 KB

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