diff --git a/lua-engine.cpp b/lua-engine.cpp index 55f314f2..b06977b6 100644 --- a/lua-engine.cpp +++ b/lua-engine.cpp @@ -1129,14 +1129,14 @@ DEFINE_LUA_FUNCTION(addressof, "table_or_function") 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. /* -** 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/ ** -** 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 ** a copy of this software and associated documentation files (the @@ -1186,7 +1186,11 @@ static UBits barg(lua_State *L, int idx) { BitNum bn; UBits b; +#if LUA_VERSION_NUM < 502 bn.n = lua_tonumber(L, idx); +#else + bn.n = luaL_checknumber(L, idx); +#endif #if defined(LUA_NUMBER_DOUBLE) bn.n += 6755399441055744.0; /* 2^52+2^51 */ #ifdef SWAPPED_DOUBLE @@ -1206,8 +1210,11 @@ static UBits barg(lua_State *L, int idx) #else #error "Unknown number type, check LUA_NUMBER_* in luaconf.h" #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"); + } +#endif 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); return false; } +#if LUA_VERSION_NUM < 502 + luaL_register(L, "bit", bit_funcs); +#else + luaL_newlib(L, bit_funcs); +#endif return true; }