Skip to content

Commit 85efb65

Browse files
committed
prepare for napi.
1 parent 7e7e80c commit 85efb65

File tree

8 files changed

+847
-29
lines changed

8 files changed

+847
-29
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ build
1616
3rdlibs/LuaJIT/src/host/buildvm_arch.h
1717
3rdlibs/LuaJIT/src/host/minilua
1818
3rdlibs/LuaJIT/src/jit/vmdef.lua
19+
20+
21+
build/
22+
build*/
23+
binding/
24+

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
## Node-luajit binding
1+
2+
## Node-luajit binding
3+
4+
support npai version 6(node minimum version v10.20.0).
5+
6+
need lower version check the branch 8.x-10.x or 6.x.
7+
8+
29
#### Cross platform. (win,mac,linux)[x64]
310
similar as `https://github.com/brettlangdon/NodeLua`
411

@@ -12,6 +19,7 @@ similar as `https://github.com/brettlangdon/NodeLua`
1219
5. add,linux auto compile luajit.[2018-01-29] http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
1320
6. add, cjson compile and auto load. [2018-01-29] https://github.com/openresty/lua-cjson/archive/master.zip
1421
7. > win64 need fix.
22+
8. support napi. support node 10.20.x-14.x [2021-01-06]
1523

1624

1725
##Installation
@@ -23,7 +31,8 @@ npm install node-luajit --unsafe-perm
2331
2432
```
2533

26-
#### node 8.x 10.x:
34+
#### node napi
35+
2736
Linux build luajit
2837
```
2938
git clone https://github.com/LuaJIT/LuaJIT.git

binding.gyp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"targets": [
33
{
4-
"target_name": "node-luajit",
4+
"target_name": "<(module_name)",
55
"variables": {
66
"lua_include": "",
77
"lib_dirs": ""
@@ -86,10 +86,27 @@
8686
"3rdlibs/lua-cjson/lua_cjson.c",
8787
"3rdlibs/lua-cjson/strbuf.c"
8888
],
89-
"include_dirs": [
90-
"<!@(node -p \"require('node-addon-api').include\")"
91-
],
92-
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
93-
}
89+
"include_dirs": [
90+
"<!@(node -p \"require('node-addon-api').include\")"
91+
],
92+
"dependencies": [
93+
"<!(node -p \"require('node-addon-api').gyp\")"
94+
],
95+
"defines": [
96+
"NAPI_VERSION=<(napi_build_version)",
97+
"NAPI_DISABLE_CPP_EXCEPTIONS",
98+
]
99+
},
100+
{
101+
"target_name": "action_after_build",
102+
"type": "none",
103+
"dependencies": [ "<(module_name)" ],
104+
"copies": [
105+
{
106+
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
107+
"destination": "<(module_path)"
108+
}
109+
]
110+
}
94111
]
95112
}

index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
'use strict';
2-
let nodelua = null;
32
let path = require('path');
4-
try {
5-
nodelua = require('./build/Release/node-luajit');
6-
} catch (e) {
7-
console.log('``` release load err:', e);
8-
try{
9-
nodelua = require('./build/Debug/node-luajit');
10-
}catch (e){
11-
nodelua = require('/Users/nuc/Library/Developer/Xcode/DerivedData/binding-ebwzqyofwzjwfzcrbpisobhcazli/Build/Products/Debug/node-luajit.node')
12-
}
13-
}
3+
const binary = require('node-pre-gyp');
4+
const binding_path = binary.find(path.resolve(path.join(__dirname, 'package.json')));
5+
const nodelua = require(binding_path);
146

157
let MyCLua = nodelua['MyLuaState'];
168

0 commit comments

Comments
 (0)