Main.hx 929 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. @:native("test.MathOperation")
  2. extern class MathOperation {
  3. public static inline overload function perform(op:Int->Int, value:Int) {
  4. return op(value);
  5. }
  6. public static inline overload function perform(op:Int->Int->Int, value:Int) {
  7. return op(value, value);
  8. }
  9. }
  10. @:native("test.MathOperation")
  11. class MathOperationNotExtern {
  12. public static extern inline overload function perform(op:Int->Int, value:Int) {
  13. return op(value);
  14. }
  15. public static extern inline overload function perform(op:Int->Int->Int, value:Int) {
  16. return op(value, value);
  17. }
  18. }
  19. class Main {
  20. static function main() {
  21. Sys.println(MathOperation.perform(double, 3));
  22. Sys.println(MathOperation.perform(multiply, 3));
  23. Sys.println(MathOperationNotExtern.perform(double, 3));
  24. Sys.println(MathOperationNotExtern.perform(multiply, 3));
  25. }
  26. static function double(a):Int {
  27. return a * 2;
  28. }
  29. static function multiply(a, b):Int {
  30. return a * b;
  31. }
  32. }