-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "tinyexpr.h" | ||
#include <stdio.h> | ||
|
||
|
||
/* An example of calling a C function. */ | ||
double my_sum(double a, double b) { | ||
printf("Called C function with %f and %f.\n", a, b); | ||
return a + b; | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
te_variable vars[] = { | ||
{"mysum", my_sum, TE_FUNCTION2} | ||
}; | ||
|
||
const char *expression = "mysum(5, 6)"; | ||
printf("Evaluating:\n\t%s\n", expression); | ||
|
||
int err; | ||
te_expr *n = te_compile(expression, vars, 1, &err); | ||
|
||
if (n) { | ||
const double r = te_eval(n); | ||
printf("Result:\n\t%f\n", r); | ||
te_free(n); | ||
} else { | ||
/* Show the user where the error is at. */ | ||
printf("\t%*s^\nError near here", err-1, ""); | ||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters