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

Method NewThread

state.go:1614–1625  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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.
1614func (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
1627func (ls *LState) NewFunctionFromProto(proto *FunctionProto) *LFunction {
1628 return newLFunctionL(proto, ls.Env, int(proto.NumUpvalues))

Callers 4

TestCheckThreadFunction · 0.45
coCreateFunction · 0.45
TestCoroutineApi1Function · 0.45
TestContextWithCroutineFunction · 0.45

Calls 1

newLStateFunction · 0.70

Tested by 3

TestCheckThreadFunction · 0.36
TestCoroutineApi1Function · 0.36
TestContextWithCroutineFunction · 0.36