diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-03-29 11:30:16 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-03-29 11:30:16 -0300 |
| commit | 1c9c8869741897d67b64a27410f3856d34415e87 (patch) | |
| tree | 97e3f28479ce7e333729623abc511cee86544486 | |
| parent | ade585bdf9e286a0ec01796763ded6701c6b1a8f (diff) | |
| download | lua-1c9c8869741897d67b64a27410f3856d34415e87.tar.gz lua-1c9c8869741897d67b64a27410f3856d34415e87.tar.bz2 lua-1c9c8869741897d67b64a27410f3856d34415e87.zip | |
standard configuration should run out-of-the-box in "any" system
| -rw-r--r-- | loadlib.c | 21 | ||||
| -rw-r--r-- | luaconf.h | 305 |
2 files changed, 200 insertions, 126 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.21 2005/03/09 16:28:07 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.22 2005/03/18 16:38:43 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -44,7 +44,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym); | |||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | #if defined(LUA_USE_DLOPEN) | 47 | #if defined(LUA_DL_DLOPEN) |
| 48 | /* | 48 | /* |
| 49 | ** {======================================================================== | 49 | ** {======================================================================== |
| 50 | ** This is an implementation of loadlib based on the dlfcn interface. | 50 | ** This is an implementation of loadlib based on the dlfcn interface. |
| @@ -78,7 +78,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | |||
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | #elif defined(LUA_USE_DLL) | 81 | #elif defined(LUA_DL_DLL) |
| 82 | /* | 82 | /* |
| 83 | ** {====================================================================== | 83 | ** {====================================================================== |
| 84 | ** This is an implementation of loadlib for Windows using native functions. | 84 | ** This is an implementation of loadlib for Windows using native functions. |
| @@ -93,7 +93,7 @@ static void pusherror (lua_State *L) { | |||
| 93 | char buffer[128]; | 93 | char buffer[128]; |
| 94 | if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, | 94 | if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, |
| 95 | NULL, error, 0, buffer, sizeof(buffer), NULL)) | 95 | NULL, error, 0, buffer, sizeof(buffer), NULL)) |
| 96 | lua_pushstring(L,buffer); | 96 | lua_pushstring(L, buffer); |
| 97 | else | 97 | else |
| 98 | lua_pushfstring(L, "system error %d\n", error); | 98 | lua_pushfstring(L, "system error %d\n", error); |
| 99 | } | 99 | } |
| @@ -120,7 +120,7 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | |||
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | 122 | ||
| 123 | #elif defined(LUA_USE_DYLD) | 123 | #elif defined(LUA_DL_DYLD) |
| 124 | /* | 124 | /* |
| 125 | ** {====================================================================== | 125 | ** {====================================================================== |
| 126 | ** Native Mac OS X / Darwin Implementation | 126 | ** Native Mac OS X / Darwin Implementation |
| @@ -212,6 +212,13 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | |||
| 212 | #define LIB_FAIL "absent" | 212 | #define LIB_FAIL "absent" |
| 213 | 213 | ||
| 214 | 214 | ||
| 215 | #if defined(__ELF__) || defined(__sun) || defined(sgi) || defined(__hpux) | ||
| 216 | #define DLMSG "your system was not properly installed, " \ | ||
| 217 | "so it cannot run `loadlib'; check your installation" | ||
| 218 | #else | ||
| 219 | #define DLMSG "`loadlib' not supported" | ||
| 220 | #endif | ||
| 221 | |||
| 215 | static void ll_unloadlib (void *lib) { | 222 | static void ll_unloadlib (void *lib) { |
| 216 | (void)lib; /* to avoid warnings */ | 223 | (void)lib; /* to avoid warnings */ |
| 217 | } | 224 | } |
| @@ -219,14 +226,14 @@ static void ll_unloadlib (void *lib) { | |||
| 219 | 226 | ||
| 220 | static void *ll_load (lua_State *L, const char *path) { | 227 | static void *ll_load (lua_State *L, const char *path) { |
| 221 | (void)path; /* to avoid warnings */ | 228 | (void)path; /* to avoid warnings */ |
| 222 | lua_pushliteral(L,"`loadlib' not supported"); | 229 | lua_pushliteral(L, DLMSG); |
| 223 | return NULL; | 230 | return NULL; |
| 224 | } | 231 | } |
| 225 | 232 | ||
| 226 | 233 | ||
| 227 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { | 234 | static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { |
| 228 | (void)lib; (void)sym; /* to avoid warnings */ | 235 | (void)lib; (void)sym; /* to avoid warnings */ |
| 229 | lua_pushliteral(L,"`loadlib' not supported"); | 236 | lua_pushliteral(L, DLMSG); |
| 230 | return NULL; | 237 | return NULL; |
| 231 | } | 238 | } |
| 232 | 239 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: luaconf.h,v 1.37 2005/03/18 18:55:45 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.38 2005/03/21 18:12:07 roberto Exp roberto $ |
| 3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -24,10 +24,10 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | /* | 26 | /* |
| 27 | *@ LUA_PATH_DEFAULT is the default path that Lua uses to look for | 27 | @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for |
| 28 | ** Lua libraries. | 28 | @* Lua libraries. |
| 29 | *@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for | 29 | @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for |
| 30 | ** C libraries. | 30 | @* C libraries. |
| 31 | ** CHANGE them if your machine has a non-conventional directory | 31 | ** CHANGE them if your machine has a non-conventional directory |
| 32 | ** hierarchy or if you want to install your libraries in | 32 | ** hierarchy or if you want to install your libraries in |
| 33 | ** non-conventional directories. | 33 | ** non-conventional directories. |
| @@ -53,7 +53,7 @@ | |||
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | /* | 55 | /* |
| 56 | *@ LUA_DIRSEP is the directory separator (for submodules). | 56 | @@ LUA_DIRSEP is the directory separator (for submodules). |
| 57 | ** CHANGE it if your machine does not use "/" as the directory separator | 57 | ** CHANGE it if your machine does not use "/" as the directory separator |
| 58 | ** and is not Windows. (On Windows Lua automatically uses "\".) | 58 | ** and is not Windows. (On Windows Lua automatically uses "\".) |
| 59 | */ | 59 | */ |
| @@ -65,7 +65,7 @@ | |||
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | /* | 67 | /* |
| 68 | *@ LUA_PATHSEP is the character that separates templates in a path. | 68 | @@ LUA_PATHSEP is the character that separates templates in a path. |
| 69 | ** CHANGE it if for some reason your system cannot use a | 69 | ** CHANGE it if for some reason your system cannot use a |
| 70 | ** semicolon. (E.g., a semicolon may be a too common character in | 70 | ** semicolon. (E.g., a semicolon may be a too common character in |
| 71 | ** file/directory names.) Probably you do not need to change this. | 71 | ** file/directory names.) Probably you do not need to change this. |
| @@ -74,8 +74,8 @@ | |||
| 74 | 74 | ||
| 75 | 75 | ||
| 76 | /* | 76 | /* |
| 77 | *@ LUA_PATH_MARK is ths string that marks the substitution points in a | 77 | @@ LUA_PATH_MARK is ths string that marks the substitution points in a |
| 78 | ** template. | 78 | @* template. |
| 79 | ** CHANGE it if for some reason your system cannot use an interogation | 79 | ** CHANGE it if for some reason your system cannot use an interogation |
| 80 | ** mark. (E.g., an interogation mark may be a too common character in | 80 | ** mark. (E.g., an interogation mark may be a too common character in |
| 81 | ** file/directory names.) Probably you do not need to change this. | 81 | ** file/directory names.) Probably you do not need to change this. |
| @@ -84,7 +84,7 @@ | |||
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | /* | 86 | /* |
| 87 | *@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. | 87 | @@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger. |
| 88 | ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most | 88 | ** CHANGE that if ptrdiff_t is not adequate on your machine. (On most |
| 89 | ** machines, ptrdiff_t gives a good choice between int or long.) | 89 | ** machines, ptrdiff_t gives a good choice between int or long.) |
| 90 | */ | 90 | */ |
| @@ -92,30 +92,36 @@ | |||
| 92 | 92 | ||
| 93 | 93 | ||
| 94 | /* | 94 | /* |
| 95 | *@ LUA_API is a mark for all core API functions. | 95 | @@ LUA_API is a mark for all core API functions. |
| 96 | *@ LUALIB_API is a mark for all standard library functions. | 96 | @@ LUALIB_API is a mark for all standard library functions. |
| 97 | ** CHANGE them if you need to define those functions in some special way. | 97 | ** CHANGE them if you need to define those functions in some special way. |
| 98 | ** For instance, if you want to create two Windows DLLs, one with the | 98 | ** For instance, if you want to create two Windows DLLs, one with the |
| 99 | ** core, the other with the libraries, you may want to use the following | 99 | ** core, the other with the libraries, you may want to use the following |
| 100 | ** definition: | 100 | ** definition (define LUA_BUILD_AS_DLL to get it). |
| 101 | ** | ||
| 102 | ** #ifdef LUA_CORE | ||
| 103 | ** #define LUA_API __declspec(__dllexport) | ||
| 104 | ** #else | ||
| 105 | ** #define LUA_API __declspec(__dllimport) | ||
| 106 | ** #endif | ||
| 107 | ** #ifdef LUA_LIB | ||
| 108 | ** #define LUALIB_API __declspec(__dllexport) | ||
| 109 | ** #else | ||
| 110 | ** #define LUALIB_API __declspec(__dllimport) | ||
| 111 | ** #endif | ||
| 112 | */ | 101 | */ |
| 102 | #if defined (LUA_BUILD_AS_DLL) | ||
| 103 | |||
| 104 | #if defined(LUA_CORE) | ||
| 105 | #define LUA_API __declspec(__dllexport) | ||
| 106 | #else | ||
| 107 | #define LUA_API __declspec(__dllimport) | ||
| 108 | #endif | ||
| 109 | #if defined(LUA_LIB) | ||
| 110 | #define LUALIB_API __declspec(__dllexport) | ||
| 111 | #else | ||
| 112 | #define LUALIB_API __declspec(__dllimport) | ||
| 113 | #endif | ||
| 114 | |||
| 115 | #else | ||
| 116 | |||
| 113 | #define LUA_API extern | 117 | #define LUA_API extern |
| 114 | #define LUALIB_API extern | 118 | #define LUALIB_API extern |
| 115 | 119 | ||
| 120 | #endif | ||
| 121 | |||
| 116 | 122 | ||
| 117 | /* | 123 | /* |
| 118 | *@ lua_assert describes the internal assertions in Lua. | 124 | @@ lua_assert describes the internal assertions in Lua. |
| 119 | ** CHANGE that only if you need to debug Lua. | 125 | ** CHANGE that only if you need to debug Lua. |
| 120 | */ | 126 | */ |
| 121 | #define lua_assert(c) ((void)0) | 127 | #define lua_assert(c) ((void)0) |
| @@ -128,13 +134,18 @@ | |||
| 128 | ** =================================================================== | 134 | ** =================================================================== |
| 129 | */ | 135 | */ |
| 130 | 136 | ||
| 131 | #ifdef lua_c | 137 | #if defined(lua_c) || defined(luaall_c) |
| 132 | 138 | ||
| 133 | /* CONFIG: definition of isatty */ | 139 | /* |
| 134 | #ifdef _POSIX_C_SOURCE | 140 | @@ lua_stdin_is_tty is a function to detect whether the standard input is |
| 141 | @* a `tty' (that is, is interactive). | ||
| 142 | ** CHANGE it if you have a better definition for non-POSIX/non-Windows | ||
| 143 | ** systems. | ||
| 144 | */ | ||
| 145 | #if !defined(__STRICT_ANSI__) && defined(_POSIX_C_SOURCE) | ||
| 135 | #include <unistd.h> | 146 | #include <unistd.h> |
| 136 | #define lua_stdin_is_tty() isatty(0) | 147 | #define lua_stdin_is_tty() isatty(0) |
| 137 | #elif defined(_WIN32) | 148 | #elif !defined(__STRICT_ANSI__) && defined(_WIN32) |
| 138 | #include <io.h> | 149 | #include <io.h> |
| 139 | #include <stdio.h> | 150 | #include <stdio.h> |
| 140 | #define lua_stdin_is_tty() _isatty(_fileno(stdin)) | 151 | #define lua_stdin_is_tty() _isatty(_fileno(stdin)) |
| @@ -143,47 +154,81 @@ | |||
| 143 | #endif | 154 | #endif |
| 144 | 155 | ||
| 145 | 156 | ||
| 157 | /* | ||
| 158 | @@ LUA_PROMPT is the default prompt used by stand-alone Lua. | ||
| 159 | @@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua. | ||
| 160 | ** CHANGE them if you want different prompts. (You can also change the | ||
| 161 | ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) | ||
| 162 | */ | ||
| 146 | #define LUA_PROMPT "> " | 163 | #define LUA_PROMPT "> " |
| 147 | #define LUA_PROMPT2 ">> " | 164 | #define LUA_PROMPT2 ">> " |
| 165 | |||
| 166 | |||
| 167 | /* | ||
| 168 | @@ LUA_PROGNAME is the default name for the stand-alone Lua program. | ||
| 169 | ** CHANGE it if your stand-alone interpreter has a different name and | ||
| 170 | ** your system is not able to detect that name automatically. | ||
| 171 | */ | ||
| 148 | #define LUA_PROGNAME "lua" | 172 | #define LUA_PROGNAME "lua" |
| 149 | 173 | ||
| 174 | |||
| 150 | /* | 175 | /* |
| 151 | *@ LUA_MAXINPUT is the maximum length for an input line | 176 | @@ LUA_MAXINPUT is the maximum length for an input line |
| 152 | ** CHANGE it if you need longer lines. | 177 | ** CHANGE it if you need longer lines. |
| 153 | */ | 178 | */ |
| 154 | #define LUA_MAXINPUT 512 | 179 | #define LUA_MAXINPUT 512 |
| 155 | 180 | ||
| 156 | 181 | ||
| 157 | /* | 182 | /* |
| 158 | *@ lua_readline defines how to show a prompt and then read a line from | 183 | @@ lua_readline defines how to show a prompt and then read a line from |
| 159 | ** the standard input. | 184 | @* the standard input. |
| 160 | *@ lua_saveline defines how to "save" a read line. | 185 | @@ lua_saveline defines how to "save" a read line. |
| 186 | @@ lua_freeline defines how to free a line read by lua_readline. | ||
| 161 | ** CHANGE them if you want to improve this functionality (e.g., using GNU | 187 | ** CHANGE them if you want to improve this functionality (e.g., using GNU |
| 162 | ** readline and history facilities). (Lua already tries to use those | 188 | ** readline and history facilities). |
| 163 | ** facilities when it detects a GNU compiler.) | ||
| 164 | */ | 189 | */ |
| 165 | #ifdef __GNUC__ | 190 | #if !defined(__STRICT_ANSI__) && defined(LUA_USE_READLINE) |
| 191 | #include <stdio.h> | ||
| 166 | #include <readline/readline.h> | 192 | #include <readline/readline.h> |
| 167 | #include <readline/history.h> | 193 | #include <readline/history.h> |
| 168 | #define lua_readline(L,b,p) (((b)=readline(p)) != NULL) | 194 | #define lua_readline(L,b,p) (((b)=readline(p)) != NULL) |
| 169 | #define lua_saveline(L,idx) \ | 195 | #define lua_saveline(L,idx) \ |
| 170 | if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ | 196 | if (lua_strlen(L,idx) > 0) /* non-empty line? */ \ |
| 171 | add_history(lua_tostring(L, idx)); /* add it to history */ | 197 | add_history(lua_tostring(L, idx)); /* add it to history */ |
| 198 | #define lua_freeline(L,b) free(b) | ||
| 172 | #else | 199 | #else |
| 173 | #define lua_readline(L,b,p) \ | 200 | #define lua_readline(L,b,p) \ |
| 174 | (fputs(p, stdout), fflush(stdout), /* show prompt */ \ | 201 | (fputs(p, stdout), fflush(stdout), /* show prompt */ \ |
| 175 | fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ | 202 | fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */ |
| 176 | #define lua_saveline(L,idx) ((void)0) | 203 | #define lua_saveline(L,idx) ((void)0) |
| 204 | #define lua_freeline(L,b) ((void)0) | ||
| 177 | #endif | 205 | #endif |
| 178 | 206 | ||
| 179 | |||
| 180 | |||
| 181 | #endif | 207 | #endif |
| 182 | 208 | ||
| 183 | /* }================================================================== */ | 209 | /* }================================================================== */ |
| 184 | 210 | ||
| 185 | 211 | ||
| 186 | /* | 212 | /* |
| 213 | @@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles | ||
| 214 | @* as a percentage. | ||
| 215 | ** CHANGE it if you want the GC to run faster or slower (higher | ||
| 216 | ** values mean larger pauses which mean slower collection.) | ||
| 217 | */ | ||
| 218 | #define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */ | ||
| 219 | |||
| 220 | |||
| 221 | /* | ||
| 222 | @@ LUAI_GCMUL defines the speed of garbage collection relative to | ||
| 223 | @* memory allocation as a percentage. | ||
| 224 | ** CHANGE it if you want to change the granularity of the garbage | ||
| 225 | ** collection. (Higher values mean coarser collections. 0 represents | ||
| 226 | ** infinity, where each step performs a full collection.) | ||
| 227 | */ | ||
| 228 | #define LUAI_GCMUL 200 /* GC runs `twice the speed' of memory allocation */ | ||
| 229 | |||
| 230 | |||
| 231 | /* | ||
| 187 | ** CHANGE here (undefining both luaL_getn and luaL_setn) if you want | 232 | ** CHANGE here (undefining both luaL_getn and luaL_setn) if you want |
| 188 | ** exact compatibility with the behavior of setn/getn in Lua 5.0. | 233 | ** exact compatibility with the behavior of setn/getn in Lua 5.0. |
| 189 | */ | 234 | */ |
| @@ -192,23 +237,25 @@ | |||
| 192 | 237 | ||
| 193 | 238 | ||
| 194 | /* | 239 | /* |
| 240 | @@ luai_apicheck is the assert macro used by the Lua-C API. | ||
| 195 | ** CHANGE luai_apicheck if you want Lua to perform some checks in the | 241 | ** CHANGE luai_apicheck if you want Lua to perform some checks in the |
| 196 | ** parameters it gets from API calls. This may slow down the interpreter | 242 | ** parameters it gets from API calls. This may slow down the interpreter |
| 197 | ** a bit, but may be quite useful when debugging C code that interfaces | 243 | ** a bit, but may be quite useful when debugging C code that interfaces |
| 198 | ** with Lua. A useful redefinition may be like this: | 244 | ** with Lua. A useful redefinition is to use assert.h. |
| 199 | ** | ||
| 200 | ** #include <assert.h> | ||
| 201 | ** #define luai_apicheck(L,o) assert(o) | ||
| 202 | ** | ||
| 203 | ** (By default lua_assert is empty, so luai_apicheck is also empty.) | ||
| 204 | */ | 245 | */ |
| 246 | #if defined(LUA_USE_APICHECK) | ||
| 247 | #include <assert.h> | ||
| 248 | #define luai_apicheck(L,o) assert(o) | ||
| 249 | #else | ||
| 250 | /* (By default lua_assert is empty, so luai_apicheck is also empty.) */ | ||
| 205 | #define luai_apicheck(L,o) lua_assert(o) | 251 | #define luai_apicheck(L,o) lua_assert(o) |
| 252 | #endif | ||
| 206 | 253 | ||
| 207 | 254 | ||
| 208 | /* | 255 | /* |
| 256 | @@ LUAI_BITSINT defines the number of bits in an int. | ||
| 209 | ** CHANGE here if Lua cannot automatically detect the number of bits of | 257 | ** CHANGE here if Lua cannot automatically detect the number of bits of |
| 210 | ** your machine. (In that case, simply define LUA_BITSINT.) Probably you | 258 | ** your machine. Probably you do not need to change this. |
| 211 | ** do not need to change this. | ||
| 212 | */ | 259 | */ |
| 213 | /* avoid overflows in comparison */ | 260 | /* avoid overflows in comparison */ |
| 214 | #if INT_MAX-20 < 32760 | 261 | #if INT_MAX-20 < 32760 |
| @@ -222,16 +269,16 @@ | |||
| 222 | 269 | ||
| 223 | 270 | ||
| 224 | /* | 271 | /* |
| 225 | *@ LUAI_UINT32 is an unsigned integer with at least 32 bits. | 272 | @@ LUAI_UINT32 is an unsigned integer with at least 32 bits. |
| 226 | *@ LUAI_INT32 is an signed integer with at least 32 bits. | 273 | @@ LUAI_INT32 is an signed integer with at least 32 bits. |
| 227 | *@ LUAI_UMEM is an an unsigned integer big enough to count the total | 274 | @@ LUAI_UMEM is an an unsigned integer big enough to count the total |
| 228 | ** memory used by Lua. | 275 | @* memory used by Lua. |
| 229 | *@ LUAI_MEM is an a signed integer big enough to count the total memory | 276 | @@ LUAI_MEM is an a signed integer big enough to count the total memory |
| 230 | ** used by Lua. | 277 | @* used by Lua. |
| 231 | ** CHANGE here if for some weird reason the default definitions are not | 278 | ** CHANGE here if for some weird reason the default definitions are not |
| 232 | ** good enough for your machine. The `else' definition always works, but | 279 | ** good enough for your machine. (The `else' definition always works, |
| 233 | ** may waste space on machines with 64-bit longs. Probably you do not | 280 | ** but may waste space on machines with 64-bit longs.) Probably you do |
| 234 | ** need to change this. | 281 | ** not need to change this. |
| 235 | */ | 282 | */ |
| 236 | #if LUAI_BITSINT >= 32 | 283 | #if LUAI_BITSINT >= 32 |
| 237 | #define LUAI_UINT32 unsigned int | 284 | #define LUAI_UINT32 unsigned int |
| @@ -250,7 +297,7 @@ | |||
| 250 | 297 | ||
| 251 | 298 | ||
| 252 | /* | 299 | /* |
| 253 | *@ LUAI_MAXCALLS limits the number of nested calls. | 300 | @@ LUAI_MAXCALLS limits the number of nested calls. |
| 254 | ** CHANGE it if you need really deep recursive calls. This limit is | 301 | ** CHANGE it if you need really deep recursive calls. This limit is |
| 255 | ** arbitrary; its only purpose is to stop infinite recursion before | 302 | ** arbitrary; its only purpose is to stop infinite recursion before |
| 256 | ** exhausting memory. | 303 | ** exhausting memory. |
| @@ -259,7 +306,7 @@ | |||
| 259 | 306 | ||
| 260 | 307 | ||
| 261 | /* | 308 | /* |
| 262 | *@ LUAI_MAXCSTACK limits the number of slots that a C function can use. | 309 | @@ LUAI_MAXCSTACK limits the number of slots that a C function can use. |
| 263 | ** CHANGE it if you need lots of (Lua) stack space for your C | 310 | ** CHANGE it if you need lots of (Lua) stack space for your C |
| 264 | ** functions. This limit is arbitrary; its only purpose is to stop C | 311 | ** functions. This limit is arbitrary; its only purpose is to stop C |
| 265 | ** functions to consume unlimited stack space. | 312 | ** functions to consume unlimited stack space. |
| @@ -283,41 +330,41 @@ | |||
| 283 | 330 | ||
| 284 | 331 | ||
| 285 | /* | 332 | /* |
| 286 | *@ LUAI_MAXCCALLS is the maximum depth for nested C calls (unsigned short). | 333 | @@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short). |
| 287 | */ | 334 | */ |
| 288 | #define LUAI_MAXCCALLS 200 | 335 | #define LUAI_MAXCCALLS 200 |
| 289 | 336 | ||
| 290 | 337 | ||
| 291 | /* | 338 | /* |
| 292 | *@ LUAI_MAXPARSERLEVEL is the maximum number of syntactical nested | 339 | @@ LUAI_MAXPARSERLEVEL is the maximum number of syntactical nested |
| 293 | ** non-terminals in a program. | 340 | @* non-terminals in a program. |
| 294 | */ | 341 | */ |
| 295 | #define LUAI_MAXPARSERLEVEL 200 | 342 | #define LUAI_MAXPARSERLEVEL 200 |
| 296 | 343 | ||
| 297 | 344 | ||
| 298 | /* | 345 | /* |
| 299 | *@ LUAI_MAXVARS is the maximum number of local variables per function | 346 | @@ LUAI_MAXVARS is the maximum number of local variables per function |
| 300 | ** (must be smaller than 250). | 347 | @* (must be smaller than 250). |
| 301 | */ | 348 | */ |
| 302 | #define LUAI_MAXVARS 200 | 349 | #define LUAI_MAXVARS 200 |
| 303 | 350 | ||
| 304 | 351 | ||
| 305 | /* | 352 | /* |
| 306 | *@ LUAI_MAXUPVALUES is the maximum number of upvalues per function | 353 | @@ LUAI_MAXUPVALUES is the maximum number of upvalues per function |
| 307 | ** (must be smaller than 250). | 354 | @* (must be smaller than 250). |
| 308 | */ | 355 | */ |
| 309 | #define LUAI_MAXUPVALUES 60 | 356 | #define LUAI_MAXUPVALUES 60 |
| 310 | 357 | ||
| 311 | 358 | ||
| 312 | /* | 359 | /* |
| 313 | *@ LUAI_MAXEXPWHILE is the maximum size of code for expressions | 360 | @@ LUAI_MAXEXPWHILE is the maximum size of code for expressions |
| 314 | ** controling a `while' loop. | 361 | @* controling a `while' loop. |
| 315 | */ | 362 | */ |
| 316 | #define LUAI_MAXEXPWHILE 100 | 363 | #define LUAI_MAXEXPWHILE 100 |
| 317 | 364 | ||
| 318 | 365 | ||
| 319 | /* | 366 | /* |
| 320 | *@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. | 367 | @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. |
| 321 | */ | 368 | */ |
| 322 | #define LUAL_BUFFERSIZE BUFSIZ | 369 | #define LUAL_BUFFERSIZE BUFSIZ |
| 323 | 370 | ||
| @@ -326,19 +373,19 @@ | |||
| 326 | 373 | ||
| 327 | 374 | ||
| 328 | /* | 375 | /* |
| 329 | *@ lua_number2int is a macro to convert lua_Number to int. | 376 | @@ lua_number2int is a macro to convert lua_Number to int. |
| 330 | ** CHANGE that if you know a faster way to convert a lua_Number to | 377 | ** CHANGE that if you know a faster way to convert a lua_Number to |
| 331 | ** int (with any rounding method and without throwing errors) in your | 378 | ** int (with any rounding method and without throwing errors) in your |
| 332 | ** system. In Pentium machines, a naive typecast from doulbe to int | 379 | ** system. In Pentium machines, a naive typecast from double to int |
| 333 | ** in C is extremely slow, so any alternative is worth trying. | 380 | ** in C is extremely slow, so any alternative is worth trying. |
| 334 | */ | 381 | */ |
| 335 | 382 | ||
| 336 | /* On a GNU/Pentium, resort to assembler */ | 383 | /* On a GNU/Pentium, resort to assembler */ |
| 337 | #if defined(__GNUC__) && defined(__i386) | 384 | #if !defined(__STRICT_ANSI__) && defined(__GNUC__) && defined(__i386) |
| 338 | #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st") | 385 | #define lua_number2int(i,d) __asm__ ("fistpl %0":"=m"(i):"t"(d):"st") |
| 339 | 386 | ||
| 340 | /* On Windows/Pentium, resort to assembler */ | 387 | /* On Windows/Pentium, resort to assembler */ |
| 341 | #elif defined(_MSC_VER) && defined(_M_IX86) | 388 | #elif !defined(__STRICT_ANSI__) && defined(_MSC_VER) && defined(_M_IX86) |
| 342 | #pragma warning(disable: 4514) | 389 | #pragma warning(disable: 4514) |
| 343 | __inline int l_lrint (double flt) | 390 | __inline int l_lrint (double flt) |
| 344 | { int i; | 391 | { int i; |
| @@ -351,7 +398,8 @@ __inline int l_lrint (double flt) | |||
| 351 | #define lua_number2int(i,d) ((i)=l_lrint((d))) | 398 | #define lua_number2int(i,d) ((i)=l_lrint((d))) |
| 352 | 399 | ||
| 353 | /* on Pentium machines compliant with C99, you can try lrint */ | 400 | /* on Pentium machines compliant with C99, you can try lrint */ |
| 354 | #elif defined (__i386) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199900L) | 401 | #elif defined (__i386) && defined(__STDC_VERSION__) && \ |
| 402 | (__STDC_VERSION__ >= 199900L) | ||
| 355 | #define lua_number2int(i,d) ((i)=lrint(d)) | 403 | #define lua_number2int(i,d) ((i)=lrint(d)) |
| 356 | 404 | ||
| 357 | /* this option always work, but may be slow */ | 405 | /* this option always work, but may be slow */ |
| @@ -362,7 +410,7 @@ __inline int l_lrint (double flt) | |||
| 362 | 410 | ||
| 363 | 411 | ||
| 364 | /* | 412 | /* |
| 365 | *@ lua_number2integer is a macro to convert lua_Number to lua_Integer. | 413 | @@ lua_number2integer is a macro to convert lua_Number to lua_Integer. |
| 366 | ** CHANGE (see lua_number2int). | 414 | ** CHANGE (see lua_number2int). |
| 367 | */ | 415 | */ |
| 368 | /* On a GNU or Windows/Pentium, resort to assembler */ | 416 | /* On a GNU or Windows/Pentium, resort to assembler */ |
| @@ -388,20 +436,20 @@ __inline int l_lrint (double flt) | |||
| 388 | 436 | ||
| 389 | 437 | ||
| 390 | /* | 438 | /* |
| 391 | *@ LUA_NUMBER is the type of numbers in Lua. | 439 | @@ LUA_NUMBER is the type of numbers in Lua. |
| 392 | *@ LUAI_UACNUMBER is the result of an `usual argument conversion' | 440 | @@ LUAI_UACNUMBER is the result of an `usual argument conversion' |
| 393 | ** over a number. | 441 | @* over a number. |
| 394 | */ | 442 | */ |
| 395 | #define LUA_NUMBER double | 443 | #define LUA_NUMBER double |
| 396 | #define LUAI_UACNUMBER LUA_NUMBER | 444 | #define LUAI_UACNUMBER LUA_NUMBER |
| 397 | 445 | ||
| 398 | 446 | ||
| 399 | /* | 447 | /* |
| 400 | *@ LUA_NUMBER_SCAN is the format for reading numbers. | 448 | @@ LUA_NUMBER_SCAN is the format for reading numbers. |
| 401 | *@ LUA_NUMBER_FMT is the format for writing numbers. | 449 | @@ LUA_NUMBER_FMT is the format for writing numbers. |
| 402 | *@ lua_number2str converts a number to a string. | 450 | @@ lua_number2str converts a number to a string. |
| 403 | *@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. | 451 | @@ LUAI_MAXNUMBER2STR is maximum size of previous conversion. |
| 404 | *@ lua_str2number converts a string to a number. | 452 | @@ lua_str2number converts a string to a number. |
| 405 | */ | 453 | */ |
| 406 | #define LUA_NUMBER_SCAN "%lf" | 454 | #define LUA_NUMBER_SCAN "%lf" |
| 407 | #define LUA_NUMBER_FMT "%.14g" | 455 | #define LUA_NUMBER_FMT "%.14g" |
| @@ -411,7 +459,7 @@ __inline int l_lrint (double flt) | |||
| 411 | 459 | ||
| 412 | 460 | ||
| 413 | /* | 461 | /* |
| 414 | *@ The luai_num* macros define the primitive operations over numbers. | 462 | @@ The luai_num* macros define the primitive operations over numbers. |
| 415 | */ | 463 | */ |
| 416 | #define luai_numadd(a,b) ((a)+(b)) | 464 | #define luai_numadd(a,b) ((a)+(b)) |
| 417 | #define luai_numsub(a,b) ((a)-(b)) | 465 | #define luai_numsub(a,b) ((a)-(b)) |
| @@ -428,7 +476,7 @@ __inline int l_lrint (double flt) | |||
| 428 | 476 | ||
| 429 | 477 | ||
| 430 | /* | 478 | /* |
| 431 | *@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. | 479 | @@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment. |
| 432 | ** CHANGE it if your system requires alignments larger than double. (For | 480 | ** CHANGE it if your system requires alignments larger than double. (For |
| 433 | ** instance, if your system supports long double and those long doubles | 481 | ** instance, if your system supports long double and those long doubles |
| 434 | ** must be aligned in 16-byte boundaries, then you should add long | 482 | ** must be aligned in 16-byte boundaries, then you should add long |
| @@ -438,43 +486,55 @@ __inline int l_lrint (double flt) | |||
| 438 | 486 | ||
| 439 | 487 | ||
| 440 | /* | 488 | /* |
| 441 | *@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. | 489 | @@ LUAI_THROW/LUAI_TRY define how Lua does exception handling. |
| 442 | ** CHANGE them if you prefer to use longjmp/setjmp even with C++. By | 490 | ** CHANGE them if you prefer to use longjmp/setjmp even with C++ or |
| 443 | ** default, Lua handles errors with longjmp/setjmp when compiling as C | 491 | ** if want/don't want to use _longjmp/_setjmp instead of regular |
| 444 | ** code and with exceptions when compiling as C++ code. | 492 | ** longjmp/setjmp. By default, Lua handles errors with exceptions when |
| 493 | ** compiling as C++ code, with _longjmp/_setjmp when compiling as C code | ||
| 494 | ** in a Unix system, and with longjmp/setjmp otherwise. | ||
| 445 | */ | 495 | */ |
| 446 | #ifndef __cplusplus | 496 | #if defined(__cplusplus) |
| 447 | /* default handling with long jumps */ | ||
| 448 | #define LUAI_THROW(L,c) longjmp((c)->b, 1) | ||
| 449 | #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } | ||
| 450 | #define luai_jmpbuf jmp_buf | ||
| 451 | |||
| 452 | #else | ||
| 453 | /* C++ exceptions */ | 497 | /* C++ exceptions */ |
| 454 | #define LUAI_THROW(L,c) throw(c) | 498 | #define LUAI_THROW(L,c) throw(c) |
| 455 | #define LUAI_TRY(L,c,a) try { a } catch(...) \ | 499 | #define LUAI_TRY(L,c,a) try { a } catch(...) \ |
| 456 | { if ((c)->status == 0) (c)->status = -1; } | 500 | { if ((c)->status == 0) (c)->status = -1; } |
| 457 | #define luai_jmpbuf int /* dummy variable */ | 501 | #define luai_jmpbuf int /* dummy variable */ |
| 502 | |||
| 503 | #elif !defined(__STRICT_ANSI__) && (defined(unix) || defined(__unix) || \ | ||
| 504 | defined(__unix__)) | ||
| 505 | /* in Unix, try _longjmp/_setjmp (more efficient) */ | ||
| 506 | #define LUAI_THROW(L,c) _longjmp((c)->b, 1) | ||
| 507 | #define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a } | ||
| 508 | #define luai_jmpbuf jmp_buf | ||
| 509 | |||
| 510 | #else | ||
| 511 | /* default handling with long jumps */ | ||
| 512 | #define LUAI_THROW(L,c) longjmp((c)->b, 1) | ||
| 513 | #define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a } | ||
| 514 | #define luai_jmpbuf jmp_buf | ||
| 515 | |||
| 458 | #endif | 516 | #endif |
| 459 | 517 | ||
| 460 | 518 | ||
| 461 | /* | 519 | /* |
| 462 | *@ LUA_MAXCAPTURES is the maximum number of captures that a pattern | 520 | @@ LUA_MAXCAPTURES is the maximum number of captures that a pattern |
| 463 | ** can do during pattern-matching. | 521 | @* can do during pattern-matching. |
| 464 | ** CHANGE it if you need more captures. This limit is arbitrary. | 522 | ** CHANGE it if you need more captures. This limit is arbitrary. |
| 465 | */ | 523 | */ |
| 466 | #define LUA_MAXCAPTURES 32 | 524 | #define LUA_MAXCAPTURES 32 |
| 467 | 525 | ||
| 468 | 526 | ||
| 469 | /* | 527 | /* |
| 470 | *@ lua_tmpnam is the function that the OS library uses to create a | 528 | @@ lua_tmpnam is the function that the OS library uses to create a |
| 471 | ** temporary name. | 529 | @* temporary name. |
| 472 | ** CHANGE it if you have an alternative to tmpnam (which is considered | 530 | @@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam. |
| 473 | ** insecure) or if you want the original tmpnam anyway. By default, | 531 | ** CHANGE them if you have an alternative to tmpnam (which is considered |
| 474 | ** Lua uses tmpnam except when compiled when POSIX is available, where | 532 | ** insecure) or if you want the original tmpnam anyway. By default, Lua |
| 475 | ** it uses mkstemp. | 533 | ** uses tmpnam except when POSIX is available, where it uses mkstemp. |
| 476 | */ | 534 | */ |
| 477 | #ifdef _POSIX_C_SOURCE | 535 | #if defined(loslib_c) || defined(luaall_c) |
| 536 | |||
| 537 | #if !defined(__STRICT_ANSI__) && defined(_POSIX_C_SOURCE) | ||
| 478 | #include <unistd.h> | 538 | #include <unistd.h> |
| 479 | #define LUA_TMPNAMBUFSIZE 32 | 539 | #define LUA_TMPNAMBUFSIZE 32 |
| 480 | #define lua_tmpnam(b,e) { \ | 540 | #define lua_tmpnam(b,e) { \ |
| @@ -487,29 +547,36 @@ __inline int l_lrint (double flt) | |||
| 487 | #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } | 547 | #define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); } |
| 488 | #endif | 548 | #endif |
| 489 | 549 | ||
| 550 | #endif | ||
| 490 | 551 | ||
| 491 | /* | 552 | /* |
| 492 | *@ LUA_USE_* define which dynamic-library system Lua should use. | 553 | @@ LUA_DL_* define which dynamic-library system Lua should use. |
| 493 | ** CHANGE here if Lua has problems choosing the appropriate | 554 | ** CHANGE here if Lua has problems choosing the appropriate |
| 494 | ** dynamic-library system for your platform (either Windows' DLL, Mac's | 555 | ** dynamic-library system for your platform (either Windows' DLL, Mac's |
| 495 | ** dyld, or Unix's dlopen). If your system is some kind of Unix, there | 556 | ** dyld, or Unix's dlopen). If your system is some kind of Unix, there |
| 496 | ** is a good chance that LUA_USE_DLOPEN will work for it. (You may need | 557 | ** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for |
| 497 | ** to adapt also the makefile.) If you do not want any kind of dynamic | 558 | ** it. To use dlopen you also need to adapt the makefile (probably |
| 498 | ** library, undefine all these options (or just remove these definitions). | 559 | ** adding -ldl to the linker options), so Lua does not select it |
| 499 | */ | 560 | ** automatically. (When you change the makefile to add -ldl, you must |
| 561 | ** also add -DLUA_USE_DLOPEN.) | ||
| 562 | ** If you do not want any kind of dynamic library, undefine all these | ||
| 563 | ** options (or just remove these definitions). | ||
| 564 | */ | ||
| 565 | #if !defined(__STRICT_ANSI__) | ||
| 500 | #if defined(_WIN32) | 566 | #if defined(_WIN32) |
| 501 | #define LUA_USE_DLL | 567 | #define LUA_DL_DLL |
| 502 | #elif defined(__APPLE__) && defined(__MACH__) | 568 | #elif defined(__APPLE__) && defined(__MACH__) |
| 503 | #define LUA_USE_DYLD | 569 | #define LUA_DL_DYLD |
| 504 | #elif defined(__linux) || defined(sun) || defined(sgi) || defined(BSD) | 570 | #elif defined(LUA_USE_DLOPEN) |
| 505 | #define LUA_USE_DLOPEN | 571 | #define LUA_DL_DLOPEN |
| 572 | #endif | ||
| 506 | #endif | 573 | #endif |
| 507 | 574 | ||
| 508 | 575 | ||
| 509 | /* | 576 | /* |
| 510 | *@ lua_lock/lua_unlock are macros for thread synchronization inside the | 577 | @@ lua_lock/lua_unlock are macros for thread synchronization inside the |
| 511 | ** Lua core. This is an attempt to simplify the implementation of a | 578 | @* Lua core. This is an attempt to simplify the implementation of a |
| 512 | ** multithreaded version of Lua. | 579 | @* multithreaded version of Lua. |
| 513 | ** CHANGE them only if you know what you are doing. all accesses to | 580 | ** CHANGE them only if you know what you are doing. all accesses to |
| 514 | ** the global state and to global objects are synchronized. Because | 581 | ** the global state and to global objects are synchronized. Because |
| 515 | ** threads can read the stack of other threads (when running garbage | 582 | ** threads can read the stack of other threads (when running garbage |
| @@ -523,15 +590,15 @@ __inline int l_lrint (double flt) | |||
| 523 | 590 | ||
| 524 | 591 | ||
| 525 | /* | 592 | /* |
| 526 | *@ lua_threadyield allows a thread switch in appropriate places in the core. | 593 | @@ lua_threadyield allows a thread switch in appropriate places in the core. |
| 527 | ** CHANGE it only if you know what you are doing. (See lua_lock.) | 594 | ** CHANGE it only if you know what you are doing. (See lua_lock.) |
| 528 | */ | 595 | */ |
| 529 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} | 596 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} |
| 530 | 597 | ||
| 531 | 598 | ||
| 532 | /* | 599 | /* |
| 533 | *@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State | 600 | @@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State |
| 534 | ** (the data goes just *before* the lua_State pointer). | 601 | @* (the data goes just *before* the lua_State pointer). |
| 535 | ** CHANGE (define) this if you really need that. This value must be | 602 | ** CHANGE (define) this if you really need that. This value must be |
| 536 | ** a multiple of the maximum alignment required for your machine. | 603 | ** a multiple of the maximum alignment required for your machine. |
| 537 | */ | 604 | */ |
| @@ -539,7 +606,7 @@ __inline int l_lrint (double flt) | |||
| 539 | 606 | ||
| 540 | 607 | ||
| 541 | /* | 608 | /* |
| 542 | *@ luai_userstateopen allows user-specific initialization on new threads. | 609 | @@ luai_userstateopen allows user-specific initialization on new threads. |
| 543 | ** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that | 610 | ** CHANGE it if you defined LUAI_EXTRASPACE and need to initialize that |
| 544 | ** data whenever a new lua_State is created. | 611 | ** data whenever a new lua_State is created. |
| 545 | */ | 612 | */ |
