[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Bitshift function in Lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 11 Feb 1999 15:38:19 -0200 (EDT)
>From: erik@hougaard.com (Erik Hougaard)
>This might be a stupid function, but is Lua missing a << >> bitshift function
yes, since it does not make sense for real numbers.
>and if so, how do I make it ?
how about this:
static void math_lshift (void)
{
int v=luaL_check_number(1);
int n=luaL_check_number(2);
lua_pushnumber(v<<n);
}
static void math_rshift (void)
{
int v=luaL_check_number(1);
int n=luaL_check_number(2);
lua_pushnumber(v>>n);
}
lua_register("lshift",math_lshift);
lua_register("rshift",math_rshift);
--lhf