Macros | |
#define | croc_getNum croc_asFloat |
Pushing and getting the Croc value types.
#define croc_getNum croc_asFloat |
An alias for croc_asFloat.
word_t croc_pushNull | ( | CrocThread * | t | ) |
Pushes a null onto the stack.
word_t croc_pushBool | ( | CrocThread * | t, |
int | v | ||
) |
Pushes a bool onto the stack with the given truth value.
word_t croc_pushInt | ( | CrocThread * | t, |
crocint_t | v | ||
) |
Pushes an int onto the stack with the given value.
word_t croc_pushFloat | ( | CrocThread * | t, |
crocfloat_t | v | ||
) |
Pushes a float onto the stack with the given value.
word_t croc_pushString | ( | CrocThread * | t, |
const char * | v | ||
) |
Pushes a string onto the stack with the given value.
The string length will be determined with strlen
. Croc makes its own copy of string data, so you don't need to keep the data you passed around.
The string must be valid UTF-8, or an exception will be thrown. (ASCII is valid UTF-8 by design.)
word_t croc_pushStringn | ( | CrocThread * | t, |
const char * | v, | ||
uword_t | len | ||
) |
Just like croc_pushString, but you give the length of the string instead of having it determined with strlen
.
v | is a pointer to the string. |
len | is the length of the string data in bytes. |
int croc_tryPushString | ( | CrocThread * | t, |
const char * | v | ||
) |
Similar to croc_pushString, but instead of throwing an exception for invalid text encoding, returns a boolean value indicating whether or not pushing was successful.
This way you can deallocate buffers if the string is not valid and throw your own exception (or handle it however).
int croc_tryPushStringn | ( | CrocThread * | t, |
const char * | v, | ||
uword_t | len | ||
) |
Just like croc_tryPushString, but you give the length of the string instead of having it determined with strlen
.
v | is a pointer to the string. |
len | is the length of the string data in bytes. |
word_t croc_pushChar | ( | CrocThread * | t, |
crocchar_t | c | ||
) |
Pushes a one-codepoint-long string which contains the given codepoint c
.
word_t croc_pushFormat | ( | CrocThread * | t, |
const char * | fmt, | ||
... | |||
) |
Pushes a formatted string onto the stack.
This uses vsnprintf
internally, so it uses the same formatting specifiers as the printf
family. You don't have to worry about dealing with the length of the output string or anything; it'll be automatically determined for you.
word_t croc_vpushFormat | ( | CrocThread * | t, |
const char * | fmt, | ||
va_list | args | ||
) |
Same as croc_pushFormat, but takes a va_list
instead of variadic arguments.
word_t croc_pushNativeobj | ( | CrocThread * | t, |
void * | o | ||
) |
Pushes a nativeobj onto the stack.
word_t croc_pushThread | ( | CrocThread * | t, |
CrocThread * | o | ||
) |
Pushes a thread o
onto t's
stack.
It is an error if the threads belong to different VMs.
int croc_getBool | ( | CrocThread * | t, |
word_t | slot | ||
) |
slot
(1 for true, 0 for false), or throws an exception if it isn't one. crocint_t croc_getInt | ( | CrocThread * | t, |
word_t | slot | ||
) |
slot
, or throws an exception if it isn't one. crocfloat_t croc_getFloat | ( | CrocThread * | t, |
word_t | slot | ||
) |
slot
, or throws an exception if it isn't one. crocchar_t croc_getChar | ( | CrocThread * | t, |
word_t | slot | ||
) |
If the given slot
contains a string, and that string is exactly one codepoint long, returns the codepoint.
Otherwise, throws an exception.
const char* croc_getString | ( | CrocThread * | t, |
word_t | slot | ||
) |
slot
, or throws an exception if it isn't one.Since Croc strings can contain embedded NUL (codepoint 0) characters, you may be missing the entire string's data with this function. If you really need the whole string, use croc_getStringn.
The string returned from this points into Croc's memory. Do not modify this string, and do not store the pointer unless you know it won't be collected!
const char* croc_getStringn | ( | CrocThread * | t, |
word_t | slot, | ||
uword_t * | len | ||
) |
Like croc_getString, but returns the length of the string in bytes through the len
parameter.
The string returned from this points into Croc's memory. Do not modify this string, and do not store the pointer unless you know it won't be collected!
void* croc_getNativeobj | ( | CrocThread * | t, |
word_t | slot | ||
) |
slot
, or throws an exception if it isn't one. CrocThread* croc_getThread | ( | CrocThread * | t, |
word_t | slot | ||
) |
slot
, or throws an exception if it isn't one.The pointer returned from this points into Croc's memory. Do not modify it, and do not store the pointer unless you know it won't be collected! The only thread that will never be collected is the VM's main thread. If you want to keep a thread around, use the native reference mechanism (croc_ref_create).