我一直在试验ES6类,我想知道你是否可以动态更改类名?例如
class [Some dynamic name] {};
Run Code Online (Sandbox Code Playgroud) 我有一些现有的C++代码,可以在独立的C++应用程序中进行数值处理.我现在想在新的node.js应用程序中使用该代码.
研究如何从node.js访问C++代码,有两个选项:
node-ffi似乎是访问现有库的一个很好的选择,但我是否正确地思考如果我使用node-ffi我将不得不编写一个C包装器来使我的C++可访问?(这是我可以通过Visual Studio在Windows上使用简单的测试用例的唯一方法).
对于我的情况,我的源代码已经在C++中,而不是C,在上面两个选项之间选择有哪些注意事项?
我正在使用HapiJs Restful Web服务并尝试启用cors,因此即使来自不同域的任何客户端也可以使用我的服务.我在服务器连接对象中尝试了cors = true但没有工作.
我正在开发的Windows简单节点的WebKit应用程序(Vista中,7,...),我需要使用一些WinAPI的功能,特别是,RegisterHotKey和SendInput,结合全系统热键,并基于该击键.node-webkit没有提供这样的API,所以我想使用node-ffi来调用这些函数.
我是WinAPI开发的新手,所以我读了一些MSDN手册,但发现大多数例子都创建了窗口,消息循环,消息处理程序等等.所以我不太了解,如何从node-webkit正确调用WinAPI,而不创建单独的窗口?
Node-ffi教程没有涵盖这种情况,所以我找到了节点Windows库,但它似乎只是通过节点实现Windows应用程序.
有没有办法在不创建Windows应用程序的情况下实现本机调用?这样做的正确方法是什么?
我开始使用Hapi nodejs框架.我使用的是"hapi@17.2.0",这是我在server.js中的代码来启动应用程序.
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 3000, host: 'localhost' });
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Hello, world!');
}
});
server.start((err) => {
if (err) {
throw err;
}
console.log(`Server running at: ${server.info.uri}`);
});
Run Code Online (Sandbox Code Playgroud)
node server.js从终端运行我的项目之后,它会抛出错误,如下所示.
/var/www/html/hello_hapi/server.js:6
server.connection({ port: 3000, host: 'localhost' });
^
TypeError: server.connection is not a function
at Object.<anonymous> (/var/www/html/hello_hapi/server.js:6:8)
at Module._compile (module.js:612:30)
at Object.Module._extensions..js (module.js:623:10)
at Module.load (module.js:531:32)
at tryModuleLoad (module.js:494:12)
at …Run Code Online (Sandbox Code Playgroud) 我想在Javascript中解析C头文件.有没有这样的图书馆?否则,任何提示可以帮助我开始?
更新:我的最终目标是自动构建node-ffi的接口.解析器不一定必须在Javascript中,只要它可以吐出Javascript可理解的格式.如果我自己很难开发,我可能不得不采用现成的解决方案......?
我正在使用node-ffi来调用一个函数,该函数将out-param作为指针到指针结构的指针.有没有办法使用ref-struct和ref-array来访问我得到的数组?
struct = require("ref-struct");
var rect_type = struct({
'x': 'int',
'y': 'int',
'width': 'int',
'height': 'int',
});
var rotation_type = struct({
'yaw': 'short',
'pitch': 'short',
'roll': 'short'
});
var face_type = struct({
'rect' : rect_type,
'rotation' : rotation_type,
'confidence' : 'double'
});
Run Code Online (Sandbox Code Playgroud)
我能够在函数调用之后从指针中获取第一个结构,但是我无法获得数组的其余部分:
var mylib = ffi.Library('lib/libN', {
'GetFaces' : [ 'int', [ 'pointer' ] ]
});
var pface_type = ref.refType(face_type);
var ppface = ref.alloc(pface_type);
result = mylib.GetFaces(ppface);
face = ppface.deref().deref();
console.log("X:" + face.rect.x + " Y:" + face.rect.y);
Run Code Online (Sandbox Code Playgroud)
有没有办法将参数声明为结构数组?我试过这个,但它不起作用: …
我想从节点 js 加载一个 dll 文件。这是头文件:
#pragma once
#ifdef __cplusplus
#define EXAMPLE __declspec(dllexport)
extern "C" {
EXAMPLE int Add(int, int);
}
#endif
Run Code Online (Sandbox Code Playgroud)
在编译为,我选择“编译为 C 代码”
在主动解决方案平台中,我选择 x64
然后,我使用 ffi 模块加载它:
var ffi = require('ffi');
var Lib = ffi.Library('test', {'Add' : ['int',['int','int']]});
Run Code Online (Sandbox Code Playgroud)
但我得到了一个错误:
C:\Users\TheHai\node_modules\ffi\lib\dynamic_library.js:112
throw new Error('Dynamic Symbol Retrieval Error: ' + this.error())
^
Error: Dynamic Symbol Retrieval Error: Win32 error 127
at DynamicLibrary.get (C:\Users\TheHai\node_modules\ffi\lib\dynamic_library.js:112:11)
at C:\Users\TheHai\node_modules\ffi\lib\library.js:50:19
at Array.forEach (native)
at Object.Library (C:\Users\TheHai\node_modules\ffi\lib\library.js:47:28)
at Object.<anonymous> (C:\Users\TheHai\Downloads\Compressed\nodejs-websocket-master\samples\chat\server.js:8:15)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10) …Run Code Online (Sandbox Code Playgroud) 在node.js中(使用Hapi框架)我正在为用户创建链接以允许我的应用程序读取用户帐户.Google处理该请求并询问是否授予权限.然后谷歌使用GET参数作为响应代码重定向到我的服务器,这里我有一个问题.
Google Chrome不会发送包含会话ID的Cookie.
如果我将该cookie标记为cookie编辑扩展中的会话cookie,则会发送该cookie.php中的行为相同,但php在创建会话时将cookie标记为会话,因此不存在问题.我正在使用插件hapi-auth-cookie,它创建会话并处理有关它的一切.我还在hapi-auth-cookie设置中将该cookie标记为非HttpOnly,因为这是第一个区别,我注意到,当我在node.js中检查那个PHP会话cookie和我的时候.我在每次重定向都有响应401缺少身份验证.如果我将光标放在地址栏并按Enter键,一切正常,所以这是重定向的问题.
我的问题基本上是,可能导致这种行为的原因.另一方面,我必须提到firefox在每个请求之后发送cookie而没有任何问题.
重定向后的标题(没有会话cookie):
{
"host": "localhost:3000",
"connection": "keep-alive",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36",
"x-client-data": "CJS2eQHIprbJAQjEtskECKmdygE=",
"x-chrome-connected": "id=110052060380026604986,mode=0,enable_account_consistency=false",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"accept-encoding": "gzip, deflate, sdch, br",
"accept-language": "pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4"
}
Run Code Online (Sandbox Code Playgroud)
点击进入地址栏后的标题(什么工作正常):
{
"host": "localhost:3000",
"connection": "keep-alive",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"accept-encoding": "gzip, deflate, sdch, br",
"accept-language": "pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4",
"cookie": "SESSID=very_long_string"
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 node-ffi 从 node.js 中使用 libvlc,虽然它似乎适用于一般的基本媒体播放器功能,但当我尝试使用时,我的程序中不断出现崩溃、分段错误和一般冻结libvlc 的异步事件系统并将其与节点的 EventEmitter 集成。到目前为止,我使用的代码托管在https://gist.github.com/2644721,但似乎不起作用。
GDB 产生了好坏参半的结果,但我收到的最后一次崩溃是:
Program received signal SIGSEGV, Segmentation fault.
0x000000000057cc86 in v8::Function::Call(v8::Handle<v8::Object>, int, v8::Handle<v8::Value>*) ()
(gdb) bt
#0 0x000000000057cc86 in v8::Function::Call(v8::Handle<v8::Object>, int, v8::Handle<v8::Value>*) ()
#1 0x00007ffff5997a41 in CallbackInfo::DispatchToV8(CallbackInfo*, void*, void**) ()
from /home/adam/node_modules/node-ffi/compiled/0.6/linux/x64/ffi_bindings.node
#2 0x00007ffff5997adb in CallbackInfo::WatcherCallback(uv_async_s*, int) ()
from /home/adam/node_modules/node-ffi/compiled/0.6/linux/x64/ffi_bindings.node
#3 0x00000000007be12f in ev_invoke_pending ()
#4 0x00000000007c2087 in ev_run ()
#5 0x00000000007b597f in uv_run ()
#6 0x000000000052a147 in node::Start(int, char**) ()
#7 0x00007ffff63ca76d in __libc_start_main ()
from /lib/x86_64-linux-gnu/libc.so.6
#8 …Run Code Online (Sandbox Code Playgroud)