View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000429 | LDMud 3.3 | Efuns | public | 2005-12-30 23:22 | 2007-10-06 19:55 |
| Reporter | ford | Assigned To | |||
| Priority | normal | Severity | feature | Reproducibility | always |
| Status | closed | Resolution | won't fix | ||
| Summary | 0000429: to_int() will not accept object type paramater. | ||||
| Description | to_int() will not accept type object. Casts of object to int fail. nul object = 0 non-nul = (!0) | ||||
| Additional Information | SYNOPSIS int to_int(string) int to_int(float) int to_int(int) int to_int(closure) (int)<value> DESCRIPTION Floats are truncated to integer values, strings with leadings digits are converted to integers up to the first non-digit. lfun-closures are converted into their function index, variable closure are converted into their variable index. Integers are just returned. Regarding floats, it is important to keep rounding effects in mind: to_int(3.1*10.0) does not return 31, but instead 30, because internally the result of the multiplication is 30.999999 . BUGS The cast notation only works if the precise type of <value> is known at compile-time. This will not be fixed - use the function form instead. HISTORY Introduced in 3.2.1@2 SEE ALSO to_string(E), sscanf(E) | ||||
| Tags | No tags attached. | ||||
|
|
Well, there isn't exactly a good way to convert an object into a number. |
|
|
int to_int(object obj) { if (obj == NULL) return 0; else return (!0); } |
|
|
int to_int(object obj) { if (obj == NULL) return 0; else return (int)obj; } |
|
|
This is only needed to tell if an object is void or not, for "if" statments. I dont care what the value is just whether or not it's void. I dont care about to_int(), except typecasts seem to use to_int(). |
|
|
Hmm, why don't you just use the object directly (if(ob) ...)? To get an integer, that shows the existence of an object, you can use: int i = ob && 1; |
|
|
Because when you do "if (ob)", the ob is automaticlly typecast to int, and ldmud uses to_int() when typecasting to integers. |
|
|
This is not a bug. While C does casts values to numbers when it requires a yes/no decision, even that is not a typecast, but a reinterpret_cast: if ("0") will evaluate to true. LPC does what could be called a conversion to boolean, which for everything but numbers results in a check if the expression has a value at all: string s; if (s) --> false s = ""; if (s) --> true It could be done differently (and other languages do), but this way LPC gives you an easy way to check whether a variable has been set or not. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2005-12-30 23:22 | ford | New Issue | |
| 2006-03-01 12:32 |
|
Note Added: 0000480 | |
| 2006-03-03 06:33 | ford | Note Added: 0000486 | |
| 2006-03-03 06:35 | ford | Note Added: 0000487 | |
| 2006-03-03 06:36 | ford | Note Edited: 0000486 | |
| 2006-03-03 06:36 | ford | Note Edited: 0000487 | |
| 2006-03-03 06:36 | ford | Note Edited: 0000487 | |
| 2006-03-03 06:40 | ford | Note Added: 0000488 | |
| 2006-03-03 06:44 | ford | Note Edited: 0000488 | |
| 2006-03-03 06:48 | Gnomi | Note Added: 0000489 | |
| 2006-03-08 23:18 | ford | Note Added: 0000493 | |
| 2006-03-08 23:35 |
|
Status | new => resolved |
| 2006-03-08 23:35 |
|
Resolution | open => won't fix |
| 2006-03-08 23:35 |
|
Assigned To | => lars |
| 2006-03-08 23:35 |
|
Note Added: 0000494 | |
| 2007-10-06 19:55 |
|
Status | resolved => closed |