我可以使用谷歌 v8 在回调函数中获取 JavaScript 函数C++源文本吗?

Can I get the source text of JavaScript functions in C++ callback function using google v8?

本文关键字:函数 C++ JavaScript 文本 获取 谷歌 v8 我可以 回调 可以使      更新时间:2023-10-16

我正在将google v8嵌入到我的C++程序中。我想将 Javascript 函数的源代码作为参数传递到我的 C++ 函数中。例如:

function ComputePixel(nir, red, blue) {
return (nir-red)/(blue-red)
}
var layer = L8.function(ComputePixel, {
‘nir': L8.select('B5'),
‘red': L8.select('B4'),
‘blue': L8.select('B2’) })

这里的"L8.function"是我C++回调函数。有什么方法可以在我的C++函数中获得计算像素的完整源代码吗?

你应该能够在上面调用ToString:

v8::String::Utf8Value str(args[0]->ToString());