Skip to content

Commit

Permalink
Document fallbacks vs messages in @native
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Less authored Nov 6, 2023
1 parent 022b2b1 commit 51e3bae
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions YSI_Server/y_natives/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,38 @@ Alternatively, instead of printing a message or explicitly checking for some fun
}
```

### Fallbacks Vs. Messages

If you provide no fallback a fatal error will be printed in the console (a fatal error in YSI also halts the script, because what else can be done if a function you are trying to use doesn't exist?) A less fatal method would be to provide a fallback function that does nothing but print an error:

```pawn
#include <YSI_Server\y_natives>
@native("frename") Float:floatmod(Float:numerator, Float:denominator)
{
printf("No `floatmod` implementation found.");
// This is trivially easy to implement in pawn, but that's not the example.
return 0.0;
}
```

This message will be printed every time the function is called, as opposed to the default message which is only printed the first time. You can also force the default message to print even when there is a fallback implementation:


```pawn
#include <YSI_Server\y_natives>
@native("frename", .print = true) Float:floatmod(Float:numerator, Float:divisor)
{
// See, I told you.
return floatfract(numerator / denominator) * denominator;
}
```

In that case only a warning will be used instead of a fatal error. As documented elsewhere `.print = true` is standard pawn syntax and allows for giving just one optional argument and leaving the rest as default. This is common in decorators.






0 comments on commit 51e3bae

Please sign in to comment.