megagrump / moonblob

Binary serialization for moonscript + LuaJIT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow classes to add member type hints in their metatable

megagrump opened this issue · 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.