Reflect.hx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C)2005-2012 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. /**
  23. The Reflect API is a way to manipulate values dynamicly through an
  24. abstract interface in an untyped manner. Use with care.
  25. **/
  26. extern class Reflect {
  27. /**
  28. Tells if an object has a field set. This doesn't take into account the object prototype (class methods).
  29. **/
  30. public static function hasField( o : Dynamic, field : String ) : Bool;
  31. /**
  32. Returns the field of an object, or null if [o] is not an object or doesn't have this field.
  33. **/
  34. public static function field( o : Dynamic, field : String ) : Dynamic;
  35. /**
  36. Set an object field value.
  37. **/
  38. public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void;
  39. /**
  40. Similar to field but also supports property (might be slower).
  41. **/
  42. public static function getProperty( o : Dynamic, field : String ) : Dynamic;
  43. /**
  44. Similar to setField but also supports property (might be slower).
  45. **/
  46. public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void;
  47. /**
  48. Call a method with the given object and arguments.
  49. **/
  50. public static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic;
  51. /**
  52. Returns the list of fields of an object, excluding its prototype (class methods).
  53. **/
  54. public static function fields( o : Dynamic ) : Array<String>;
  55. /**
  56. Tells if a value is a function or not.
  57. **/
  58. public static function isFunction( f : Dynamic ) : Bool;
  59. /**
  60. Generic comparison function, does not work for methods, see [compareMethods]
  61. **/
  62. public static function compare<T>( a : T, b : T ) : Int;
  63. /**
  64. Compare two methods closures. Returns true if it's the same method of the same instance.
  65. **/
  66. public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool;
  67. /**
  68. Tells if a value is an object or not.
  69. **/
  70. public static function isObject( v : Dynamic ) : Bool;
  71. /**
  72. Delete an object field.
  73. **/
  74. public static function deleteField( o : Dynamic, f : String ) : Bool;
  75. /**
  76. Make a copy of the fields of an object.
  77. **/
  78. public static function copy<T>( o : T ) : T;
  79. /**
  80. Transform a function taking an array of arguments into a function that can
  81. be called with any number of arguments.
  82. **/
  83. @:overload(function( f : Array<Dynamic> -> Void ) : Dynamic {})
  84. public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic;
  85. }