rogems 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ module RoGems
2
+ module Exceptions
3
+ class TranspileError < Exception
4
+ def initialize(msg)
5
+ super("Failed to transpile: #{msg}")
6
+ end
7
+ end
8
+ class InitError < Exception
9
+ def initialize(msg)
10
+ super("Cannot run RoGems: #{msg}")
11
+ self.set_backtrace([])
12
+ end
13
+ end
14
+ class NoInputDirError < InitError
15
+ def initialize(searched)
16
+ super("No input directory '#{searched}' found.")
17
+ end
18
+ end
19
+ class NoOutputDirError < InitError
20
+ def initialize(searched)
21
+ super("No output directory '#{searched}' found.")
22
+ end
23
+ end
24
+ class MissingConfigError < InitError
25
+ def initialize(dir)
26
+ super("Missing 'rogems.json' config file in '#{dir}'")
27
+ end
28
+ end
29
+ class RojoNotFoundError < InitError
30
+ def initialize
31
+ super("Rojo could not be found. Please make sure it is installed and discoverable (i.e. you can run 'rojo -v').")
32
+ end
33
+ end
34
+ class InvalidInitModeError < InitError
35
+ def initialize(mode, usage)
36
+ super("Invalid init mode '#{mode}' provided.")
37
+ puts usage
38
+ end
39
+ end
40
+ class UnsupportedBitOpError < TranspileError
41
+ def initialize(op)
42
+ super("Bitwise operators are not supported.")
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require "benchmark"
2
+ require "CodeGenerator"
3
+
4
+ module RoGems
5
+ class Transpiler
6
+ def initialize(config, base_dir)
7
+ cwd = File.join(base_dir || Dir.pwd, config["rootDir"])
8
+ @input_dir = File.join(cwd, config["sourceDir"])
9
+ @output_dir = File.join(cwd, config["outDir"])
10
+ @config = config
11
+
12
+ raise Exceptions::NoInputDirError.new(@input_dir) unless Dir.exist?(@input_dir)
13
+ raise Exceptions::NoOutputDirError.new(@output_dir) unless Dir.exist?(@output_dir)
14
+ end
15
+
16
+ def transpile
17
+ elapsed = Benchmark.realtime { transpile_dir(@input_dir) }
18
+ puts "Compiled files successfully. (#{(elapsed * 1000).floor} ms)"
19
+ end
20
+
21
+ def transpile_dir(dir, output_subdir = "")
22
+ Dir.foreach(dir) do |file_name|
23
+ next if file_name == '.' or file_name == '..'
24
+ input_path = File.join(dir, file_name)
25
+
26
+ if File.directory?(input_path)
27
+ output_path = File.join(@output_dir, output_subdir)
28
+ Dir.mkdir(output_path) unless Dir.exist?(output_path)
29
+ transpile_dir(input_path, File.join(output_subdir, file_name))
30
+ else
31
+ output_file = File.join(@output_dir, output_subdir, file_name.gsub(/\.[^.]+$/, '.lua'))
32
+ code_generator = CodeGenerator.new(@config, File.read(input_path))
33
+ output_code = code_generator.generate
34
+ File.write(output_file, output_code)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module RoGems
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ {
2
+ "rootDir": "./",
3
+ "sourceDir": "src",
4
+ "outDir": "out",
5
+ "debugging": false
6
+ }
@@ -0,0 +1,13 @@
1
+ local Ruby = {}
2
+
3
+ function Ruby.list(t)
4
+ local i = 0
5
+ return function()
6
+ i += 1
7
+ if i <= #t then
8
+ return t[i]
9
+ end
10
+ end
11
+ end
12
+
13
+ return Ruby
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rogems
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - r-unic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - roleyspersonal@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - CODE_OF_CONDUCT.md
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE
25
+ - README.md
26
+ - examples/classes/.gitignore
27
+ - examples/classes/README.md
28
+ - examples/classes/default.project.json
29
+ - examples/classes/out/client/main.client.lua
30
+ - examples/classes/rogems.json
31
+ - examples/classes/src/client/main.client.rb
32
+ - examples/lava_brick/aftman.toml
33
+ - examples/lava_brick/default.project.json
34
+ - examples/lava_brick/out/client/test.lua
35
+ - examples/lava_brick/rogems.json
36
+ - examples/lava_brick/src/client/test.rb
37
+ - examples/test/.gitignore
38
+ - examples/test/README.md
39
+ - examples/test/default.project.json
40
+ - examples/test/out/client/main.client.lua
41
+ - examples/test/rogems.json
42
+ - examples/test/src/client/main.client.rb
43
+ - lib/RoGems.rb
44
+ - lib/rogems/CLI.rb
45
+ - lib/rogems/CodeGenerator.rb
46
+ - lib/rogems/Exceptions.rb
47
+ - lib/rogems/Transpiler.rb
48
+ - lib/rogems/Version.rb
49
+ - lib/rogems/default_rogems.json
50
+ - lib/rogems/lua/Runtime.lua
51
+ homepage: https://github.com/r-unic/rogems
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ allowed_push_host: https://rubygems.org/
56
+ homepage_uri: https://github.com/r-unic/rogems
57
+ source_code_uri: https://github.com/r-unic/rogems
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.0.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.3.25
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: A Ruby to Lua transpiler for compiling Ruby scripts into Roblox code.
77
+ test_files: []