diff options
| author | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 14:54:36 +0200 |
|---|---|---|
| committer | Benoit Germain <benoit.germain@ubisoft.com> | 2025-07-04 14:54:36 +0200 |
| commit | 7bddb06461d8f80030b3b86175ec737dbb16ac3b (patch) | |
| tree | 031238469090658f7f20535137edb2620bc77182 /src/compat.cpp | |
| parent | 042055968ab0c48faec607889814e38c50c09efa (diff) | |
| download | lanes-7bddb06461d8f80030b3b86175ec737dbb16ac3b.tar.gz lanes-7bddb06461d8f80030b3b86175ec737dbb16ac3b.tar.bz2 lanes-7bddb06461d8f80030b3b86175ec737dbb16ac3b.zip | |
Added Lua 5.5 support
* some unit tests fail/segfault/freeze, but that could be because Lua 5.5 is still in beta yet
Diffstat (limited to 'src/compat.cpp')
| -rw-r--r-- | src/compat.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/compat.cpp b/src/compat.cpp index 08f22ca..c833480 100644 --- a/src/compat.cpp +++ b/src/compat.cpp | |||
| @@ -149,3 +149,41 @@ int lua_setiuservalue(lua_State* const L_, StackIndex const idx_, UserValueIndex | |||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | #endif // LUA_VERSION_NUM | 151 | #endif // LUA_VERSION_NUM |
| 152 | |||
| 153 | // ################################################################################################# | ||
| 154 | |||
| 155 | #if LUA_VERSION_NUM < 505 | ||
| 156 | |||
| 157 | #include <time.h> | ||
| 158 | |||
| 159 | /* Size for the buffer, in bytes */ | ||
| 160 | #define BUFSEEDB (sizeof(void*) + sizeof(time_t)) | ||
| 161 | |||
| 162 | /* Size for the buffer in int's, rounded up */ | ||
| 163 | #define BUFSEED ((BUFSEEDB + sizeof(int) - 1) / sizeof(int)) | ||
| 164 | |||
| 165 | /* | ||
| 166 | ** Copy the contents of variable 'v' into the buffer pointed by 'b'. | ||
| 167 | ** (The '&b[0]' disguises 'b' to fix an absurd warning from clang.) | ||
| 168 | */ | ||
| 169 | #define addbuff(b, v) (memcpy(&b[0], &(v), sizeof(v)), b += sizeof(v)) | ||
| 170 | |||
| 171 | // Copied from Lua 5.5 lauxlib.c | ||
| 172 | unsigned int luaL_makeseed(lua_State*) | ||
| 173 | { | ||
| 174 | unsigned int buff[BUFSEED]; | ||
| 175 | unsigned int res; | ||
| 176 | unsigned int i; | ||
| 177 | time_t t = time(nullptr); | ||
| 178 | char* b = (char*) buff; | ||
| 179 | addbuff(b, b); /* local variable's address */ | ||
| 180 | addbuff(b, t); /* time */ | ||
| 181 | /* fill (rare but possible) remain of the buffer with zeros */ | ||
| 182 | memset(b, 0, sizeof(buff) - BUFSEEDB); | ||
| 183 | res = buff[0]; | ||
| 184 | for (i = 1; i < BUFSEED; i++) | ||
| 185 | res ^= (res >> 3) + (res << 7) + buff[i]; | ||
| 186 | return res; | ||
| 187 | } | ||
| 188 | |||
| 189 | #endif // LUA_VERSION_NUM < 505 | ||
