Macros | |
#define | croc_isTrue croc_asBool |
All sorts of simple operations on values of any type.
#define croc_isTrue croc_asBool |
An alias for croc_asBool.
word_t croc_foreachBegin | ( | CrocThread * | t, |
uword_t | numContainerVals | ||
) |
This, croc_foreachNext, and croc_foreachEnd are used together to perform the equivalent of the Croc 'foreach'
loop.
Here's how you use them:
'foreach'
loop.croc_foreachBegin
, telling it how many values you pushed, and store the value it returns.croc_foreachBegin
returned and the number of indices you want. Use the return value from croc_foreachNext
to determine if the loop should continue.It sounds complex, but it's easier in an example. Let's translate the following loop into API calls.
In the native API:
numContainerVals | is how many values you pushed for the container. This must be 1, 2, or 3, and there must be that many values on top of the stack. |
int croc_foreachNext | ( | CrocThread * | t, |
word_t | state, | ||
uword_t | numIndices | ||
) |
Gets the next values in a foreach loop, as demonstrated in croc_foreachBegin.
state | is the value that was returned from croc_foreachBegin. |
numIndices | is how many indices you want. In Croc, this would be the number of variables to the left of the semicolon in the 'foreach' . You can indeed pass 1 for this parameter, and it will work the same way as in Croc; the first index returned from the iterator function will be ignored, and only the second index will be on top of the stack. |
void croc_foreachEnd | ( | CrocThread * | t, |
word_t | state | ||
) |
Cleans up a foreach loop, as demonstrated in croc_foreachBegin.
You should call this no matter how you exit the loop (unless you return from a native function inside the loop... then you don't have to). This will check that the stack is in the appropriate configuration and will pop the bookkeeping variables that croc_foreachBegin pushed.
state | is the value that was returned from croc_foreachBegin. |
void croc_removeKey | ( | CrocThread * | t, |
word_t | obj | ||
) |
Removes the key-value pair from the table or namespace at slot obj
whose key is the value on top of the stack, then pops that value.
For tables, you can also do this by index-assigning null
into a key, but for namespaces this is the only way to remove a key-value pair.
word_t croc_pushToString | ( | CrocThread * | t, |
word_t | slot | ||
) |
Pushes a string representation of the value at slot
by essentially calling the Croc toString
on it.
word_t croc_pushToStringRaw | ( | CrocThread * | t, |
word_t | slot | ||
) |
Pushes a raw string representation of the value at slot
by essentially calling the Croc rawToString
on it.
int croc_asBool | ( | CrocThread * | t, |
word_t | slot | ||
) |
The equivalent of using as bool
in Croc.
slot
converts to true
, and zero otherwise. crocint_t croc_asInt | ( | CrocThread * | t, |
word_t | slot | ||
) |
The equivalent of using as int
in Croc.
slot
typecast to an integer. crocfloat_t croc_asFloat | ( | CrocThread * | t, |
word_t | slot | ||
) |
The equivalent of using as float
in Croc.
slot
typecast to a float. int croc_in | ( | CrocThread * | t, |
word_t | item, | ||
word_t | container | ||
) |
The equivalent of Croc's 'in'
operator.
Calls opIn
metamethods if necessary.
item
is in the value at container
. crocint_t croc_cmp | ( | CrocThread * | t, |
word_t | a, | ||
word_t | b | ||
) |
The equivalent of Croc's <=>
operator.
Calls opCmp
metamethods if necessary.
a
and b
. int croc_equals | ( | CrocThread * | t, |
word_t | a, | ||
word_t | b | ||
) |
The equivalent of Croc's ==
operator.
Calls opEquals
metamethods if necessary.
a
and b
are equal. int croc_is | ( | CrocThread * | t, |
word_t | a, | ||
word_t | b | ||
) |
The equivalent of Croc's is
operator.
a
and b
are identical. word_t croc_idx | ( | CrocThread * | t, |
word_t | container | ||
) |
The equivalent of Croc's a[b]
operation.
This expects the index to be on top of the stack, and it is replaced with the result of the indexing operation. Calls opIndex
metamethods if necessary.
container | is the object to index. |
void croc_idxa | ( | CrocThread * | t, |
word_t | container | ||
) |
The equivalent of Croc's a[b] = c
operation.
This expects the value to be assigned (c
) to be on top of the stack, and the index (b
) below it. Calls opIndexAssign
metamethods if necessary. Pops both the value and the index from the top of the stack.
container | is the object to index-assign. |
word_t croc_idxi | ( | CrocThread * | t, |
word_t | container, | ||
crocint_t | idx | ||
) |
A convenience function when you want to index a container using an integer index.
Pushes the result of indexing on top of the stack.
container | is the object to index. |
idx | is the integer index. |
void croc_idxai | ( | CrocThread * | t, |
word_t | container, | ||
crocint_t | idx | ||
) |
A convenience function when you want to index-assign a container using an integer index.
Expects the value to be on top of the stack, and pops it.
container | is the object to index-assign. |
idx | is the integer index. |
word_t croc_slice | ( | CrocThread * | t, |
word_t | container | ||
) |
The equivalent of Croc's a[b ..
c]
operation.
Expects the slice indices on top of the stack (the high index on top, and the low index below it). Calls opSlice
metamethods if necessary. Pops the slice indices and pushes the result.
container | is the object to slice. |
void croc_slicea | ( | CrocThread * | t, |
word_t | container | ||
) |
The equivalent of Croc's a[b ..
c] = d
operation.
Expects the value to be assigned into the slice on top, and the slice indices below it (the high index below the value, and the low index below that). Calls opSliceAssign
metamethods if necessary. Pops all three values.
container | is the object to slice-assign. |
word_t croc_field | ( | CrocThread * | t, |
word_t | container, | ||
const char * | name | ||
) |
The equivalent of Croc's a.name
operation, this gets the field named name
from the object in container
and pushes the result.
Calls any opField
metamethods if necessary.
word_t croc_fieldStk | ( | CrocThread * | t, |
word_t | container | ||
) |
Same as croc_field, but expects the field name to be on top of the stack, which is replaced with the result of the field access (like how croc_idx works).
void croc_fielda | ( | CrocThread * | t, |
word_t | container, | ||
const char * | name | ||
) |
The equivalent of Croc's a.name = b
operation, this sets the field named name
in container
to the value on top of the stack, and then pops that value.
Calls any opFieldAssign
metamethods if necessary.
void croc_fieldaStk | ( | CrocThread * | t, |
word_t | container | ||
) |
Same as croc_fielda, but expects the value on top of the stack and the name of the field to assign to be in the slot below it (like how croc_idxa works).
Pops both the name and value.
word_t croc_rawField | ( | CrocThread * | t, |
word_t | container, | ||
const char * | name | ||
) |
Same as croc_field, but does not call any opField
metamethods.
word_t croc_rawFieldStk | ( | CrocThread * | t, |
word_t | container | ||
) |
Same as croc_fieldStk, but does not call any opField
metamethods.
void croc_rawFielda | ( | CrocThread * | t, |
word_t | container, | ||
const char * | name | ||
) |
Same as croc_fielda, but does not call any opFieldAssign
metamethods.
void croc_rawFieldaStk | ( | CrocThread * | t, |
word_t | container | ||
) |
Same as croc_fieldaStk, but does not call any opFieldAssign
metamethods.
word_t croc_hfield | ( | CrocThread * | t, |
word_t | container, | ||
const char * | name | ||
) |
Gets the hidden field named name
from the class or instance in container
and pushes it.
word_t croc_hfieldStk | ( | CrocThread * | t, |
word_t | container | ||
) |
Same as croc_hfield, but expects the name on top of the stack and replaces the name with the value of the field (like croc_fieldStk).
void croc_hfielda | ( | CrocThread * | t, |
word_t | container, | ||
const char * | name | ||
) |
Assigns the value on top of the stack into hidden field named name
into the class or instance in container
and pops the value (like croc_fielda).
void croc_hfieldaStk | ( | CrocThread * | t, |
word_t | container | ||
) |
Same as croc_hfielda but expects the value to be on top of the stack and the name of the hidden field to be below it, and pops both (like croc_fieldaStk).
word_t croc_pushLen | ( | CrocThread * | t, |
word_t | slot | ||
) |
The equivalent of Croc's #
operator, this pushes the length of the object in slot
, calling opLength
metamethods if necessary.
crocint_t croc_len | ( | CrocThread * | t, |
word_t | slot | ||
) |
Similar to croc_pushLen, except it expects the length to be an integer (throwing an error if not), and doesn't push the length onto the stack, instead returning it.
slot
. void croc_lena | ( | CrocThread * | t, |
word_t | slot | ||
) |
Sets the length of the object at slot
to the value on top of the stack, calling opLengthAssign
metamethods if necessary, and pops the length.
void croc_lenai | ( | CrocThread * | t, |
word_t | slot, | ||
crocint_t | length | ||
) |
Same as croc_lena, but this is a convenience function which sets the length of the object at slot
to the length given by length
instead of using a value on the stack.
The stack is left unchanged.
word_t croc_cat | ( | CrocThread * | t, |
uword_t | num | ||
) |
The equivalent of Croc's ~
operator, this concatenates the top num
values on the stack, calling opCat
and opCat_r
metamethods as necessary.
The top num
values are popped, and the result of concatenation is pushed in their place.
void croc_cateq | ( | CrocThread * | t, |
word_t | dest, | ||
uword_t | num | ||
) |
The equivalent of Croc's ~=
operator, this appends the top num
values to the object in dest
, calling opCatAssign
metamethods as necessary.
The top num
values are popped.