github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/runtime/lua/bitwise.lua (about)

     1  print(-1 >> 56 == 0xff)
     2  --> =true
     3  
     4  print(1 >> -3)
     5  --> =8
     6  
     7  print(10 << -2)
     8  --> =2
     9  
    10  local function perr(s)
    11      local ok, err = pcall(load("return " .. s))
    12      print(err)
    13  end
    14  
    15  perr[[100 & "2"]]
    16  --> ~.*attempt to perform bitwise and on a string value
    17  
    18  perr[["100" | 23]]
    19  --> ~.*attempt to perform bitwise or on a string value
    20  
    21  perr[[~"55"]]
    22  --> ~.*attempt to perform bitwise not on a string value
    23  
    24  perr[[23 ~ "5"]]
    25  --> ~.*attempt to perform bitwise xor on a string value
    26  
    27  perr[["77" >> 9]]
    28  --> ~.*attempt to perform bitwise shr on a string value
    29  
    30  perr[["123" << "456" ]]
    31  --> ~.*attempt to perform bitwise shl on a string value
    32  
    33  perr[[0.5 | 1.2]]
    34  --> ~.*number has no integer representation
    35  
    36  perr[[45.2 >> "a"]]
    37  --> ~.*attempt to perform bitwise shr on a string value