luaconf.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. ** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $
  3. ** Configuration file for Lua
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef luaconf_h
  7. #define luaconf_h
  8. #include <limits.h>
  9. #include <stddef.h>
  10. #include <stdint.h>
  11. #include <stdbool.h>
  12. #include "user_config.h"
  13. /*
  14. ** ===================================================================
  15. ** The NodeMCU Lua environment support 2 compilation targets:
  16. **
  17. ** * The ESP8266 ans ESP32 embedded runtimes which are compiled using
  18. ** the GCC XTENSA cross-compiler toolchain.
  19. **
  20. ** * An extend version of the luac build for cross-compiling Lua
  21. ** sources for downloading to the ESP hardware. This is command
  22. ** line only and does not support any interactive dialogue or
  23. ** dynamically loaded libraries.
  24. **
  25. ** Note that we've removd the "how to fill this in comments so you
  26. ** can now see the actual content more easily. Also the two big
  27. ** boilerplate conditional sections "Configuration for Numbers" and
  28. ** "Dependencies with C99 and other C details" have been moved to
  29. ** the end of the include file to keep the information dense content
  30. ** at the front.
  31. ** ===================================================================
  32. */
  33. #ifdef __XTENSA__
  34. # define LUA_USE_ESP
  35. # define LUA_USE_ESP8266
  36. #else
  37. # define LUA_USE_HOST
  38. # define LUA_CROSS_COMPILER
  39. #endif
  40. #if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
  41. # define LUA_USE_WINDOWS /* enable goodies for regular Windows */
  42. //# define LUA_USE_C89 /* We only support the VS2013 C or later */
  43. #elif defined(__APPLE__)
  44. # define LUA_USE_MACOSX
  45. # define LUA_USE_POSIX
  46. #else
  47. # define LUA_USE_LINUX
  48. //# define LUA_USE_POSIX
  49. #endif
  50. #define LUA_NODEMCU_NOCLOADERS
  51. //#define LUA_C89_NUMBERS
  52. #define LUAI_BITSINT 32
  53. /* predefined options for LUA_INT_TYPE */
  54. #define LUA_INT_INT 1
  55. #define LUA_INT_LONG 2
  56. #define LUA_INT_LONGLONG 3L
  57. /* predefined options for LUA_FLOAT_TYPE */
  58. #define LUA_FLOAT_FLOAT 1
  59. #define LUA_FLOAT_DOUBLE 2
  60. #define LUA_FLOAT_LONGDOUBLE 3
  61. /*
  62. ** default configuration for 64-bit Lua ('long long' and 'double')
  63. */
  64. #if 0
  65. #if defined(LUA_32BITS)
  66. /*
  67. ** 32-bit integers and 'float'
  68. */
  69. # define LUA_INT_TYPE LUA_INT_INT
  70. # define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
  71. #else
  72. # define LUA_INT_TYPE LUA_INT_LONGLONG
  73. # define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
  74. #endif
  75. #endif
  76. #ifdef LUA_NUMBER_64BITS
  77. # define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
  78. # define LUA_INT_TYPE LUA_INT_LONGLONG
  79. #else
  80. # define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
  81. # define LUA_INT_TYPE LUA_INT_INT
  82. #endif
  83. #ifdef LUA_NUMBER_INTEGRAL
  84. #error LUA_NUMBER_INTEGRAL is not supported in LUA5.3 builds
  85. #endif
  86. /*
  87. ** Configuration for Paths.
  88. **
  89. ** LUA_CPATH_DEFAULT is the default path that Lua uses to look for
  90. ** Dynamic C libraries are not used and ditto LUA_CPATH_DEFAULT
  91. */
  92. #define LUA_PATH_SEP ";"
  93. #define LUA_PATH_MARK "?"
  94. #define LUA_EXEC_DIR "!"
  95. #define LUA_PATH_DEFAULT "?.lc;?.lua"
  96. #if defined(_WIN32)
  97. #define LUA_DIRSEP "\\"
  98. #else
  99. #define LUA_DIRSEP "/"
  100. #endif
  101. /*
  102. ** {==================================================================
  103. ** Marks for exported symbols in the C code
  104. ** ===================================================================
  105. **
  106. @@ LUA_API is a mark for all core API functions.
  107. @@ LUALIB_API is a mark for all auxiliary library functions.
  108. @@ LUAMOD_API is a mark for all standard library opening functions.
  109. */
  110. #define LUA_API extern
  111. #define LUALIB_API LUA_API
  112. #define LUAMOD_API LUALIB_API
  113. /*
  114. @@ LUAI_FUNC, LUAI_DDEF and LUAI_DDEC are used to mark visibilty when
  115. ** building lua as a shared library. Used to tag private inter-module
  116. ** Lua internal functions.
  117. */
  118. //#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
  119. #define LUAI_FUNC extern
  120. #define LUAI_DDEC LUAI_FUNC
  121. #define LUAI_DDEF
  122. /*
  123. ** {==================================================================
  124. ** Compatibility with previous versions
  125. ** ===================================================================
  126. */
  127. //#define LUA_COMPAT_MATHLIB // retains several deprecated functions in math.
  128. //#define LUA_COMPAT_BITLIB // bit32 is separately implemented as a NodeMCU lib
  129. //#define LUA_COMPAT_IPAIRS // enables __ipairs meta which isn't used in NodeMCU
  130. #define LUA_NODEMCU_COMPAT_MATHLIB /* retains NodeMCU subset of mathlib */
  131. #define LUA_COMPAT_APIINTCASTS /* needed to enable NodeMCU modules to work on */
  132. /* both Lua 5.1 and Lua 5.3 */
  133. #define LUA_COMPAT_UNPACK /* needed to support a global 'unpack' */
  134. #define LUA_COMPAT_LOADERS /* keeps 'package.loaders' as a synonym for */
  135. /* 'package.searchers'. Used in our libraries */
  136. #define LUA_COMPAT_LOADSTRING /* keeps loadstring(s) as synonym for load(s) */
  137. #if 0
  138. #define lua_cpcall(L,f,u) \ // Not used in our module code
  139. (lua_pushcfunction(L, (f)), \
  140. lua_pushlightuserdata(L,(u)), \
  141. lua_pcall(L,1,0,0))
  142. #endif
  143. //#define LUA_COMPAT_LOG10 // math.log10 not used in NodeMCU
  144. //#define LUA_COMPAT_MAXN // math.maxn not used
  145. /* Compatbililty for some API calls withdrawn in Lua53 */
  146. #define lua_strlen(L,i) lua_rawlen(L, (i))
  147. #define lua_objlen(L,i) lua_rawlen(L, (i))
  148. #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
  149. #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
  150. // #define LUA_COMPAT_MODULE // drop support for legacy module() format not used in our modules
  151. /**** May need to revisit this one *****/
  152. // #define LUA_COMPAT_FLOATSTRING // makes Lua format integral floats without a float mark
  153. #define LUA_KCONTEXT ptrdiff_t
  154. #define lua_getlocaledecpoint() '.'
  155. // #define LUA_NOCVTN2S // enable automatic coercion between
  156. // #define LUA_NOCVTS2N // strings and numbers
  157. #if defined(LUA_USE_APICHECK)
  158. #include <assert.h>
  159. #define luai_apicheck(l,e) assert(e)
  160. #endif
  161. #define LUA_EXTRASPACE (sizeof(void *)) // raw memory area associated with a Lua state
  162. #define LUAI_MAXSTACK 12000 // Maximum Lua stack size
  163. #define LUA_IDSIZE 60 // Maximum size for the description of the source
  164. /*
  165. @@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
  166. ** Change that if you do not want to use C locales. (Code using this
  167. ** macro must include header 'locale.h'.)
  168. */
  169. // of a function in debug information.
  170. #define LUAL_BUFFERSIZE 256 // NodeMCU setting because of stack limits
  171. #define LUA_QL(x) "'" x "'" // No longer used in lua53, but still used
  172. #define LUA_QS LUA_QL("%s") // in some of our apllication modules
  173. /*
  174. ** {==================================================================
  175. ** Other NodeMCU configuration.
  176. ** ===================================================================
  177. */
  178. #ifdef LUA_USE_ESP
  179. #define LUAI_USER_ALIGNMENT_T size_t
  180. #endif
  181. #define LUAI_GCPAUSE 110 /* 110% (wait memory to grow 10% before next gc) */
  182. /* }================================================================== */
  183. /*
  184. ** {==================================================================
  185. ** Configuration for Numbers.
  186. ** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
  187. ** satisfy your needs.
  188. ** ===================================================================
  189. **
  190. @@ LUA_NUMBER is the floating-point type used by Lua.
  191. @@ LUAI_UACNUMBER is the result of a 'default argument promotion' over a floating number.
  192. @@ l_mathlim(x) corrects limit name 'x' to the proper float type by prefixing it with one of FLT/DBL/LDBL.
  193. @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
  194. @@ LUA_NUMBER_FMT is the format for writing floats.
  195. @@ lua_number2str converts a float to a string.
  196. @@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
  197. @@ l_floor takes the floor of a float.
  198. @@ lua_str2number converts a decimal numeric string to a number.
  199. */
  200. /* The following definitions are good for most cases here */
  201. #define l_floor(x) (l_mathop(floor)(x))
  202. #define lua_number2str(s,sz,n) \
  203. l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
  204. /*
  205. @@ lua_numbertointeger converts a float number to an integer, or
  206. ** returns 0 if float is not within the range of a lua_Integer.
  207. ** (The range comparisons are tricky because of rounding. The tests
  208. ** here assume a two-complement representation, where MININTEGER always
  209. ** has an exact representation as a float; MAXINTEGER may not have one,
  210. ** and therefore its conversion to float may have an ill-defined value.)
  211. */
  212. #define lua_numbertointeger(n,p) \
  213. ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
  214. (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
  215. (*(p) = (LUA_INTEGER)(n), 1))
  216. /* now the variable definitions */
  217. #if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
  218. #define LUA_NUMBER float
  219. #define l_mathlim(n) (FLT_##n)
  220. #define LUAI_UACNUMBER double
  221. #define LUA_NUMBER_FRMLEN ""
  222. #define LUA_NUMBER_FMT "%.7g"
  223. #define l_mathop(op) op##f
  224. #define lua_str2number(s,p) strtof((s), (p))
  225. #elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
  226. #define LUA_NUMBER long double
  227. #define l_mathlim(n) (LDBL_##n)
  228. #define LUAI_UACNUMBER long double
  229. #define LUA_NUMBER_FRMLEN "L"
  230. #define LUA_NUMBER_FMT "%.19Lg"
  231. #define l_mathop(op) op##l
  232. #define lua_str2number(s,p) strtold((s), (p))
  233. #elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
  234. #define LUA_NUMBER double
  235. #define l_mathlim(n) (DBL_##n)
  236. #define LUAI_UACNUMBER double
  237. #define LUA_NUMBER_FRMLEN ""
  238. #define LUA_NUMBER_FMT "%.14g"
  239. #define l_mathop(op) op
  240. #define lua_str2number(s,p) strtod((s), (p))
  241. #else /* }{ */
  242. #error "numeric float type not defined"
  243. #endif /* } */
  244. #define LUA_FLOAT LUA_NUMBER
  245. /*
  246. @@ LUA_INTEGER is the integer type used by Lua.
  247. **
  248. @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
  249. **
  250. @@ LUAI_UACINT is the result of a 'default argument promotion'
  251. @@ over a lUA_INTEGER.
  252. @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
  253. @@ LUA_INTEGER_FMT is the format for writing integers.
  254. @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
  255. @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
  256. @@ lua_integer2str converts an integer to a string.
  257. */
  258. /* The following definitions are good for most cases here */
  259. #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
  260. #define LUAI_UACINT LUA_INTEGER
  261. #define lua_integer2str(s,sz,n) \
  262. l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
  263. /*
  264. ** use LUAI_UACINT here to avoid problems with promotions (which
  265. ** can turn a comparison between unsigneds into a signed comparison)
  266. */
  267. #define LUA_UNSIGNED unsigned LUAI_UACINT
  268. /* now the variable definitions */
  269. #if LUA_INT_TYPE == LUA_INT_INT /* { int */
  270. #define LUA_INTEGER int
  271. #define LUA_INTEGER_FRMLEN ""
  272. #define LUA_MAXINTEGER INT_MAX
  273. #define LUA_MININTEGER INT_MIN
  274. #elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
  275. #define LUA_INTEGER long
  276. #define LUA_INTEGER_FRMLEN "l"
  277. #define LUA_MAXINTEGER LONG_MAX
  278. #define LUA_MININTEGER LONG_MIN
  279. #elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
  280. /* use presence of macro LLONG_MAX as proxy for C99 compliance */
  281. #if defined(LLONG_MAX) /* { */
  282. /* use ISO C99 stuff */
  283. #define LUA_INTEGER long long
  284. #define LUA_INTEGER_FRMLEN "ll"
  285. #define LUA_MAXINTEGER LLONG_MAX
  286. #define LUA_MININTEGER LLONG_MIN
  287. #elif defined(LUA_USE_WINDOWS) /* }{ */
  288. /* in Windows, can use specific Windows types */
  289. #define LUA_INTEGER __int64
  290. #define LUA_INTEGER_FRMLEN "I64"
  291. #define LUA_MAXINTEGER _I64_MAX
  292. #define LUA_MININTEGER _I64_MIN
  293. #else /* }{ */
  294. #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
  295. or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
  296. #endif /* } */
  297. #else /* }{ */
  298. #error "numeric integer type not defined"
  299. #endif /* } */
  300. /* }================================================================== */
  301. /*
  302. ** {==================================================================
  303. ** Dependencies with C99 and other C details
  304. ** ===================================================================
  305. */
  306. /*
  307. @@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
  308. ** (All uses in Lua have only one format item.)
  309. */
  310. #if !defined(LUA_USE_C89)
  311. #define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
  312. #else
  313. #define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
  314. #endif
  315. /*
  316. @@ lua_strx2number converts an hexadecimal numeric string to a number.
  317. ** In C99, 'strtod' does that conversion. Otherwise, you can
  318. ** leave 'lua_strx2number' undefined and Lua will provide its own
  319. ** implementation.
  320. */
  321. #if !defined(LUA_USE_C89)
  322. #define lua_strx2number(s,p) lua_str2number(s,p)
  323. #endif
  324. /*
  325. @@ lua_pointer2str converts a pointer to a readable string in a
  326. ** non-specified way.
  327. */
  328. #define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
  329. /*
  330. @@ lua_number2strx converts a float to an hexadecimal numeric string.
  331. ** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
  332. ** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
  333. ** provide its own implementation.
  334. */
  335. #if !defined(LUA_USE_C89)
  336. #define lua_number2strx(L,b,sz,f,n) \
  337. ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
  338. #endif
  339. /*
  340. ** 'strtof' and 'opf' variants for math functions are not valid in
  341. ** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
  342. ** availability of these variants. ('math.h' is already included in
  343. ** all files that use these macros.)
  344. */
  345. #if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
  346. #undef l_mathop /* variants not available */
  347. #undef lua_str2number
  348. #define l_mathop(op) (lua_Number)op /* no variant */
  349. #define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
  350. #endif
  351. #undef lua_str2number
  352. #define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
  353. #define LUA_DEBUG_HOOK lua_debugbreak
  354. #endif