C# attributes

62 views
Skip to first unread message

Fernando Serboncini

unread,
Jun 2, 2016, 3:41:06 PM6/2/16
to Haxe, wan...@gmail.com
I'm trying to revive Unity support for Haxe. The HEAD CS generator is pretty good at using C# dlls, so thanks for that! 

One issue I'm having is: how to do C# attributes in Haxe? I.e., like [Range(-100, 100)] or [ExecuteInEditMode]?

Thanks,
Fernando

Dan Korostelev

unread,
Jun 2, 2016, 3:49:51 PM6/2/16
to Haxe, wan...@gmail.com
Hey!

You can do that using the `@:meta` metadata. For example: @:meta(UnityEngine.Range(-100, 100)). For more complex cases you could also use string constant for that metadata, like @:meta("global::WhateverNameSpace.MyAttribute(...)")

четверг, 2 июня 2016 г., 22:41:06 UTC+3 пользователь Fernando Serboncini написал:

Fernando Serboncini

unread,
Jun 2, 2016, 3:52:04 PM6/2/16
to Haxe, wan...@gmail.com
thanks :)

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Cauê Waneck

unread,
Jun 2, 2016, 3:53:31 PM6/2/16
to Dan Korostelev, Haxe
You can also use strict metadata by using the `@:strict` meta. There is still not much documentatn about it, but you can see the unit tests (e.g.) https://github.com/HaxeFoundation/haxe/blob/development/tests/unit/src/unit/TestCSharp.hx#L693 for examples on how to use them

Fernando Serboncini

unread,
Jun 2, 2016, 4:28:49 PM6/2/16
to haxe...@googlegroups.com, Dan Korostelev
On a related note, is there a way to globally replace "trace" ?

I know one can do haxe.Log.trace = function(v, ?posInfo) {...}, but is there a way to do this that would work on Unity? I.e., where I don't have a main entry point and don't want to do this before every use?




Cauê Waneck

unread,
Jun 2, 2016, 5:08:14 PM6/2/16
to haxe...@googlegroups.com, Dan Korostelev
You can use `static function __init__()` to initialize functions like these
Reply all
Reply to author
Forward
0 new messages