moonblob icon indicating copy to clipboard operation
moonblob copied to clipboard

Allow classes to add member type hints in their metatable

Open megagrump opened this issue 6 years ago • 0 comments

When serializing tables, the types of each key and value are automatically detected. This works well for default Lua types, but not so well for class and cdata objects.

By adding a table with type information to its metatable, a table should be able to override type detection for some or all of its fields, and also instruct the serializer to skip transient values.

Example:

-- Node is a class
Node.__types = {
	child: Node       -- child is an object of class Node
	data: 'int'       -- data is a cdata object of type int
	transient: false  -- do not serialize field transient
}

Fields that are not listed should still use type detection.

Related to #2, but does not override the whole serialization logic.

megagrump avatar Feb 07 '19 10:02 megagrump