llimits.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. ** $Id: llimits.h,v 1.46 2002/10/08 18:46:08 roberto Exp roberto $
  3. ** Limits, basic types, and some other `installation-dependent' definitions
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef llimits_h
  7. #define llimits_h
  8. #include <limits.h>
  9. #include <stddef.h>
  10. #include "lua.h"
  11. /*
  12. ** try to find number of bits in an integer
  13. */
  14. #ifndef BITS_INT
  15. /* avoid overflows in comparison */
  16. #if INT_MAX-20 < 32760
  17. #define BITS_INT 16
  18. #else
  19. #if INT_MAX > 2147483640L
  20. /* machine has at least 32 bits */
  21. #define BITS_INT 32
  22. #else
  23. #error "you must define BITS_INT with number of bits in an integer"
  24. #endif
  25. #endif
  26. #endif
  27. /*
  28. ** the following types define integer types for values that may not
  29. ** fit in a `small int' (16 bits), but may waste space in a
  30. ** `large long' (64 bits). The current definitions should work in
  31. ** any machine, but may not be optimal.
  32. */
  33. /* an unsigned integer to hold hash values */
  34. typedef unsigned int lu_hash;
  35. /* its signed equivalent */
  36. typedef int ls_hash;
  37. /* an unsigned integer big enough to count the total memory used by Lua; */
  38. /* it should be at least as large as size_t */
  39. typedef unsigned long lu_mem;
  40. /* an integer big enough to count the number of strings in use */
  41. typedef long ls_nstr;
  42. /* an integer big enough to count the number of steps when calling a
  43. ** `count' hook */
  44. typedef long ls_count;
  45. /* chars used as small naturals (so that `char' is reserved for characteres) */
  46. typedef unsigned char lu_byte;
  47. #define MAX_SIZET ((size_t)(~(size_t)0)-2)
  48. #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
  49. /*
  50. ** conversion of pointer to integer
  51. ** this is for hashing only; there is no problem if the integer
  52. ** cannot hold the whole pointer value
  53. */
  54. #define IntPoint(p) ((lu_hash)(p))
  55. /* type to ensure maximum alignment */
  56. #ifndef LUSER_ALIGNMENT_T
  57. typedef union { double u; void *s; long l; } L_Umaxalign;
  58. #else
  59. typedef LUSER_ALIGNMENT_T L_Umaxalign;
  60. #endif
  61. /* result of `usual argument convertion' over lua_Number */
  62. #ifndef LUA_UACNUMBER
  63. typedef double l_uacNumber;
  64. #else
  65. typedef LUA_UACNUMBER l_uacNumber;
  66. #endif
  67. #ifndef lua_assert
  68. #define lua_assert(c) /* empty */
  69. #endif
  70. #ifndef check_exp
  71. #define check_exp(c,e) (e)
  72. #endif
  73. #ifndef UNUSED
  74. #define UNUSED(x) ((void)(x)) /* to avoid warnings */
  75. #endif
  76. #ifndef cast
  77. #define cast(t, exp) ((t)(exp))
  78. #endif
  79. /*
  80. ** type for virtual-machine instructions
  81. ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
  82. */
  83. typedef unsigned long Instruction;
  84. /* maximum depth for calls */
  85. #ifndef LUA_MAXCALLS
  86. #define LUA_MAXCALLS 4096
  87. #endif
  88. /* maximum size for the C stack */
  89. #ifndef LUA_MAXCSTACK
  90. #define LUA_MAXCSTACK 2048
  91. #endif
  92. /* maximum stack for a Lua function */
  93. #define MAXSTACK 250
  94. /* maximum number of variables declared in a function */
  95. #ifndef MAXVARS
  96. #define MAXVARS 200 /* arbitrary limit (<MAXSTACK) */
  97. #endif
  98. /* maximum number of upvalues per function */
  99. #ifndef MAXUPVALUES
  100. #define MAXUPVALUES 32
  101. #endif
  102. /* maximum number of parameters in a function */
  103. #ifndef MAXPARAMS
  104. #define MAXPARAMS 100 /* arbitrary limit (<MAXLOCALS) */
  105. #endif
  106. /* minimum size for the string table (must be power of 2) */
  107. #ifndef MINSTRTABSIZE
  108. #define MINSTRTABSIZE 32
  109. #endif
  110. /* minimum size for string buffer */
  111. #ifndef LUA_MINBUFFER
  112. #define LUA_MINBUFFER 32
  113. #endif
  114. #endif