首页 > 解决方案 > 如何将 C 程序与 javascript 连接起来?

问题描述

我有一个用 C 编写的模式发现工具程序。它会自动发现模式。我也有一个用 javascript 编写的 web 应用程序。我想在该 Web 应用程序上可视化从该工具收到的数据。我怎样才能将两者连接起来。即 C 程序工具和 javascript 编写的网络应用程序?

标签: javascriptcdatabase-designtooltipschema

解决方案


在您的 C 代码中放入以下行

1. 在 Javascript 中创建一个函数

  parser.parse( "function faculty(input) {\n"
  "   if(input<=1) return 1;\n"
  "   return input*faculty(input-1);\n"
  "}");

context* c=parser.get_context();

从 C++ 调用函数
valueP result = c->global()"faculty";

提取结果(应为 3628800)

int output = unwrap<int>(result)();

推荐阅读