The Croc Programming Language
VM other

Functions

CrocThreadcroc_vm_getMainThread (CrocThread *t)
 
CrocThreadcroc_vm_getCurrentThread (CrocThread *t)
 
uword_t croc_vm_bytesAllocated (CrocThread *t)
 
word_t croc_vm_pushTypeMT (CrocThread *t, CrocType type)
 
void croc_vm_setTypeMT (CrocThread *t, CrocType type)
 
word_t croc_vm_pushRegistry (CrocThread *t)
 
word_t croc_vm_pushGlobals (CrocThread *t)
 

Detailed Description

Accessing other VM-level objects and features.

Function Documentation

CrocThread* croc_vm_getMainThread ( CrocThread t)

Gets the main thread object of the VM that owns the given thread.

This thread will never be collected, so it's safe to keep a reference to it somewhere (as long as you don't close its owning VM...!).

CrocThread* croc_vm_getCurrentThread ( CrocThread t)

Gets the currently-running thread of the VM that owns the given thread.

If no thread is currently running, returns the main thread.

uword_t croc_vm_bytesAllocated ( CrocThread t)

Returns the number of bytes that are currently allocated by the given thread's VM.

word_t croc_vm_pushTypeMT ( CrocThread t,
CrocType  type 
)

Pushes the given type's global metatable onto the stack, or pushes null if none has been set for that type.

Parameters
typeis the type whose metatable will be retrieved.
Returns
the stack index of the pushed value.
void croc_vm_setTypeMT ( CrocThread t,
CrocType  type 
)

Expects either a namespace or null on top of the stack.

Pops it and sets it as the global metatable for the given type.

Parameters
typeis the type whose metatable will be set (or unset, if the value is null).
word_t croc_vm_pushRegistry ( CrocThread t)

Pushes the VM's native registry namespace onto the given thread's stack.

The native registry is a sort of "hidden global namespace" which is only accessible to native code. In it you can store things which need to be VM-global, but which you don't want script code to access.

word_t croc_vm_pushGlobals ( CrocThread t)

Pushes the VM's global namespace onto the given thread's stack.

This is the same namespace that is accessible through the global _G by default, but since script code can reassign that variable, native code can't depend on it always holding a reference to the globals. Using this function will always push the right namespace.