Checking parameters in native functions.
| void croc_ex_checkAnyParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that a parameter of any type has been passed at the given index, and if not, throws a ParamError saying that at least index parameters were expected.
| int croc_ex_checkBoolParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that parameter index is a bool, and returns its value.
| crocint_t croc_ex_checkIntParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that parameter index is an int, and returns its value.
| crocfloat_t croc_ex_checkFloatParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that parameter index is a float, and returns its value.
| crocfloat_t croc_ex_checkNumParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that parameter index is an int or float, and returns the value (cast to a float if needed).
| const char* croc_ex_checkStringParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that parameter index is a string, and returns the value.
The same warnings that apply to croc_getString apply here.
| const char* croc_ex_checkStringParamn | ( | CrocThread * | t, |
| word_t | index, | ||
| uword_t * | len | ||
| ) |
Checks that parameter index is a string, and returns the value, as well as returning the byte length of the string through the len parameter.
The same warnings that apply to croc_getString apply here.
| crocchar_t croc_ex_checkCharParam | ( | CrocThread * | t, |
| word_t | index | ||
| ) |
Checks that parameter index is a one-codepoint string, and returns the codepoint.
| void croc_ex_checkInstParam | ( | CrocThread * | t, |
| word_t | index, | ||
| const char * | name | ||
| ) |
Checks that parameter index is an instance of the class name (which is looked up with croc_ex_lookup).
| void croc_ex_checkInstParamSlot | ( | CrocThread * | t, |
| word_t | index, | ||
| word_t | classIndex | ||
| ) |
Same as croc_ex_checkInstParam, but checks that parameter index is an instance of the class in slot classIndex.
| void croc_ex_checkParam | ( | CrocThread * | t, |
| word_t | index, | ||
| CrocType | type | ||
| ) |
Checks that parameter index is of type type, and if not, throws an exception.
| uword_t croc_ex_checkIndexParam | ( | CrocThread * | t, |
| word_t | index, | ||
| uword_t | length, | ||
| const char * | name | ||
| ) |
Checks that parameter index is an integer that is suitable to be used as an index into a list-like object of length .
The parameter can be negative to mean from the end of the object, in which case it will automatically have length added to it before being returned.
| name | is a descriptive name of the object which will be passed to croc_ex_indexError if this function fails. |
| uword_t croc_ex_checkLoSliceParam | ( | CrocThread * | t, |
| word_t | index, | ||
| uword_t | length, | ||
| const char * | name | ||
| ) |
Checks that parameter index is an optional integer that is suitable to be used as a slice index into a list-like object of length .
If no parameter was passed for index, returns 0 (as the default behavior for a null low slice is to slice from the beginning of the list). This differs from croc_ex_checkIndexParam in one important regard: slice indices can be equal to length, whereas normal indices cannot.
| name | is a descriptive name of the object which will be passed to croc_ex_indexError if this function fails. |
| uword_t croc_ex_checkHiSliceParam | ( | CrocThread * | t, |
| word_t | index, | ||
| uword_t | length, | ||
| const char * | name | ||
| ) |
Same as croc_ex_checkLoSliceParam, except defaults to returning length if null was passed for parameter index.
| uword_t croc_ex_checkSliceParams | ( | CrocThread * | t, |
| word_t | index, | ||
| uword_t | length, | ||
| const char * | name, | ||
| uword_t * | hi | ||
| ) |
Combines checking for low and high slice parameters into one function.
The parameters at index and index + 1 are checked as low and high slice indices into a list-like object of length length;
| [out] | hi | will receive the high slice index value. |
| int croc_ex_optBoolParam | ( | CrocThread * | t, |
| word_t | index, | ||
| int | def | ||
| ) |
If there was a bool passed for parameter index, returns its value; otherwise, returns def.
| crocint_t croc_ex_optIntParam | ( | CrocThread * | t, |
| word_t | index, | ||
| crocint_t | def | ||
| ) |
If there was an int passed for parameter index, returns its value; otherwise, returns def.
| crocfloat_t croc_ex_optFloatParam | ( | CrocThread * | t, |
| word_t | index, | ||
| crocfloat_t | def | ||
| ) |
If there was a float passed for parameter index, returns its value; otherwise, returns def.
| crocfloat_t croc_ex_optNumParam | ( | CrocThread * | t, |
| word_t | index, | ||
| crocfloat_t | def | ||
| ) |
If there was a number passed for parameter index, returns its value; otherwise, returns def.
| const char* croc_ex_optStringParam | ( | CrocThread * | t, |
| word_t | index, | ||
| const char * | def | ||
| ) |
If there was a string passed for parameter index, returns its value; otherwise, returns def.
| const char* croc_ex_optStringParamn | ( | CrocThread * | t, |
| word_t | index, | ||
| const char * | def, | ||
| uword_t * | len | ||
| ) |
Same as croc_ex_optStringParam, but returns the length of the string (or of def) through the len parameter.
| crocchar_t croc_ex_optCharParam | ( | CrocThread * | t, |
| word_t | index, | ||
| crocchar_t | def | ||
| ) |
If there was a one-codepoint string passed for parameter index, returns that codepoint; otherwise, returns def.
| int croc_ex_optParam | ( | CrocThread * | t, |
| word_t | index, | ||
| CrocType | type | ||
| ) |
type was passed for parameter index, or 0 if null was passed or no parameter was passed. | uword_t croc_ex_optIndexParam | ( | CrocThread * | t, |
| word_t | index, | ||
| uword_t | length, | ||
| const char * | name, | ||
| crocint_t | def | ||
| ) |
If there was an int passed for parameter index, checks that it's a valid index like croc_ex_checkIndexParam; otherwise, returns def.
| word_t croc_ex_paramTypeError | ( | CrocThread * | t, |
| word_t | index, | ||
| const char * | expected | ||
| ) |
Throws a TypeError exception with a nice message about the expected type for the parameter index, and what type was actually passed instead, like "Expected type 'int' for parameter 2, not 'string'".
If index is 0, the message will say 'this' instead of 'parameter n'.
| void croc_ex_checkValidSlice | ( | CrocThread * | t, |
| crocint_t | lo, | ||
| crocint_t | hi, | ||
| uword_t | length, | ||
| const char * | name | ||
| ) |
Given positive slice indices lo and hi, sees if they define a valid slice within a list-like object of length length.
Calls croc_ex_sliceIndexError if not.
| name | is the descriptive name as listed in croc_ex_sliceIndexError. |
| word_t croc_ex_indexError | ( | CrocThread * | t, |
| crocint_t | index, | ||
| uword_t | length, | ||
| const char * | name | ||
| ) |
Throws a BoundsError exception with a nice message about index being an invalid index in a list-like object of length length, where name is a descriptive name of the object.
For example, the message might be "Invalid Vector index 6 (length: 4)".
| word_t croc_ex_sliceIndexError | ( | CrocThread * | t, |
| crocint_t | lo, | ||
| crocint_t | hi, | ||
| uword_t | length, | ||
| const char * | name | ||
| ) |
Throws a BoundsError exception with a nice message about lo and hi being invalid slice indices in a list-like object of length length, where name is a descriptive name of the object.
For example, the message might be "Invalid Vector slice indices: 2 .. 5 (length: 4)".
1.8.6