Reflect.hx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. /**
  26. The Reflect API is a way to manipulate values dynamicly through an
  27. abstract interface in an untyped manner. Use with care.
  28. **/
  29. extern class Reflect {
  30. /**
  31. Tells if an object has a field set. This doesn't take into account the object prototype (class methods).
  32. **/
  33. public static function hasField( o : Dynamic, field : String ) : Bool;
  34. /**
  35. Returns the field of an object, or null if [o] is not an object or doesn't have this field.
  36. **/
  37. public static function field( o : Dynamic, field : String ) : Dynamic;
  38. /**
  39. Set an object field value.
  40. **/
  41. public static function setField( o : Dynamic, field : String, value : Dynamic ) : Void;
  42. /**
  43. Similar to field but also supports property (might be slower).
  44. **/
  45. public static function getProperty( o : Dynamic, field : String ) : Dynamic;
  46. /**
  47. Similar to setField but also supports property (might be slower).
  48. **/
  49. public static function setProperty( o : Dynamic, field : String, value : Dynamic ) : Void;
  50. /**
  51. Call a method with the given object and arguments.
  52. **/
  53. public static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic;
  54. /**
  55. Returns the list of fields of an object, excluding its prototype (class methods).
  56. **/
  57. public static function fields( o : Dynamic ) : Array<String>;
  58. /**
  59. Tells if a value is a function or not.
  60. **/
  61. public static function isFunction( f : Dynamic ) : Bool;
  62. /**
  63. Generic comparison function, does not work for methods, see [compareMethods]
  64. **/
  65. public static function compare<T>( a : T, b : T ) : Int;
  66. /**
  67. Compare two methods closures. Returns true if it's the same method of the same instance.
  68. **/
  69. public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool;
  70. /**
  71. Tells if a value is an object or not.
  72. **/
  73. public static function isObject( v : Dynamic ) : Bool;
  74. /**
  75. Delete an object field.
  76. **/
  77. public static function deleteField( o : Dynamic, f : String ) : Bool;
  78. /**
  79. Make a copy of the fields of an object.
  80. **/
  81. public static function copy<T>( o : T ) : T;
  82. /**
  83. Transform a function taking an array of arguments into a function that can
  84. be called with any number of arguments.
  85. **/
  86. public static function makeVarArgs( f : Array<Dynamic> -> Dynamic ) : Dynamic;
  87. }