Skip to content

Reference

Thomas edited this page Jan 31, 2019 · 2 revisions

Reference

This page describes all the functions and values exported by the binary module and the threading.lua module.


Global threading (main context)

The functions and values in this table are all also available when using the gthread table but you will not be able to use all the functions provided by the threading module if you use it.

threading.newThread( [ type ] )

Creates a new thread.

Parameters:
	- type: threading.CONTEXTYPE_* (unused)
Returns:
	- [GThread object]

threading.newChannel()

Creates a new single channel.

Parameters: /
Returns:
	- [GThreadChannel object]

threading.newPacket( [tag] )

Creates a new packet. Optionally assign it a tag for filtering.

Parameters:
	- tag: number
Returns:
	- [GThreadPacket object]

threading.getDetached()

Returns all GThread objects that were garbage-collected.

Parameters: /
Returns:
	- table ( [GThread object] )

threading.CONTEXTYPE_*

CONTEXTYPE_ISOLATED

threading.HEAD_*

Head enum for GThreadPacket:Seek()

HEAD_W
HEAD_R

threading.LOC_*

Location enum for GThreadPacket:Seek()

LOC_START
LOC_CUR
LOC_END

threading.Version

Version of the gthread module


Global engine (gthread context)

The global object engine represents the thread itself and is only available inside GThread contexts.

engine:Block( [ handles... ] )

Blocks the thread execution until one of the passed handles is ready. Returns which handle was marked as ready along with its results.

Parameters:
	- handles: varargs... ( number )
Returns:
	- handle: number
	- ...
Timing:
	- Blocks until a handle in `handles` is ready

engine:OpenChannel( name )

Equivalent of GThread:OpenChannel() with the return values flipped.

engine:CreateTimer( ms )

Creates a timer handle that will resolve in the given amount of milliseconds.

Parameters:
	- ms: number
Returns:
	- handle: number

engine:Sleep( ms ) *

*Added by threading.lua

Creates a timer and blocks on it. if ran in a coroutine it will yield the coroutine instead. (passing the created handle)

Parameters:
	- ms: number
Returns:
	- handle: number
Timing:
	- Blocks for `ms` milliseconds

engine.newChannel()

Equivalent of threading.newChannel()

engine.newPacket( [tag] )

Equivalent of threading.newPacket()

engine.HEAD_*

Equivalent of threading.HEAD\_\*

engine.LOC_*

Equivalent of threading.LOC\_\*


Metatable GThread

These are the functions available on objects returned by threading.newThread().

GThread:Run()

GThread:OpenChannel()

GThread:AttachChannel()

GThread:Kill()

GThread:Terminate()


Metatable GThreadChannel

These are the functions available on objects returned by threading.newChannel(). The Data functions are also available.

GThreadChannel:StartPacket()

GThreadChannel:PushPacket()

GThreadChannel:GetHandle()

GThreadChannel:Receive() *

GThreadChannel:Wait() *

GThreadChannel:GetInPacket()

GThreadChannel:GetOutPacket()

GThreadChannel:SetFilter()

GThreadChannel:PullPacket()

GThreadChannel:Close()


Metatable GThreadPacket

These are the functions available on objects returned by threading.newPacket(). The Data functions are also available.

GThreadPacket:Seek()

GThreadPacket:GetSize()

GThreadPacket:Slice()

GThreadPacket:SetTag()

GThreadPacket:GetTag()


Data functions

These functions apply to both GThreadPacket and GThreadChannel objects.

In the case of GThreadChannel:

  • Write* functions use the outgoing packet of the channel object.
  • Read* functions use the incoming packet of the channel object.

Packet:..Byte()

Packet:..Short()

Packet:..Int()

Packet:..Long()

Packet:..UByte()

Packet:..UShort()

Packet:..UInt()

Packet:..ULong()

Packet:..Size()

Packet:..Float()

Packet:..Double()

Packet:..Data()

Packet:..String()

Packet:..Function()

Packet:..Type() *

Packet:..Table() *

Packet:..Varargs() *

Packet:..Bool() *