~rootmos/lua-hack

471f8448042ae29190da357b3d787fa21be7bcf0 — Gustav Behm 1 year, 2 months ago 334bfea uint32-32
Move bits guesser into its own module
2 files changed, 7 insertions(+), 6 deletions(-)

R scripts/bits.lua => bits.lua
M test
R scripts/bits.lua => bits.lua +2 -4
@@ 1,13 1,11 @@
max = 0x7fffffffffffffff
if math.type(max) == "integer" and max + 1 < 0 then
    print("64")
    os.exit()
    return 64
end

max = 0x7fffffff
if math.type(max) == "integer" and max + 1 < 0 then
    print("32")
    os.exit()
    return 32
end

error("unknown integer width")

M test => test +5 -2
@@ 18,14 18,17 @@ while getopts "b:-" OPT; do
done
shift $((OPTIND-1))

GUESS_BITS=$($LUA "$SCRIPT_DIR/scripts/bits.lua")
guess_bits() {
    $1 -lbits -e 'print(require"bits")'
}
GUESS_BITS=$(guess_bits "$LUA")
if [ "$GUESS_BITS" -ne "$BITS" ]; then
    if [ -n "${LUA32-}" ]; then
        LUA=$LUA32
    else
        LUA="$SCRIPT_DIR/scripts/lua32"
    fi
    GUESS_BITS=$($LUA "$SCRIPT_DIR/scripts/bits.lua")
    GUESS_BITS=$(guess_bits "$LUA")
    if [ "$GUESS_BITS" -ne "$BITS" ]; then
        echo 1>&2 "unable to find a usable lua executable"
        exit 1