(th *LState, fn *LFunction, args ...LValue)
| 1942 | } |
| 1943 | |
| 1944 | func (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 |
nothing calls this directly
no test coverage detected