View Issue Details

IDProjectCategoryView StatusLast Update
0000646LDMud 3.3LPC Languagepublic2010-01-24 13:03
Reporter_xtian_ Assigned Tozesstra  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version3.3.717 
Target Version3.3.720Fixed in Version3.3.720 
Summary0000646: to_struct( STRUCT ) does nothing but could cast to other template
DescriptionSince casting in LPC is mostly done by to_int(), to_string(), etc ... it would be useful to be able to cast a struct to another struct type by using to_struct().

to_struct() already can cast mappings to specific struct-type by giving: to_struct( MAPPING, STRUCT-TEMPLATE ) so this would be a similar functionality. I propose:

to_struct( STRUCT, STRUCT-TEMPLATE )

Strictly speaking this can already be done by: to_struct( mkmapping( STRUCT ), STRUCT-TEMPLATE ) but I would suggest that this form of re-casting a struct should be stricter and thus throw an error/warning on incompatible struct-types (for ex. which are not inherited from another).
TagsNo tags attached.

Relationships

related to 0000645 new casting structs (to 'inherited struct') does nothing 

Activities

zesstra

2009-06-01 08:05

administrator   ~0001176

Mhmm, I am not sure, if there is any information about the relation of two structs (e.g. b 'inherited' a) at runtime.

_xtian_

2009-06-01 08:07

reporter   ~0001177

Oh. hm. Mist. ;)

Gnomi

2009-06-01 09:01

manager   ~0001181

There is even an efun that can do it: baseof. (But it seems that is has problems with empty base structs.)

zesstra

2009-10-27 10:21

administrator   ~0001562

I like the idea (although I would not call it 'cast', but 'conversion').

We could discuss, if in addition to conversion between structs in the same 'struct-inherit-chain' the conversion from anonymous structs to a specific one should be possible.

And one question is, if you can only convert from an inherited struct to one which inherits or also in the other direction:
struct a_s {int i;};
struct b_s (a_s) {int j; };

Conversion from a_s to b_s is simple (b_s->j would remain 0).
Conversion from b_s to a_s: disallow or just discard b_s->j in the new instance of a_s?

_xtian_

2009-10-27 13:49

reporter   ~0001565

Yes, I have a use-case where I convert up. Although the 'parent-struct' doesn't add members (I use it as a sort of typedef).

zesstra

2009-11-03 16:38

administrator   ~0001591

I created a patch for 3.5 implementing the conversion from a base to one its children and from a child to one of its bases. This is r2794 in trunk.
I plan to apply that later together with some other changes (e.g. for 0000695) to 3.3.

zesstra

2010-01-24 13:03

administrator   ~0001696

So far I heard of no complaints. I applied the changes as well to the 3.3 branch (r2827 - r2832). This should conclude the issue for now.

Issue History

Date Modified Username Field Change
2009-06-01 06:22 _xtian_ New Issue
2009-06-01 07:37 zesstra Project LDMud => LDMud 3.5
2009-06-01 08:05 zesstra Note Added: 0001176
2009-06-01 08:07 _xtian_ Note Added: 0001177
2009-06-01 09:01 Gnomi Note Added: 0001181
2009-10-27 10:21 zesstra Note Added: 0001562
2009-10-27 13:49 _xtian_ Note Added: 0001565
2009-11-03 16:35 zesstra Status new => assigned
2009-11-03 16:35 zesstra Assigned To => zesstra
2009-11-03 16:38 zesstra Note Added: 0001591
2009-11-03 16:38 zesstra Project LDMud 3.5 => LDMud 3.3
2009-11-03 16:39 zesstra Target Version => 3.3.720
2009-11-05 15:08 zesstra Relationship added related to 0000645
2010-01-24 13:03 zesstra Note Added: 0001696
2010-01-24 13:03 zesstra Status assigned => resolved
2010-01-24 13:03 zesstra Fixed in Version => 3.3.720
2010-01-24 13:03 zesstra Resolution open => fixed