luaconf.h 13 KB

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