-- or --
bool b = string(object x)
This serves to define the string type.
You can also call it like an ordinary function to determine if an object is a string.
When invoked as a function, returns true (1) if x is a string otherwise false (0).
A type check error occurs if a variable declared as a string is assigned with a dword-sequence.
Note the string type is really a sequence of bytes #00..#FF, it can actually hold raw binary as well as ascii and UTF-8 strings, however UTF-32 is 32 bits (or more strictly 21) per character and UTF-16 has 16-bit chars/surrogate pairs, and hence both must instead be kept in a sequence.
The following are also defined in builtins/ptypes.e (not an autoinclude, but used by
pGUI, mpfr, cffi, and
hence indirectly builtins/structs.e, so any of those will include it):
global type nullable_string(object o) - o must be a string or NULL.
global type atom_string(object o) - o must be a string or an unsigned non-fractional machine-word-sized atom, such as the result from allocate_string() or a char* from c_func(), or any other pointer, or an integer index, or NULL, etc.
string s = "hello"
if string(x) then puts(1,x) else -- x must be an atom or dword-sequence ? x end if
There are generic versions of the string function implemented as :%opStr in builtins\VM\pType.e and :%opStr0 in builtins\VM\pJcc.e that
the compiler only invokes as a last resort, preferring instead to inline that functionality if the argument is known to be assigned or the
result variable, if any, is known to be an integer, ie does not require decref/dealloc. The compiler may also completely omit the test
and/or any related code, if type inference/propagation determines that the result will always be true or always false.
As already mentioned, builtins/ptypes.e is where the supplemental types are defined.
|See Also:||atom, integer, sequence, object, Sequences, Core Language, Strings|