From f616c9e690097a97bcb7ec17653ed2a2fd044fee Mon Sep 17 00:00:00 2001
From: "p.kosyh@gmail.com"
Date: Thu, 28 Apr 2011 19:29:21 +0000
Subject: [PATCH] bitwise operations
---
src/sdl-instead/instead.c | 48 +++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/src/sdl-instead/instead.c b/src/sdl-instead/instead.c
index b34265e..4dc294c 100644
--- a/src/sdl-instead/instead.c
+++ b/src/sdl-instead/instead.c
@@ -1409,6 +1409,47 @@ static int luaB_get_ticks(lua_State *L) {
return 1;
}
+static int luaB_bit_and(lua_State *L) {
+ unsigned int a = luaL_optnumber(L, 1, 0);
+ unsigned int b = luaL_optnumber(L, 2, 0);
+ lua_pushnumber(L, a & b);
+ return 1;
+}
+
+static int luaB_bit_or(lua_State *L) {
+ unsigned int a = luaL_optnumber(L, 1, 0);
+ unsigned int b = luaL_optnumber(L, 2, 0);
+ lua_pushnumber(L, a | b);
+ return 1;
+}
+
+static int luaB_bit_xor(lua_State *L) {
+ unsigned int a = luaL_optnumber(L, 1, 0);
+ unsigned int b = luaL_optnumber(L, 2, 0);
+ lua_pushnumber(L, a ^ b);
+ return 1;
+}
+
+static int luaB_bit_shl(lua_State *L) {
+ unsigned int a = luaL_optnumber(L, 1, 0);
+ unsigned int b = luaL_optnumber(L, 2, 0);
+ lua_pushnumber(L, a << b);
+ return 1;
+}
+
+static int luaB_bit_shr(lua_State *L) {
+ unsigned int a = luaL_optnumber(L, 1, 0);
+ unsigned int b = luaL_optnumber(L, 2, 0);
+ lua_pushnumber(L, a >> b);
+ return 1;
+}
+
+static int luaB_bit_not(lua_State *L) {
+ unsigned int a = luaL_optnumber(L, 1, 0);
+ lua_pushnumber(L, ~a);
+ return 1;
+}
+
static const luaL_Reg base_funcs[] = {
{"doencfile", luaB_doencfile},
{"dofile", luaB_dofile},
@@ -1449,6 +1490,13 @@ static const luaL_Reg base_funcs[] = {
{"sprite_rotate", luaB_rotate_sprite},
{"sprite_text_size", luaB_text_size},
{"sprite_pixel", luaB_pixel_sprite},
+
+ {"bit_or", luaB_bit_or},
+ {"bit_and", luaB_bit_and},
+ {"bit_xor", luaB_bit_xor},
+ {"bit_shl", luaB_bit_shl},
+ {"bit_shr", luaB_bit_shr},
+ {"bit_not", luaB_bit_not},
{NULL, NULL}
};