Skip to content

Instantly share code, notes, and snippets.

@waneck
Created September 14, 2012 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waneck/3723305 to your computer and use it in GitHub Desktop.
Save waneck/3723305 to your computer and use it in GitHub Desktop.
class LimitMinMax implements haxe.rtti.Meta
{
public var max:Float;
public var min:Float;
public function new(max, min)
{
this.max = max;
this.min = min;
}
}
import LimitMinMax;
class Test
{
@LimitMinMax public var field2:Float; //error: limitMinMax takes two arguments
@LimitMinMax(10, 0) public var field3:Float; //alright! -> if you want to exclude this, do a verification step with macros
@LimitMinMax(0, 10) public var field3:Float; //alright!
@mylib.Limit.LimitMinMax(0, 10) public var field3:Float; //alright, with fully qualified name!
public static function main()
{
new B();
var metas = haxe.rtti.Meta.getFields(Test);
trace(Std.is(metas.field3, LimitMinMax)); //true
}
}
@jasononeil
Copy link

I tried to follow through and think about all the different use cases:

import LimitMinMax;

class Test 
{
    // Use constructor.  Must be a valid type that has been imported.
    @LimitMinMax(0,10)
    public var field1:Float; //alright!

    // Use fully qualified name, constructor.  Must be a valid type.
    @mylib.Limit.LimitMinMax(0, 10) 
    public var field2:Float;

    // Use local, not typed metadata.  Name follows local variable naming rules in haxe (must start lower case character, no periods)
    @debug @values(-1,100) 
    var x : Int;

    // Set typed metadata properties - Do we allow any of this?
    @LimitMinMax.min(0) 
    @LimitMinMax.max(10) 
    var y : Int;

    // Or once it's imported, even use it simpler
    @min(0) 
    @max(10) 
    var z : Int;

    // Current generic boolean metadata (if it's defined, true, if it is never defined, false)
    @test
    function myTest() {}

    // The namespaced equivalent of that?
    @munit.Tests.myTest
    function myTest() {}

    // Or use a constructor?
    @munit.Test(true)
    function myTest() {}

    // Or something else?
}

The issues to resolve:

  • Do we still support local, untyped metadata?
  • And if we do, how to distinguish between typed and untyped?
  • And then with typed metadata, can we access the properties or only use the constructors?
  • What is the typed and namespaced equivalent of metadata with no content, eg "@test"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment