Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ Like Structs in Script?

Started by The Crypt Oct 27, 2023 at 9:51 PM 3 replies 5.8k views
Original Post
The Crypt
The Crypt

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.
WitchLord
WitchLord

‘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 - <a href="http://www.angelcode.com/tower" rel
The Crypt
The Crypt

@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.
WitchLord
WitchLord

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 - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.