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

     1  package base
     2  
     3  import rt "github.com/arnodel/golua/runtime"
     4  
     5  func pairs(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
     6  	if err := c.Check1Arg(); err != nil {
     7  		return nil, err
     8  	}
     9  	coll := c.Arg(0)
    10  	next := c.Next()
    11  	res := rt.NewTerminationWith(c, 0, true)
    12  	err, ok := rt.Metacall(t, coll, "__pairs", []rt.Value{coll}, res)
    13  	if ok {
    14  		if err != nil {
    15  			return nil, err
    16  		}
    17  		t.Push(next, res.Etc()...)
    18  		return next, nil
    19  	}
    20  	t.Push(next, rt.FunctionValue(nextGoFunc), coll, rt.NilValue)
    21  	return next, nil
    22  }