C++ Like Structs in Script?

Started by
3 comments, last by WitchLord 6 months, 1 week ago

Hey, Simple stupid question, Is it possible to create structs in AngelScript? I don't mean exposed structs. Something like :

struct TestDataStruct
{
	int		someInt;
	float		someFloat;
	uint64		someUInt64;
	string		someString;
};

If I use class instead of struct it works, But with struct I get following error :

Error : Expected one of: get, set, }
Error : Instead found reserved keyword 'int'
Error : Unexpected token '}'

I'm trying to implement a JSON serializer.

  • The universe is basically an animal. It grazes on the ordinary.
Advertisement

‘struct’ is not a recognized keyword at this moment. Use ‘class’ for this.

I have an entry on my to-do list to add support for ‘struct’, which would use a different memory model than classes to be compatible with C++ structs. But this is very low priority and may never be implemented.

You may want to take a look at Hanan's JSON parser & writer for AngelScript. Or were you planning on implementing a json serializer in the script language itself?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

@WitchLord Just wanted to make sure and this JSON parser was exactly what I was looking for, Thank you <3

By any chance do you have any idea how to automate serializing like C# [Serializable] for JSON?

  • The universe is basically an animal. It grazes on the ordinary.

You could potentially use the metadata system in the CScriptBuilder add-on, to collect information on what to serialize in a class, and then build a generic serialize function that can read the serializable attributes from the class and convert them to the json structure.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement