为NodeJs编写的Addon如何无缝的使用到AtomShell上

陆经渔 发布于 2014/08/25 10:08
阅读 1K+
收藏 0

如题,现在想为Atom-Shell编写一个核心扩展,使得其编写的程序可以方便的调用Windows本地的dll中的导出函数和类。但是目前只在网上查到如何为NodeJs编写Addon(这里),尝试着直接在Atom-Shell里使用为NodeJs编写的Addon,但提示说“Module did not self register”,截图如下:

测试项目的文件结构如下:

其中hello.node是使用node-gyp命令生成的,源文件是hello.cc,其内容如下:

#include <node.h>
#include <v8.h>

using namespace v8;

Handle<Value> Method(const Arguments & args)
{
	HandleScope scope;
	return scope.Close(String::New("world"));
}

void init(Handle<Object> target)
{
	target->Set(String::NewSymbol("hello"), 
		FunctionTemplate::New(Method)->GetFunction());
}

NODE_MODULE(hello, init);



index.html内容如下:

<!DOCTYPE html>
<html>
	<title>first atom shell</title>
	<body>
		<h1>first atom shell app.</h1>		
		<input type="button" value="Click Me" onclick="show()"/>
		<p id="show"></p>
		<script type="text/javascript">
			function show()
			{
				document.getElementById("show").innerHTML = "hello world";
			}
		</script>
	</body>
</html>



main.js内容如下:

// Module to control application life.
var app = require('app');
// Module to create native browser window.
var BrowserWindow = require('browser-window');

// Report crashes to our server.
require('crash-reporter').start();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function(){
	if(process.platform != 'darwin')
		app.quit();
});

// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', function(){
	// Create the browser window.
	mainWindow = new BrowserWindow({width:800, height:600});

	// and load the index.html of the app.
	mainWindow.loadUrl('file://' + __dirname + '/index.html');

	var hello = require('./hello.node').hello();
	//console.log(hello);
	
	// Emitted when the window is closed.
	mainWindow.on('closed', function(){
		// Dereference the window object, usually you would store windows
		// in an array if your app supports multi windows, this is the time
		// when you should delete the corresponding element.
		mainWindow = null;
	});
});



package.json内容如下:

{
	"name"		: "firstAtom",
	"version"	: "0.1.0",
	"main"		: "main.js"
}



请问怎样正确的为Atom-Shell编写并应用Addon?

加载中
0
红红
红红

最新的atom-shell使用node版本是的v 0.16.2

node-gyp 的时候指定版本


node-gyp rebuild --target=0.16.2 --arch=ia32 --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
0
gastrodia
gastrodia
用apm安装
返回顶部
顶部