- # Return atan2l( self, x ) from libmath
- fun atan_with( x : Int ) : Float `{
- return atan2( recv, x );
- `}
-
- # This method callback to Nit methods from C code
- # It will use from C code:
- # * the local fib method
- # * the + operator, a method of Int
- # * to_s, a method of all objects
- # * String::to_cstring, a method of String to return an equivalent char*
- fun foo import fib, +, to_s, String::to_cstring `{
- long recv_fib = Int_fib( recv );
- long recv_plus_fib = Int__plus( recv, recv_fib );
+ # Print the result of adding `self` to `self.fib` with callbacks from C
+ #
+ # This method illustrates many forms of callbacks from C,
+ # but it would have been better implemented in Nit (as done by `bar`).
+ #
+ # It is recommended to avoid callbacks when possible, use each language according to their strengths.
+ # Nit is better than C to call methods and manipulate objects.
+ # C has easy access to system functions, native libraries and it does low-level stuff.
+ #
+ # The implementation calls:
+ # * the local `fib` method,
+ # * the `+` operator, a method of `Int`,
+ # * `to_s`, a method of all objects,
+ # * `String.to_cstring`, a method of `String` to get as a `char*`.
+ fun foo import fib, +, to_s, String.to_cstring `{
+ long self_fib = Int_fib(self);
+ long self_plus_fib = Int__plus(self, self_fib);