github.com/arnodel/golua@v0.0.0-20230215163904-e0b5347eaaa1/lib/base/error.go (about)

     1  package base
     2  
     3  import (
     4  	rt "github.com/arnodel/golua/runtime"
     5  )
     6  
     7  func errorF(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
     8  	var (
     9  		err   *rt.Error
    10  		level int64 = 1
    11  	)
    12  	if c.NArgs() == 0 {
    13  		err = rt.NewError(rt.NilValue)
    14  	} else {
    15  		err = rt.NewError(c.Arg(0))
    16  	}
    17  	if c.NArgs() >= 2 {
    18  		var argErr error
    19  		level, argErr = c.IntArg(1)
    20  		if argErr != nil {
    21  			return nil, argErr
    22  		}
    23  	}
    24  	if level != 1 {
    25  		err = err.AddContext(c.Next(), int(level))
    26  	}
    27  	return nil, err
    28  }