This commit is contained in:
p.kosyh@gmail.com 2011-04-28 19:45:59 +00:00
parent ec694545b7
commit 40fdbad777

View file

@ -1412,49 +1412,57 @@ static int luaB_get_ticks(lua_State *L) {
static int luaB_bit_and(lua_State *L) { static int luaB_bit_and(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 0); unsigned int b = luaL_optnumber(L, 2, 0);
lua_pushnumber(L, a & b); unsigned int r = a & b;
lua_pushnumber(L, r);
return 1; return 1;
} }
static int luaB_bit_or(lua_State *L) { static int luaB_bit_or(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 0); unsigned int b = luaL_optnumber(L, 2, 0);
lua_pushnumber(L, a | b); unsigned int r = a | b;
lua_pushnumber(L, r);
return 1; return 1;
} }
static int luaB_bit_xor(lua_State *L) { static int luaB_bit_xor(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 0); unsigned int b = luaL_optnumber(L, 2, 0);
lua_pushnumber(L, a ^ b); unsigned int r = a ^ b;
lua_pushnumber(L, r);
return 1; return 1;
} }
static int luaB_bit_shl(lua_State *L) { static int luaB_bit_shl(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 0); unsigned int b = luaL_optnumber(L, 2, 0);
lua_pushnumber(L, a << b); unsigned int r = a << b;
lua_pushnumber(L, r);
return 1; return 1;
} }
static int luaB_bit_shr(lua_State *L) { static int luaB_bit_shr(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 0); unsigned int b = luaL_optnumber(L, 2, 0);
lua_pushnumber(L, a >> b); unsigned int r = a >> b;
lua_pushnumber(L, r);
return 1; return 1;
} }
static int luaB_bit_not(lua_State *L) { static int luaB_bit_not(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
lua_pushnumber(L, ~a); unsigned int r = ~a;
lua_pushnumber(L, r);
return 1; return 1;
} }
static int luaB_bit_div(lua_State *L) { static int luaB_bit_div(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 1); unsigned int b = luaL_optnumber(L, 2, 1);
unsigned int r;
if (b) { if (b) {
lua_pushnumber(L, a / b); r = a / b;
lua_pushnumber(L, r);
return 1; return 1;
} }
return 0; return 0;
@ -1463,13 +1471,23 @@ static int luaB_bit_div(lua_State *L) {
static int luaB_bit_mod(lua_State *L) { static int luaB_bit_mod(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0); unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 1); unsigned int b = luaL_optnumber(L, 2, 1);
unsigned int r;
if (b) { if (b) {
lua_pushnumber(L, a % b); r = a % b;
lua_pushnumber(L, r);
return 1; return 1;
} }
return 0; return 0;
} }
static int luaB_bit_mul(lua_State *L) {
unsigned int a = luaL_optnumber(L, 1, 0);
unsigned int b = luaL_optnumber(L, 2, 0);
unsigned int r = a * b;
lua_pushnumber(L, r);
return 1;
}
static const luaL_Reg base_funcs[] = { static const luaL_Reg base_funcs[] = {
{"doencfile", luaB_doencfile}, {"doencfile", luaB_doencfile},
{"dofile", luaB_dofile}, {"dofile", luaB_dofile},
@ -1519,6 +1537,7 @@ static const luaL_Reg base_funcs[] = {
{"bit_not", luaB_bit_not}, {"bit_not", luaB_bit_not},
{"bit_div", luaB_bit_div}, {"bit_div", luaB_bit_div},
{"bit_mod", luaB_bit_mod}, {"bit_mod", luaB_bit_mod},
{"bit_mul", luaB_bit_mul},
{NULL, NULL} {NULL, NULL}
}; };