47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <emscripten/val.h>
|
|
|
|
#include "canvas_graph.hpp"
|
|
|
|
using namespace emscripten;
|
|
|
|
static std::vector<Expression> s_exprs;
|
|
|
|
int main() {
|
|
return 0;
|
|
}
|
|
|
|
extern "C" void set_num_exprs(size_t num_exprs) {
|
|
s_exprs.resize(num_exprs);
|
|
}
|
|
|
|
extern "C" void set_expr(size_t idx, const char *expr) {
|
|
if (idx >= s_exprs.size())
|
|
return;
|
|
|
|
s_exprs[idx].SetExpression(expr);
|
|
}
|
|
|
|
extern "C" void print_errors() {
|
|
const val document = val::global("document");
|
|
val p = document.call<val>("getElementById", val("output"));
|
|
|
|
std::string errors;
|
|
|
|
for (const auto& expr : s_exprs) {
|
|
const char* error_text = expr.GetErrorText();
|
|
if (error_text) {
|
|
errors += error_text;
|
|
errors += "\n";
|
|
}
|
|
}
|
|
|
|
p.set("innerText", errors.c_str());
|
|
}
|
|
|
|
extern "C" void draw_graph(double xmin, double xmax, double ymin, double ymax, double pointer_x, double pointer_y) {
|
|
struct graph_range range = {xmin, xmax, ymin, ymax};
|
|
canvas_generate_graph(s_exprs.data(), s_exprs.size(), &range, pointer_x, pointer_y);
|
|
}
|