MCPcopy Index your code
hub / github.com/yuin/gopher-lua / Resume

Method Resume

_state.go:1944–2002  ·  view source on GitHub ↗
(th *LState, fn *LFunction, args ...LValue)

Source from the content-addressed store, hash-verified

1942}
1943
1944func (ls *LState) Resume(th *LState, fn *LFunction, args ...LValue) (ResumeState, error, []LValue) {
1945 isstarted := th.isStarted()
1946 if !isstarted {
1947 base := 0
1948 th.stack.Push(callFrame{
1949 Fn: fn,
1950 Pc: 0,
1951 Base: base,
1952 LocalBase: base + 1,
1953 ReturnBase: base,
1954 NArgs: 0,
1955 NRet: MultRet,
1956 Parent: nil,
1957 TailCall: 0,
1958 })
1959 }
1960
1961 if ls.G.CurrentThread == th {
1962 return ResumeError, newApiErrorS(ApiErrorRun, "can not resume a running thread"), nil
1963 }
1964 if th.Dead {
1965 return ResumeError, newApiErrorS(ApiErrorRun, "can not resume a dead thread"), nil
1966 }
1967 th.Parent = ls
1968 ls.G.CurrentThread = th
1969 if !isstarted {
1970 cf := th.stack.Last()
1971 th.currentFrame = cf
1972 th.SetTop(0)
1973 for _, arg := range args {
1974 th.Push(arg)
1975 }
1976 cf.NArgs = len(args)
1977 th.initCallFrame(cf)
1978 th.Panic = panicWithoutTraceback
1979 } else {
1980 for _, arg := range args {
1981 th.Push(arg)
1982 }
1983 }
1984 top := ls.GetTop()
1985 threadRun(th)
1986 haserror := LVIsFalse(ls.Get(top + 1))
1987 ret := make([]LValue, 0, ls.GetTop())
1988 for idx := top + 2; idx <= ls.GetTop(); idx++ {
1989 ret = append(ret, ls.Get(idx))
1990 }
1991 if len(ret) == 0 {
1992 ret = append(ret, LNil)
1993 }
1994 ls.SetTop(top)
1995
1996 if haserror {
1997 return ResumeError, newApiError(ApiErrorRun, ret[0]), nil
1998 } else if th.stack.IsEmpty() {
1999 return ResumeOK, nil, ret
2000 }
2001 return ResumeYield, nil, ret

Callers

nothing calls this directly

Calls 12

SetTopMethod · 0.95
GetTopMethod · 0.95
GetMethod · 0.95
LVIsFalseFunction · 0.85
newApiErrorSFunction · 0.70
threadRunFunction · 0.70
newApiErrorFunction · 0.70
PushMethod · 0.65
LastMethod · 0.65
IsEmptyMethod · 0.65
isStartedMethod · 0.45
initCallFrameMethod · 0.45

Tested by

no test coverage detected