[go: up one dir, main page]

tostring

Macro for implementing toString on your types (and other string-related tools).
https://github.com/Frixuu/ToString/

To install, run:

haxelib install tostring 0.2.2 

See using Haxelib in Haxelib documentation for more information.

README.md

tostring

Haxe macro for automatically generating toString methods.

How to use

  • To generate the method, use this build macro (autobuild also works fine):

`haxe @:build(tostring.ToString.generate())`

  • To exclude a field from being printed out, use meta:

`haxe @:tostring.exclude`

Example

class Animal {
    public var age: Int;
    public var name: Null<String>;
    @:tostring.exclude public var momName: Null<String>;
}

@:build(tostring.ToString.generate())
class Dog extends Animal {
    @:tostring.exclude public var favoriteFood: String;
    public var breed: Breed;
    public var ageInDogYears(get, never): Int;
    public function get_ageInDogYears(): Int {
        return this.age * 7;
    }
}

Example output:

Dog { age: 6, name: Rex, breed: GoldenRetriever, ageInDogYears: 42 }
Contributors
frixuu
Version
0.2.2
Published
2 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub