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

     1  local function apply(f, ...)
     2      return f(...)
     3  end
     4  
     5  apply(print, 1, 2)
     6  --> =1	2
     7  
     8  print(apply(rawlen, "abc"))
     9  --> =3
    10  
    11  print(pcall(apply, rawequal, 1))
    12  --> ~^false
    13  
    14  local function errtest(...)
    15      local ok, err = pcall(...)
    16      if ok then
    17          print "OK"
    18      else
    19          print(err)
    20      end
    21  end
    22  
    23  print(type(string.dump(apply)))
    24  --> =string
    25  
    26  print(math.sin(0))
    27  --> =0
    28  
    29  print(string.byte("A", 1))
    30  --> =65
    31  
    32  errtest(string.dump, 1)
    33  --> ~must be a lua function
    34  
    35  errtest(string.len, 1)
    36  --> ~must be a string
    37  
    38  errtest(string.len)
    39  --> ~value needed
    40  
    41  errtest(coroutine.create, "wrong!")
    42  --> ~must be a callable
    43  
    44  errtest(coroutine.resume, {})
    45  --> ~must be a thread
    46  
    47  errtest(string.byte, "x", {})
    48  --> ~must be an integer
    49  
    50  errtest(math.cos, true)
    51  --> ~must be a number
    52  
    53  errtest(rawget, 1, 2)
    54  --> ~must be a table
    55  
    56  errtest(dofile, 1, 2, 3)
    57  --> ~must be a string