diff options
| -rw-r--r-- | lbitlib.c | 9 |
1 files changed, 4 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbitlib.c,v 1.27 2014/10/01 11:54:56 roberto Exp roberto $ | 2 | ** $Id: lbitlib.c,v 1.28 2014/11/02 19:19:04 roberto Exp roberto $ |
| 3 | ** Standard library for bitwise operations | 3 | ** Standard library for bitwise operations |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -186,11 +186,10 @@ static int b_extract (lua_State *L) { | |||
| 186 | static int b_replace (lua_State *L) { | 186 | static int b_replace (lua_State *L) { |
| 187 | int w; | 187 | int w; |
| 188 | lua_Unsigned r = trim(luaL_checkunsigned(L, 1)); | 188 | lua_Unsigned r = trim(luaL_checkunsigned(L, 1)); |
| 189 | lua_Unsigned v = luaL_checkunsigned(L, 2); | 189 | lua_Unsigned v = trim(luaL_checkunsigned(L, 2)); |
| 190 | int f = fieldargs(L, 3, &w); | 190 | int f = fieldargs(L, 3, &w); |
| 191 | int m = mask(w); | 191 | lua_Unsigned m = mask(w); |
| 192 | v &= m; /* erase bits outside given width */ | 192 | r = (r & ~(m << f)) | ((v & m) << f); |
| 193 | r = (r & ~(m << f)) | (v << f); | ||
| 194 | lua_pushunsigned(L, r); | 193 | lua_pushunsigned(L, r); |
| 195 | return 1; | 194 | return 1; |
| 196 | } | 195 | } |
