luaapi 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/luaapi.rb +133 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 494a1fb9309aa089eec1d339bf5a7b122b6017c953fde685a3e5c222348a7192
|
4
|
+
data.tar.gz: c6c7666b72b34ddcda01be334c1745b43c3787966728f22f6c52cb1db4a2c54e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d16ae7e7367d41ca1a7bc9a9507f057befcc6414dc8614fdd611c793bad7e811ab75f6374a8f32f13150eab28ff654fd62d0bd59d9d8a8f570993bded9c873b8
|
7
|
+
data.tar.gz: 604cf3b408055660943978ddb1711e8f1cf4474c9012b41fe002476d39a846fdbbc15c35f1437dfe1c73327ef7680561f885ec7faf3f2063b5bf2d057838b4e5
|
data/lib/luaapi.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
# Author: Marek K.
|
2
|
+
|
3
|
+
=begin
|
4
|
+
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
This program is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU General Public License
|
16
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
|
19
|
+
der GNU General Public License, wie von der Free Software Foundation,
|
20
|
+
Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
|
21
|
+
veröffentlichten Version, weiter verteilen und/oder modifizieren.
|
22
|
+
|
23
|
+
Dieses Programm wird in der Hoffnung bereitgestellt, dass es nützlich sein wird, jedoch
|
24
|
+
OHNE JEDE GEWÄHR,; sogar ohne die implizite
|
25
|
+
Gewähr der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
|
26
|
+
Siehe die GNU General Public License für weitere Einzelheiten.
|
27
|
+
|
28
|
+
Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
|
29
|
+
Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
|
30
|
+
|
31
|
+
=end
|
32
|
+
|
33
|
+
class LuaApi
|
34
|
+
require "net/http"
|
35
|
+
require "uri"
|
36
|
+
|
37
|
+
attr_accessor :type
|
38
|
+
|
39
|
+
def initialize
|
40
|
+
begin
|
41
|
+
File.open "./lua_api-in.txt", "w" do |f|
|
42
|
+
f.write "print(_VERSION)"
|
43
|
+
f.close
|
44
|
+
end
|
45
|
+
|
46
|
+
IO.popen "lua ./lua_api-in.txt" do |p|
|
47
|
+
@version = p.gets
|
48
|
+
p.close
|
49
|
+
end
|
50
|
+
|
51
|
+
@type = 0
|
52
|
+
rescue Errno::ENOENT => e
|
53
|
+
@type = 1
|
54
|
+
uri = URI("https://www.lua.org/cgi-bin/demo")
|
55
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
56
|
+
https.use_ssl = true
|
57
|
+
req = Net::HTTP::Post.new(uri.path)
|
58
|
+
req.body = "input=" + URI::encode("print(_VERSION)")
|
59
|
+
res = https.request(req)
|
60
|
+
if res.code == "200"
|
61
|
+
@version = res.body.match(/<H2>Output<\/H2>\n<TEXTAREA ROWS="8" COLS="80">\n(.*)\n<\/TEXTAREA><P><IMG SRC="images\/ok.png" ALIGN="absbottom">\nYour program ran successfully\./m)[1]
|
62
|
+
else
|
63
|
+
@type = 2
|
64
|
+
raise RuntimeError, "No interpreter found!"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def version?
|
70
|
+
return @version
|
71
|
+
end
|
72
|
+
|
73
|
+
def good?
|
74
|
+
true unless @type == 2
|
75
|
+
end
|
76
|
+
|
77
|
+
def interpret code
|
78
|
+
case @type
|
79
|
+
when 0
|
80
|
+
File.open "./lua_api-in.txt", "w" do |f|
|
81
|
+
f.write code
|
82
|
+
f.close
|
83
|
+
end
|
84
|
+
|
85
|
+
begin
|
86
|
+
IO.popen "lua ./lua_api-in.txt" do |p|
|
87
|
+
@result = p.gets
|
88
|
+
p.close
|
89
|
+
end
|
90
|
+
rescue Errno::ENOENT => e
|
91
|
+
raise RuntimeError, "No interpreter found!"
|
92
|
+
end
|
93
|
+
when 1
|
94
|
+
uri = URI("https://www.lua.org/cgi-bin/demo")
|
95
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
96
|
+
https.use_ssl = true
|
97
|
+
|
98
|
+
req = Net::HTTP::Post.new(uri.path)
|
99
|
+
req.body = "input=" + URI::encode(code)
|
100
|
+
res = https.request(req)
|
101
|
+
|
102
|
+
if res.code == "200"
|
103
|
+
r = res.body.match(/<H2>Output<\/H2>\n<TEXTAREA ROWS="8" COLS="80">\n(.*)\n<\/TEXTAREA><P><IMG SRC="images\/ok.png" ALIGN="absbottom">\nYour program ran successfully\./m)
|
104
|
+
unless r
|
105
|
+
r = res.body.match(/<H2>Output<\/H2>\n<TEXTAREA ROWS="8" COLS="80">\n(.*)<\/TEXTAREA><P><IMG SRC="images\/alert.png" ALIGN="absbottom">\nYour program failed to compile\./m)
|
106
|
+
end
|
107
|
+
unless r
|
108
|
+
r = res.body.match(/<H2>Output<\/H2>\n<TEXTAREA ROWS="8" COLS="80">\n(.*)<\/TEXTAREA><P><IMG SRC="images\/alert.png" ALIGN="absbottom">\nYour program failed to run\./m)
|
109
|
+
end
|
110
|
+
unless r
|
111
|
+
r = res.body.match(/<H2>Output<\/H2>\n<TEXTAREA ROWS="8" COLS="80">\n(.*)<\/TEXTAREA><P><IMG SRC="images\/alert.png" ALIGN="absbottom">\nYour program was aborted\./m)
|
112
|
+
end
|
113
|
+
@result = nil unless r
|
114
|
+
@result = r[1]
|
115
|
+
else
|
116
|
+
raise RuntimeError, "Online Interpreter not available!"
|
117
|
+
end
|
118
|
+
when 2
|
119
|
+
raise RuntimeError, "No interpreter found!"
|
120
|
+
end
|
121
|
+
return @result
|
122
|
+
end
|
123
|
+
|
124
|
+
def result
|
125
|
+
@result
|
126
|
+
end
|
127
|
+
|
128
|
+
def close
|
129
|
+
File.delete "./lua_api-in.txt" if File.exist? "./lua_api-in.txt"
|
130
|
+
@type = 2
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: luaapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marek K.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: The Lua API runs Lua scripts. The API does this by trying to connect
|
14
|
+
to a local Lua interpreter. If this does not work, the API connects to an online
|
15
|
+
interpreter.
|
16
|
+
email: m.k@mk16.de
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/luaapi.rb
|
22
|
+
homepage: http://test.mk16.de/projects/luaapi-gem
|
23
|
+
licenses:
|
24
|
+
- GPL-3.0
|
25
|
+
metadata:
|
26
|
+
documentation_uri: http://test.mk16.de/projects/luaapi-gem
|
27
|
+
source_code_uri: http://test.mk16.de/scriptFiles/luaapi.rb
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.7.8
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: The Lua API runs Lua scripts.
|
48
|
+
test_files: []
|