Update LuaBitOp to 1.0.2

This commit is contained in:
gocha 2012-08-31 06:59:00 +09:00
parent b7b749af3f
commit 81c078eba8
1 changed files with 16 additions and 4 deletions

View File

@ -1129,14 +1129,14 @@ DEFINE_LUA_FUNCTION(addressof, "table_or_function")
return 1; return 1;
} }
// the following bit operations are ported from LuaBitOp 1.0.1, // the following bit operations are ported from LuaBitOp 1.0.12
// because it can handle the sign bit (bit 31) correctly. // because it can handle the sign bit (bit 31) correctly.
/* /*
** Lua BitOp -- a bit operations library for Lua 5.1. ** Lua BitOp -- a bit operations library for Lua 5.1/5.2.
** http://bitop.luajit.org/ ** http://bitop.luajit.org/
** **
** Copyright (C) 2008-2009 Mike Pall. All rights reserved. ** Copyright (C) 2008-2012 Mike Pall. All rights reserved.
** **
** Permission is hereby granted, free of charge, to any person obtaining ** Permission is hereby granted, free of charge, to any person obtaining
** a copy of this software and associated documentation files (the ** a copy of this software and associated documentation files (the
@ -1186,7 +1186,11 @@ static UBits barg(lua_State *L, int idx)
{ {
BitNum bn; BitNum bn;
UBits b; UBits b;
#if LUA_VERSION_NUM < 502
bn.n = lua_tonumber(L, idx); bn.n = lua_tonumber(L, idx);
#else
bn.n = luaL_checknumber(L, idx);
#endif
#if defined(LUA_NUMBER_DOUBLE) #if defined(LUA_NUMBER_DOUBLE)
bn.n += 6755399441055744.0; /* 2^52+2^51 */ bn.n += 6755399441055744.0; /* 2^52+2^51 */
#ifdef SWAPPED_DOUBLE #ifdef SWAPPED_DOUBLE
@ -1206,8 +1210,11 @@ static UBits barg(lua_State *L, int idx)
#else #else
#error "Unknown number type, check LUA_NUMBER_* in luaconf.h" #error "Unknown number type, check LUA_NUMBER_* in luaconf.h"
#endif #endif
if (b == 0 && !lua_isnumber(L, idx)) #if LUA_VERSION_NUM < 502
if (b == 0 && !lua_isnumber(L, idx)) {
luaL_typerror(L, idx, "number"); luaL_typerror(L, idx, "number");
}
#endif
return b; return b;
} }
@ -1301,6 +1308,11 @@ bool luabitop_validate(lua_State *L) // originally named as luaopen_bit
luaL_error(L, "bit library self-test failed (%s)", msg); luaL_error(L, "bit library self-test failed (%s)", msg);
return false; return false;
} }
#if LUA_VERSION_NUM < 502
luaL_register(L, "bit", bit_funcs);
#else
luaL_newlib(L, bit_funcs);
#endif
return true; return true;
} }