github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/object/thread.go (about)

     1  package object
     2  
     3  type ThreadStatus int
     4  
     5  const (
     6  	THREAD_INIT ThreadStatus = iota
     7  	THREAD_SUSPENDED
     8  	THREAD_ERROR
     9  	THREAD_RETURN
    10  	THREAD_RUNNING
    11  )
    12  
    13  type Thread interface {
    14  	Value
    15  
    16  	// common APIs
    17  
    18  	NewTableSize(asize, msize int) Table
    19  	NewTableArray(a []Value) Table
    20  	NewThread() Thread
    21  	NewGoThread() Thread
    22  	NewClosure(p *Proto) Closure
    23  
    24  	Globals() Table
    25  	Loaded() Table
    26  	Preload() Table
    27  
    28  	GetMetatable(val Value) Table
    29  	SetMetatable(val Value, mt Table)
    30  
    31  	// aux API
    32  
    33  	Require(name string, open GoFunction) (Value, bool)
    34  
    35  	// ↓ thread specific APIs
    36  
    37  	// ↓ should be called from vm loop
    38  
    39  	Call(fn Value, args ...Value) ([]Value, *RuntimeError)
    40  
    41  	// ↓ for debug support
    42  
    43  	GetInfo(level int, what string) *DebugInfo
    44  	GetInfoByFunc(fn Value, what string) *DebugInfo
    45  
    46  	Traceback(level int) []*StackTrace
    47  
    48  	GetLocal(level, n int) (name string, val Value)
    49  	SetLocal(level, n int, val Value) (name string)
    50  
    51  	GetLocalName(fn Value, n int) (name string)
    52  
    53  	GetHook() (hook Value, mask string, count int)
    54  	SetHook(hook Value, mask string, count int)
    55  
    56  	// ↓ for coroutine & goroutine support
    57  
    58  	LoadFunc(fn Value)
    59  	Resume(args ...Value) (rets []Value, err *RuntimeError)
    60  
    61  	// ↓ for coroutine support
    62  
    63  	Yield(args ...Value) (rets []Value, err *RuntimeError)
    64  
    65  	IsYieldable() bool
    66  	IsMainThread() bool
    67  
    68  	Status() ThreadStatus
    69  }