-
Notifications
You must be signed in to change notification settings - Fork 0
/
lisp.html
127 lines (127 loc) · 4.36 KB
/
lisp.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
119
120
121
122
123
124
125
126
127
<html><head>
<meta charset="UTF-8" id="meta" />
<title>Lisp!</title>
<link rel="stylesheet" href="/css/khak.css" type="text/css" id="theme"></link>
<link rel="icon" href='/media/NPHotChoc.svg.png'></link>
</head>
<body >
<div class="gray notes">
Lisp Repl
<image src="/media/moon.svg" id="themech"
width="30" height="30" >
</image> <!-- </button> -->
<script type="text/javascript" src="/js/theme.js">
</script>
<br>
</div>
<div class="fg">
<blockquote style="text-align: left;">
<pre id="out" style="max-height: 50%; overflow-y: auto;"><br>
<a href="https://github.com/ErmineII/mapL/">mapL</a>, powered by
<a href="https://github.com/fengari-lua">Fengari</a><br>
</pre>
λ> <input type="search"
style="width: 500px;
font-family: 'BefontLegible';"
id="inp"></input>
</blockquote></div>
<div hidden>
<textarea readonly id="lineview" cols="80" rows="20 "></textarea><br>
<button onclick="this.parentElement.hidden = true;">hide</button>
<input type="number" id="start"></input>
<input type="number" id="end" ></input>
<button onclick="grabLine(luafile,0,0)">get</button>
</div>
<script src="/js/console.js" type="text/javascript"></script>
<script src="lib/fengari-web.js" type="text/javascript"></script>
<script type="application/lua">
function tree(obj, maxdepth, before) -- call like tree(var) or tree(var, 4)
before = before or ""; maxdepth = maxdepth or 4
if (maxdepth > 0) then
for key, val in pairs(obj) do
if (type(val) == "string") then
if (val:len() < 20) then
print(before .."-> "..key .. "='" .. val .. "'")
else
print(before .."-> "..key .. "='" .. val:sub(1,15) .. ". . .")
end
elseif (type(val) == "number") then
print(before .."-> "..key .. "= " .. val)
elseif (type(val) == "function") then
print(before .."-> "..key .. "()")
elseif (type(val) == "table") then
if key == "parent" then print(before.."-> ... parent")
elseif key == "_G" then print(before.."-> ... _G")
elseif key == "__index" then print(before.."-> ... __index")
else
print(before .."-> "..key .. ": ")
tree(val, maxdepth-1, " |" .. before)
end
else print(before .. "-> "..key.."=", val)
end
end
else
print(before .." ...")
end
return obj
end
print("lisp repl")
js = require("js")
lisp = require("mapl.lisp")
lisp.begin()
lispEval = function (str)
return lisp.eval(lisp.read(str))
end
prEv = function (self,strgetter)
print(lisp.toString( lispEval(strgetter()) ))
end
js.global.document:getElementById("meta").le = lispEval
js.global.document:getElementById("meta").pe = prEv
</script>
<script>
function esc(str){
return str
.replace(/(["'\\])/g, "\\$1")
.replace(/]]/, "\\]]");
}
function luaStringGetter(jsString){
return fengari.load("return [[" + esc(jsString) + "]]");
}
myconsole.setinputhandler( (str)=>{
try{
document.getElementById("meta").pe(luaStringGetter(str));
} catch (e) {
myconsole.error(
e.replace(/\/([a-z]*)\.lua:([0-9]*):/,
`/$1.lua:<a href="javascript:(()=>{
luafile='/lua/5.3/$1.lua';
grabLine(luafile, $2 - 20, $2 + 20);
})()">$2 =></a>:`)
);}
});
myconsole.inputhandler("(quote . ..loaded)");
async function grabLine(source, st, en){
luafile=source;
var start = document.querySelector("#start");
var end = document.querySelector("#end" );
if(st || en){
start.value = st;
end.value = en;
}
fetch(source)
.then(response => response.text())
.then(text =>{
var out = document.querySelector("#lineview");
out.value =
lines(start.value, end.value, text);
out.parentElement.hidden = false;
});
}
function lines(start, end, from){
from = from.split("\n");
for(var i = 0; i < from.length; i++)
from[i] = i+1 + "\t" + from[i];
return from.slice(start<0?0:start, end).join("\n");
}
</script>
</body></html>