NewThread returns a new LState that shares with the original state all global objects. If the original state has context.Context, the new state has a new child context of the original state and this function returns its cancel function.
()
| 1612 | // NewThread returns a new LState that shares with the original state all global objects. |
| 1613 | // If the original state has context.Context, the new state has a new child context of the original state and this function returns its cancel function. |
| 1614 | func (ls *LState) NewThread() (*LState, context.CancelFunc) { |
| 1615 | thread := newLState(ls.Options) |
| 1616 | thread.G = ls.G |
| 1617 | thread.Env = ls.Env |
| 1618 | var f context.CancelFunc = nil |
| 1619 | if ls.ctx != nil { |
| 1620 | thread.mainLoop = mainLoopWithContext |
| 1621 | thread.ctx, f = context.WithCancel(ls.ctx) |
| 1622 | thread.ctxCancelFn = f |
| 1623 | } |
| 1624 | return thread, f |
| 1625 | } |
| 1626 | |
| 1627 | func (ls *LState) NewFunctionFromProto(proto *FunctionProto) *LFunction { |
| 1628 | return newLFunctionL(proto, ls.Env, int(proto.NumUpvalues)) |