Skip to content

Custom Type Templates

brett hartshorn edited this page Apr 4, 2015 · 8 revisions

customtypes

When using the C++ backend the translator will use standard C++11 template arrays and smart pointers. You can configure the translator to instead output your own custom types by blocking code under with syntax(...): and defining a JSON config file.

JSON Format

The C++ translator type configuration format. Replace My* with your own types.

@myconfig.json

{
	"vector"   : {
		"template": "MyArray<%s>",
		"append"  : "myappend",
		"len"     : "mylen"
	},
	"string" : {
		"type": "MyString",
		"new" : "MyString(%s)"
	},
	"shared" : {
		"template" : "MySharedRef<%s>",
		"type"     : "MySharedRef",
		"reset"    : "myreset"
	},
	"weakref": {
		"template": "MyWeakref<%s>",
		"type": "MyWeakref",
		"lock": "mylock",
		"reset": "myreset",
		"valid": "myvalid"
	},
	"map": {
		"template": "MyMap<%s, %s>",
		"type": "MyMap"
	}
}

note: when using a custom type for weak references you may need to use the builtin weak.valid(ptr) to check if the weak pointer is still pointing to a valid instance. Some smart pointer API's like the one used by Unreal Engine do not allow null pointers, or require a method call to check if the weak reference is valid, using weak.valid(ptr) and defining a method for valid in the config json is the workaround for this issue.

Sidebar

Clone this wiki locally