https://github.com/approvers/do-lua
The Lua binding for JavaScript.
https://github.com/approvers/do-lua
Last synced: about 1 year ago
JSON representation
The Lua binding for JavaScript.
- Host: GitHub
- URL: https://github.com/approvers/do-lua
- Owner: approvers
- License: apache-2.0
- Created: 2019-12-12T13:52:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-18T17:22:11.000Z (about 2 years ago)
- Last Synced: 2025-04-09T17:14:23.027Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 711 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# do-lua
The Lua runtime for Node.js.
## Usage
```js
const { doFile, doString } = require('do-lua');
const program = `
print("Hello, World!")
`;
doString(program).then(() => {
console.log("Done doString");
})
doFile('examples/test1.lua').then(() => {
console.log("Done doFile");
})
```
You cannot use `this` in functions of the passing table on `loadProgram`. Use arrow function instead of that.
```js
const { loadProgram } = require('do-lua');
const state = loadProgram(`
obj.ox = 50;
obj.mes("Hello, World!")
`);
let message = '';
const table = {
ox: 0,
mes: (text) => {
message += text; // `this` cannot be used but can capture variables.
}
};
state.setTable('obj', table);
state.run().then((G) => { // G is global table exclusive "package" and "_G"
console.log("ox: ", G.obj.ox); // 50
console.log("Message: ", message); // Hello, World!
});
```