forked from mia/Aegisub
9492192b73
In preparation for switching to LuaJIT, which doesn't support PUC Lua's thing of using C++ exceptions for lua_error. Requires replacing all uses of lua_error (and things calling lua_error) with custom versions that throw an exception instead and adding an exception -> lua error wrapper at all C++ -> Lua boundaries.
54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
/*
|
|
* luainternals.c
|
|
* Code quoted from MIT-licensed Lua 5.1.4 internals
|
|
* See copyright notice in lua.h
|
|
*/
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
|
|
#include <lua.h>
|
|
#include <lauxlib.h>
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
|
|
#include "luainternals.h"
|
|
|
|
/*
|
|
* BEGIN COPY-PASTE FROM Lua 5.1.4 llimits.h
|
|
*/
|
|
|
|
/* chars used as small naturals (so that `char' is reserved for characters) */
|
|
typedef unsigned char lu_byte;
|
|
|
|
/*
|
|
* END COPY-PASTE FROM Lua 5.1.4 llimits.h
|
|
*/
|
|
|
|
/*
|
|
* BEGIN COPY-PASTE FROM Lua 5.1.4 lobject.c
|
|
*/
|
|
|
|
int luaO_log2 (unsigned int x) {
|
|
static const lu_byte log_2[256] = {
|
|
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
|
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
|
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
|
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
|
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
|
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
|
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
|
|
};
|
|
int l = -1;
|
|
while (x >= 256) { l += 8; x >>= 8; }
|
|
return l + log_2[x];
|
|
|
|
}
|
|
|
|
/*
|
|
* END COPY-PASTE FROM Lua 5.1.4 lobject.c
|
|
*/
|