mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
This maintains the type information which can be used for enforce const-correctness and also for implementing more advanced ways of handling the type information.
90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
|
|
#include "bitops.h"
|
|
#include "scripting/ade_args.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
//**********LIBRARY: Bitwise Ops
|
|
ADE_LIB(l_BitOps, "BitOps", "bit", "Bitwise Operations library");
|
|
|
|
ADE_FUNC(AND, l_BitOps, "number, number", "Values for which bitwise boolean AND operation is performed", "number", "Result of the AND operation")
|
|
{
|
|
|
|
int a, b, c;
|
|
if(!ade_get_args(L, "ii", &a,&b))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
c = (a & b);
|
|
|
|
return ade_set_args(L, "i", c);
|
|
}
|
|
|
|
ADE_FUNC(OR, l_BitOps, "number, number", "Values for which bitwise boolean OR operation is performed", "number", "Result of the OR operation")
|
|
{
|
|
int a, b, c;
|
|
if(!ade_get_args(L, "ii", &a,&b))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
c = (a | b);
|
|
|
|
return ade_set_args(L, "i", c);
|
|
}
|
|
|
|
ADE_FUNC(XOR, l_BitOps, "number, number", "Values for which bitwise boolean XOR operation is performed", "number", "Result of the XOR operation")
|
|
{
|
|
int a, b, c;
|
|
if(!ade_get_args(L, "ii", &a,&b))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
c = (a ^ b);
|
|
|
|
return ade_set_args(L, "i", c);
|
|
}
|
|
|
|
ADE_FUNC(toggleBit, l_BitOps, "number, number (bit)", "Toggles the value of the set bit in the given number for 32 bit integer", "number", "Result of the operation")
|
|
{
|
|
int a, b, c;
|
|
if(!ade_get_args(L, "ii", &a,&b))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (!((b >= 0) && (b < 32)))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
c = a ^ (1 << b);
|
|
|
|
return ade_set_args(L, "i", c);
|
|
}
|
|
|
|
ADE_FUNC(checkBit, l_BitOps, "number, number (bit)", "Checks the value of the set bit in the given number for 32 bit integer", "boolean", "Was the bit true of false")
|
|
{
|
|
int a, b;
|
|
if(!ade_get_args(L, "ii", &a,&b))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (!((b >= 0) && (b < 32)))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if(a & (1<<b))
|
|
return ADE_RETURN_TRUE;
|
|
else
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
ADE_FUNC(addBit, l_BitOps, "number, number (bit)", "Performs inclusive or (OR) operation on the set bit of the value", "number", "Result of the operation")
|
|
{
|
|
int a, b, c;
|
|
if(!ade_get_args(L, "ii", &a,&b))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
if (!((b >= 0) && (b < 32)))
|
|
return ade_set_error(L, "i", 0);
|
|
|
|
c = (a | (1<<b));
|
|
|
|
return ade_set_args(L, "i", c);
|
|
}
|
|
|
|
}
|
|
}
|