-
Notifications
You must be signed in to change notification settings - Fork 4
/
index2.html
118 lines (96 loc) · 2.96 KB
/
index2.html
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
116
117
118
<html>
<head>
<title>Lua5.1.js packer example</title>
<script src="lua5.1.5.min.js"></script>
<script src="example.lua5.1.js"></script>
<link rel=stylesheet href="codemirror/docs.css">
<link rel="stylesheet" href="codemirror/codemirror.css">
<link rel="stylesheet" href="codemirror/neat.css">
<script src="codemirror-5.5/lib/codemirror.js"></script>
<!-- <script src="codemirror/matchbrackets.js"></script>-->
<script src="codemirror/lua.js"></script>
<style>
.CodeMirror {
border: 1px solid black;
}
</style>
</head>
<body>
<article>
<h2>Lua mode</h2>
<form>
<textarea id="code" name="code">
--[[
example useless code to show lua syntax highlighting
this is multiline comment
]]
function blahblahblah(x)
--local table = {"asd" = 123, "x" = 0.34, }
if x ~= 3 then
print( x )
elseif x == "string" then
my_custom_function( 0x34 )
else
unknown_function( "some string" )
end
--single line comment
end
function blablabla3()
for k,v in ipairs( table ) do
--abcde..
y=[=[
x=[[
x is a multi line string
]]
but its definition is iside a highest level string!
]=]
print(" \"\" ")
s = math.sin( x )
end
end
</textarea>
</form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
matchBrackets: true,
theme: "neat"
});
</script>
<p>Loosely based on Franciszek Wawrzak's <a href="http://codemirror.net/1/contrib/lua">CodeMirror
1 mode</a>. One configuration parameter is supported, <code>specials</code>, to which you can provide an array of strings to have those identifiers highlighted with the <code>lua-special</code> style.</p>
<p><strong>MIME types defined:</strong> <code>text/x-lua</code>.</p>
</article>
<script type="text/javascript">
var C = Lua5_1.C;
var L = C.lua_open();
C.luaL_openlibs(L);
C.lua_pushcfunction(
L,
Lua5_1.Runtime.addFunction(
function (L) {
var str = C.luaL_checkstring(L, 1);
console.log(str);
editor.setValue(str);
return 0;
}
)
);
C.lua_setglobal(L, "OUTPUT");
//console.log()
C.luaL_dofile(L, 'main.lua');
var value=editor.getValue();
C.lua_pushstring(L,value);
C.lua_setglobal(L, "toS");
C.lua_pushstring(L,"miao");
C.lua_setglobal(L, "outputS");
// console.log(value)
if (C.luaL_dostring(L, "OUTPUT(M.indentcode(toS, [[\n\n]], true, ' '))") !== 0) {
var err = C.lua_tostring(L, -1);
C.lua_close(L);
L = 0;
throw new Error("Lua error: " + err);
}
// console.log(outputS)
</script>
</body>
</html>