-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAST.vue
116 lines (99 loc) · 1.98 KB
/
AST.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
<div id="ast" class="two-split">
<monaco-editor
class="editor"
v-model="code"
language="lua"
:amdRequire="amdRequire"
:options="editorCfg"></monaco-editor>
<vue-json-pretty
class="json-viewer"
:path="'res'"
:data="ast"
@click="handleClick"
></vue-json-pretty>
</div>
</template>
<script lang="lua">
local MonacoEditor = require('vue-monaco')
local VueJsonPretty = require('vue-json-pretty')
local m = {
data = function()
return {
editorCfg = {
minimap = {
enabled = false
}
},
code = '',
ast = {}
}
end,
watch = {
code = function(v, ov)
this.compile(v)
end
},
methods = {
handleClick = function() end,
compile = function(code)
local me = this;
fetch('http://localhost:8081/ast', {
method = 'post',
headers = {
['Content-Type'] = 'application/json',
}
body = JSON.stringify({
code = me.code
})
}).then(function(response)
return response.json()
end).then(function(resp)
print(resp.data)
me.ast = resp.data
end)
end,
amdRequire = window.require
},
mounted = function()
this.code = [[local Person = class(function(name)
self.name = name
end)
function Person:sayHi()
return "hi"
end
local SuperMan = class(Person, function(name, skill)
self.skill = skill
end)
function SuperMan:sayHi()
return super.sayHi() .. " " .. self.name
end
local sp = SuperMan("tom", "fly")
print(sp.name)
print(sp.skill)
print(sp.sayHi())]]
end,
components = {
MonacoEditor = MonacoEditor
VueJsonPretty = VueJsonPretty
}
}
return m
</script>
<style>
.two-split {
margin-top: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.editor {
width: 50%;
height: calc(100vh - 30px);
}
.json-viewer {
width: 49%;
height: calc(100vh - 30px);
overflow: scroll;
}
</style>