Dealing with softcode datatypes in hardcode
Dealing with softcode datatypes in hardcode raevnos Wed, 2003-06-25 23:19When adding a new softcode function to the Penn source, you'll quickly notice that all the arguments are passed as strings (In the args array), and it returns values by adding them to another string. But in softcode, you have functions that expect numbers, dbrefs, etc. Penn provides a set of functions for use in the hardcode for converting strings to and from C types upon which real work can be done, and for appending values to the return string buffer.
They're described in the following table:
Datatype | C type | Is a TYPE | String to C | C to string | Adding to a string buffer |
---|---|---|---|---|---|
Integer | int | is_integer(char*) and is_strict_integer(char*) | parse_integer(char*) | unparse_integer(int) | safe_integer(int, buff, bp) |
Unsigned Integer | unsigned int | is_uinteger(char*) | parse_uinteger(char*) | unparse_uinteger(unsigned int) | safe_uinteger(unsigned int, buff, bp) |
Floating-point number | NVAL | is_number(char*) and is_strict_number(char*) | parse_number(char*) | unparse_number(NVAL) | safe_number(NVAL, buff, bp) |
Dbref | dbref | is_dbref(char*) | parse_dbref(char*) | unparse_dbref(dbref) | safe_dbref(dbref, buff, bp) |
Boolean | int | is_boolean(char *) | parse_boolean(char *) | unparse_boolean(int) | safe_boolean(int, buff, bp) |
Character | char | N/A | N/A | N/A | safe_chr(char, buff, bp) |
String | char* | N/A | N/A | N/A | safe_str(string, buff, bp, string), safe_strl(string, length, buff, bp) |
|