相关疑难解决方法(0)

使用参数从c ++调用v8 javascript函数

我正在使用c ++和v8,并遇到了以下挑战:我希望能够使用v8在javascript中定义一个函数,然后通过c ++调用该函数.另外,我希望能够从c ++将参数传递给javascript函数.我认为以下示例源代码最能解释它.检查示例代码的末尾,看看我想要完成什么.

#include <v8.h>
#include <iostream>
#include <string>
#include <array>

using namespace v8;

int main(int argc, char* argv[]) {

    // Create a stack-allocated handle scope.
    HandleScope handle_scope;

    // Create a new context.
    Persistent<Context> context = Context::New();
    Context::Scope context_scope(context);
    Handle<String> source;
    Handle<Script> script;
    Handle<Value> result;

    // Create a string containing the JavaScript source code.
    source = String::New("function test_function(test_arg) { var match = 0;if(test_arg[0] == test_arg[1]) { match = 1; }");

    // Compile the source code.
    script = Script::Compile(source);

    // …
Run Code Online (Sandbox Code Playgroud)

c++ v8 embedded-v8

29
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

embedded-v8 ×1

v8 ×1