├── .browserslistrc
├── .gitignore
├── README.md
├── babel.config.js
├── index.html
├── index.js
├── package-lock.json
├── package.json
├── postcss.config.js
├── public
├── favicon.ico
└── index.html
├── server.js
├── src
├── App.vue
├── assets
│ └── logo.png
├── main.js
├── router.js
├── store.js
└── views
│ ├── AST.vue
│ └── JS.vue
└── vue.config.js
/.browserslistrc:
--------------------------------------------------------------------------------
1 | > 1%
2 | last 2 versions
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 | *.sw?
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jlua-demo
2 |
3 | This is a demo for [jlua](https://github.com/hsiaosiyuan0/jlua), it's also made with jlua and Vue which means the `script` tag within Single File Components has a attribute `lang` with value `lua`, see this [source file](/src/views/AST.vue) to get a intuitive feeling.
4 |
5 | ## Project setup
6 | ```
7 | npm install
8 | ```
9 |
10 | ### Compiles and hot-reloads for development
11 | ```
12 | npm run serve
13 | ```
14 |
15 | ### Compiles and minifies for production
16 | ```
17 | npm run build
18 | ```
19 |
20 | ### Run your tests
21 | ```
22 | npm run test
23 | ```
24 |
25 | ### Lints and fixes files
26 | ```
27 | npm run lint
28 | ```
29 |
30 | ### Customize configuration
31 | See [Configuration Reference](https://cli.vuejs.org/config/).
32 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | '@vue/app'
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | jlua-demo
8 |
9 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const __jlua__ = require("jlua/lib/js/runtime");
2 |
3 | let Person = __jlua__.class("Person", function (name) {
4 | this.name = name;
5 | });
6 |
7 | Person.prototype.sayHi = function () {
8 | return "hi";
9 | };
10 |
11 | let SuperMan = __jlua__.class("SuperMan", Person, function (name, skill) {
12 | this.skill = skill;
13 | });
14 |
15 | SuperMan.prototype.sayHi = function () {
16 | return __jlua__.add(Object.getPrototypeOf(SuperMan.prototype).sayHi.call(this), __jlua__.add(" ", this.name));
17 | };
18 |
19 | let sp = SuperMan("tom", "fly");
20 |
21 | __jlua__.print(sp.name);
22 |
23 | __jlua__.print(sp.skill);
24 |
25 | __jlua__.print(sp.sayHi());
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jlua-demo",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "serve": "vue-cli-service serve",
7 | "build": "vue-cli-service build"
8 | },
9 | "dependencies": {
10 | "core-js": "^2.6.5",
11 | "cors": "^2.8.5",
12 | "express": "^4.17.0",
13 | "jlua": "file:../jlua",
14 | "vue": "^2.6.10",
15 | "vue-json-pretty": "^1.6.0",
16 | "vue-monaco": "^0.3.2",
17 | "vue-router": "^3.0.3",
18 | "vuex": "^3.0.1"
19 | },
20 | "devDependencies": {
21 | "@vue/cli-plugin-babel": "^3.7.0",
22 | "@vue/cli-service": "^3.7.0",
23 | "vue-template-compiler": "^2.5.21"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | autoprefixer: {}
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/going-merry0/jlua-demo/4bc92dd8b4d58deed6b4faa4a1bbe82795f1be44/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | jlua-demo
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const cors = require("cors");
3 | const lexer = require("jlua/lib/lexer");
4 | const Lexer = lexer.Lexer;
5 | const Source = lexer.Source;
6 | const Parser = require("jlua/lib/parser").Parser;
7 | const YamlVisitor = require("jlua/lib/visitor").YamlVisitor;
8 | const compile = require("jlua/lib/js/compile").default;
9 |
10 | const port = 8081;
11 | const app = express();
12 |
13 | app.use(cors());
14 | app.use(express.json());
15 |
16 | app.post("/ast", (req, res) => {
17 | const src = new Source(req.body.code, "stdin");
18 | const lexer = new Lexer(src);
19 | const parser = new Parser(lexer);
20 | const chk = parser.parseChunk();
21 | const v = new YamlVisitor();
22 | const ast = v.visitChunk(chk);
23 | res.send({
24 | code: 0,
25 | data: ast
26 | });
27 | });
28 |
29 | app.post("/js", (req, res) => {
30 | const { code } = compile(req.body.code, "stdin");
31 | res.send({
32 | code: 0,
33 | data: code
34 | });
35 | });
36 |
37 | app.listen(port, () =>
38 | console.log(`Compiling service is listening on port ${port}!`)
39 | );
40 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 | Demo for
14 |
jlua
15 |
16 |
AST |
17 |
JS
18 |
19 |
20 |
21 |
22 |
23 |
24 |
52 |
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/going-merry0/jlua-demo/4bc92dd8b4d58deed6b4faa4a1bbe82795f1be44/src/assets/logo.png
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from "vue";
2 | import App from "./App.vue";
3 | import router from "./router";
4 | import store from "./store";
5 |
6 | Vue.config.productionTip = false;
7 |
8 | window.require.config({
9 | paths: {
10 | vs: "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.17.0/min/vs"
11 | }
12 | });
13 |
14 | // Before loading vs/editor/editor.main, define a global MonacoEnvironment that overwrites
15 | // the default worker url location (used when creating WebWorkers). The problem here is that
16 | // HTML5 does not allow cross-domain web workers, so we need to proxy the instantiation of
17 | // a web worker through a same-domain script
18 | window.MonacoEnvironment = {
19 | getWorkerUrl: function(workerId, label) {
20 | return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
21 | self.MonacoEnvironment = {
22 | baseUrl: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.17.0/min/'
23 | };
24 | importScripts('https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.17.0/min/vs/base/worker/workerMain.js');`)}`;
25 | }
26 | };
27 |
28 | window.require(["vs/editor/editor.main"], function() {
29 | new Vue({
30 | router,
31 | store,
32 | render: h => h(App)
33 | }).$mount("#app");
34 | });
35 |
--------------------------------------------------------------------------------
/src/router.js:
--------------------------------------------------------------------------------
1 | import Vue from "vue";
2 | import Router from "vue-router";
3 |
4 | Vue.use(Router);
5 |
6 | export default new Router({
7 | routes: [
8 | {
9 | path: "/",
10 | redirect: '/ast'
11 | },
12 | {
13 | path: "/ast",
14 | name: "ast",
15 | component: () =>
16 | import(/* webpackChunkName: "ast" */ "./views/AST.vue")
17 | },
18 | {
19 | path: "/js",
20 | name: "js",
21 | component: () =>
22 | import(/* webpackChunkName: "js" */ "./views/JS.vue")
23 | }
24 | ]
25 | });
26 |
--------------------------------------------------------------------------------
/src/store.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue'
2 | import Vuex from 'vuex'
3 |
4 | Vue.use(Vuex)
5 |
6 | export default new Vuex.Store({
7 | state: {
8 |
9 | },
10 | mutations: {
11 |
12 | },
13 | actions: {
14 |
15 | }
16 | })
17 |
--------------------------------------------------------------------------------
/src/views/AST.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
15 |
16 |
17 |
18 |
96 |
97 |
116 |
117 |
--------------------------------------------------------------------------------
/src/views/JS.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
14 |
15 |
16 |
17 |
89 |
90 |
--------------------------------------------------------------------------------
/vue.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 |
3 | module.exports = {
4 | chainWebpack: config => {
5 | config.resolve.symlinks(false);
6 |
7 | config.devtool("inline-source-map");
8 |
9 | config.module
10 | .rule("lua")
11 | .test(/\.lua$/)
12 | .use("babel")
13 | .loader("babel-loader")
14 | .options({
15 | presets: ["@babel/preset-env"]
16 | })
17 | .end()
18 | .use("lua")
19 | .loader("jlua/lib/js/loader")
20 | .end();
21 |
22 | config.plugin("html").tap(args => {
23 | args[0].template = path.resolve(__dirname, "index.html");
24 | return args;
25 | });
26 |
27 | config.externals([
28 | {
29 | "monaco-editor": "monaco"
30 | }
31 | ]);
32 | }
33 | };
34 |
--------------------------------------------------------------------------------