Saving and loading structs with constructor to/from string?

gnysek

Member
With 2.3+, there's easy option to save/load struct, using json_stringify() and json_parse(). That however saves only normal struct, not those created using new keyword from constructor functions (they will be converted to normal struct too), so I can't later use instanceof on them.

I was searching in manual for a way to save and load struct like this, so I can still use functions (especially static ones) after load, but I came with nothing.

So, my general idea to load struct in a way I mentioned is:
- create new struct using new something()
- load saved struct from file using json_parse()
- get sorted list of properties of both structs using variable_struct_get_names() and compare, if both have same number of them
- iterate over array got from variable_struct_get_names to copy variables from loaded struct to struct object - this will also prevent overriding functions and statics with tampered data (I'm thinking about comparing variable types too).

As long as there's no multi-level structs that doesn't sounds hard, but maybe you know better (and safe) solution?
 
Top