Skip to content

Commit

Permalink
prepare for napi.
Browse files Browse the repository at this point in the history
  • Loading branch information
whtiehack committed Jan 6, 2021
1 parent 7e7e80c commit 85efb65
Show file tree
Hide file tree
Showing 8 changed files with 847 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ build
3rdlibs/LuaJIT/src/host/buildvm_arch.h
3rdlibs/LuaJIT/src/host/minilua
3rdlibs/LuaJIT/src/jit/vmdef.lua


build/
build*/
binding/

13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## Node-luajit binding

## Node-luajit binding

support npai version 6(node minimum version v10.20.0).

need lower version check the branch 8.x-10.x or 6.x.


#### Cross platform. (win,mac,linux)[x64]
similar as `https://github.com/brettlangdon/NodeLua`

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


##Installation
Expand All @@ -23,7 +31,8 @@ npm install node-luajit --unsafe-perm
```

#### node 8.x 10.x:
#### node napi

Linux build luajit
```
git clone https://github.com/LuaJIT/LuaJIT.git
Expand Down
29 changes: 23 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"targets": [
{
"target_name": "node-luajit",
"target_name": "<(module_name)",
"variables": {
"lua_include": "",
"lib_dirs": ""
Expand Down Expand Up @@ -86,10 +86,27 @@
"3rdlibs/lua-cjson/lua_cjson.c",
"3rdlibs/lua-cjson/strbuf.c"
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
}
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"defines": [
"NAPI_VERSION=<(napi_build_version)",
"NAPI_DISABLE_CPP_EXCEPTIONS",
]
},
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
]
}
14 changes: 3 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
'use strict';
let nodelua = null;
let path = require('path');
try {
nodelua = require('./build/Release/node-luajit');
} catch (e) {
console.log('``` release load err:', e);
try{
nodelua = require('./build/Debug/node-luajit');
}catch (e){
nodelua = require('/Users/nuc/Library/Developer/Xcode/DerivedData/binding-ebwzqyofwzjwfzcrbpisobhcazli/Build/Products/Debug/node-luajit.node')
}
}
const binary = require('node-pre-gyp');
const binding_path = binary.find(path.resolve(path.join(__dirname, 'package.json')));
const nodelua = require(binding_path);

let MyCLua = nodelua['MyLuaState'];

Expand Down
Loading

0 comments on commit 85efb65

Please sign in to comment.