-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRProgN.html
127 lines (114 loc) · 4.56 KB
/
RProgN.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
<head>
<meta charset="UTF-8">
<script
src="jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script>
// Thanks http://www.netlobo.com/url_query_string_javascript.html
function gup( name, url ) {
if (!url) url = location.href;
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
return results == null ? null : decodeURIComponent(results[1]);
}
function byteCount(s){
return encodeURI(s).split(/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - 1;
}
setInterval(function(){
document.getElementById('howmanybyes').innerHTML = byteCount(document.getElementById('CodeInput').value)+" Bytes"
},500)
var main = "";
var sugar = "";
var stack = "";
function try_complete_code(){
if(main.length>0 && stack.length>0 && sugar.length>0){
main = main.replace(/stack=require'stack'/,stack.replace(/return stack/, ''))
main = main.replace(/-- START SUGAR LOAD(.|\s)*?-- END SUGAR LOAD/, 'local sugar = [['+sugar+']]')
main = main.replace(/-- TRY INPUT(.|\s)*?-- END TRY INPUT/, 'input = arg[1]')
document.getElementById('RProgN').innerHTML = "arg = {<CODETORUN><INPUTS>}"+main
}
}
window.onload = function(){
var defRPN = gup('rpn')
var defINP = gup('input')
if(defRPN != null){
document.getElementById('CodeInput').value = defRPN
}
if(defINP != null){
document.getElementById('inputs').value = defINP
}
$.get('lua_implementation/stack.lua',function(dat){
stack = dat
try_complete_code()
},"text")
$.get('lua_implementation/sugar.txt',function(dat){
sugar = dat
try_complete_code()
},"text")
$.get('lua_implementation/main.lua',function(dat){
main = dat
try_complete_code()
},"text")}
function getlink(){
var out = window.location.href.replace(/([^?]*)(\?.*)?/,'$1')+"?rpn="+encodeURIComponent(document.getElementById('CodeInput').value)+"&input="+encodeURIComponent(document.getElementById('inputs').value)
document.getElementById('outputURL').value = out
}
function dorpn(){
var rpn = document.getElementById('CodeInput').value
var inp = document.getElementById('inputs').value
var rpn_code = document.getElementById('RProgN').innerHTML
rpn_code = rpn_code.replace(/<CODETORUN>/gi, '[['+rpn.replace(/]]/g, ']].."]]"..[[').replace(/\$/,'$$')+']]');
var i = inp.replace(/(\s|^)+(("(.*?)")|(\S+))/gi, ', [[$5$4♪').replace(/]]/g, ']].."]]"..[[').replace(/♪/g,']]')
rpn_code = rpn_code.replace(/<INPUTS>/gi, i.replace(/\$/,'$$'))
document.getElementById('output').value = ''
emscripten.print = function(n){document.getElementById('output').value = document.getElementById('output').value + n + "\n"}
emscripten.write = function(n){document.getElementById('output').value = document.getElementById('output').value + n}
try{L.execute(rpn_code);}
catch(e){
document.getElementById('output').value = document.getElementById('output').value + e.toString() + "\n"
}
}
</script>
<script src="https://daurnimator.github.io/lua.vm.js/lua.vm.js"></script>
<style>
body{
text-align:left;
}
#footer{
font-size:0.8em;
text-align:center;
}
#inputs{
width:25em;
}
#output{
width:25em;
height:25em;
}
#CodeInput{
width:25em;
height:25em;
}
</style>
</head>
<body>
<font size = 2>Be advised, ► Zero space has been replaced with ~ in all situations.
This is not backwards compatible, change your code!</font><br />
<textarea name="CodeInput" id="CodeInput">"Hello, World!" p</textarea>
<form>
<input type="text" id="inputs" placeholder="Type your inputs in here! Separated by whitespace."></input>
<p id='howmanybyes'>0 Bytes</p>
<input type="button" value="Run" onclick="dorpn()"></input>
<input type="button" value="Get Link" onclick="getlink()"></input>
<input type="text" placeholder="Output URL." id="outputURL"></input>
</form>
<textarea name="Output" id="output"><YOUR OUTPUT GOES HERE></textarea>
<div id="footer">
Credit to <a href='https://daurnimator.github.io/lua.vm.js/lua.vm.js.html'>lua.vm.js</a> for their Lua VM. Which actively interprets Reverse Programmer Notation.<br><a href="https://github.com/TehFlaminTaco/Reverse-Programmer-Notation">Check out the github for Reverse Programmer Notation Here!</a>
</div>
<script type='N/A' id='RProgN'>
</script>
</body>