esruby 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd5da76d0d225e6d42316dc57217fb8f1e412043
4
- data.tar.gz: 097fc7b776e2d56570b23c1fd16373e1d6383d27
3
+ metadata.gz: c9f97ad43c8652ddb099701a6a3281fc56f35e26
4
+ data.tar.gz: 115fac3faed60bc8f939dc6b5ceffbda67e27b7c
5
5
  SHA512:
6
- metadata.gz: c0fbea22fb85dd5a15c65b315f26d13146b1a5bc0381b4293eac5566bfd0e57b299abaf93e4c47b43667b22a52689cf2dddd0f6ec07cd53c074e12c3acbb9750
7
- data.tar.gz: a6f84a1b8fd0ff472c98f170f6907cf06f0deff30f35cef526f5ce169a77457bc1341b68107ab4895dccc277b5dc8e3f63aec188ec2e19da84f0304c1c5a6b1c
6
+ metadata.gz: 4caa20cb2a49da0317f50544b0f73f0d414368c4fa032d88cfacf01b4e328f3907ae27a06d70984755d0aa5495542f2d6d0de95af51d3e039bc53d78df5e6e07
7
+ data.tar.gz: 65ade892ebbf6c39ea66960ab6366a980aae6ab61aaddae25f72f55f1c00a910cb4c7b56777d532b79a0fb04a4379901c616f11d362576079368a03330d4fb28
data/README.md CHANGED
@@ -33,6 +33,10 @@ to your `.bashrc` and `.profile`
33
33
  * you will now have `www/app.js` and `www/index.html`
34
34
  * a simple way to serve these files would be `ruby -run -e httpd www -p 4444`
35
35
  * the app with be available at http://localhost:4444
36
+
37
+ # Binding with JS
38
+ Explore my [esruby-bind](https://github.com/robfors/esruby-bind) gem that binds the Ruby and JS object space together.
39
+
36
40
  # License
37
41
 
38
42
  This project is distributed under the MIT License. See LICENSE for further details.
data/lib/esruby/build.rb CHANGED
@@ -55,6 +55,7 @@ module ESRuby
55
55
  js_files += specification.appended_js_sources
56
56
  end
57
57
  js_files += @configuration.appended_js_sources
58
+ js_files << "#{gem_directory}/resources/js/esruby.js"
58
59
  js_files
59
60
  end
60
61
 
@@ -116,8 +117,7 @@ module ESRuby
116
117
  RakeFileUtils.sh "#{mrbc} -B app -o #{build_directory}/app.c #{ruby_sources.join(" ")}"
117
118
  RakeFileUtils.sh "emcc --bind -I #{mruby_directory}/include #{build_directory}/app.c -o #{build_directory}/app.o #{build_directory}/emscripten/lib/libmruby.a -lm #{js_arguments} #{optimization_argument} #{closure_argument} #{debug_argument}"
118
119
  RakeFileUtils.sh "emcc -std=c++11 --bind -I #{mruby_directory}/include #{gem_directory}/resources/cpp/esruby.cpp -o #{build_directory}/esruby.o #{build_directory}/emscripten/lib/libmruby.a -lm #{js_arguments} #{optimization_argument} #{closure_argument} #{debug_argument}"
119
- RakeFileUtils.sh "emcc -std=c++11 --bind -I #{mruby_directory}/include #{gem_directory}/resources/cpp/main.cpp -o #{build_directory}/main.o #{build_directory}/emscripten/lib/libmruby.a -lm #{js_arguments} #{optimization_argument} #{closure_argument} #{debug_argument}"
120
- RakeFileUtils.sh "emcc --bind -I #{mruby_directory}/include -o #{build_directory}/output.js #{build_directory}/app.o #{build_directory}/esruby.o #{build_directory}/main.o #{build_directory}/emscripten/lib/libmruby.a -lm #{js_arguments} #{optimization_argument} #{closure_argument} #{debug_argument}"
120
+ RakeFileUtils.sh "emcc --bind -I #{mruby_directory}/include -o #{build_directory}/output.js #{build_directory}/app.o #{build_directory}/esruby.o #{build_directory}/emscripten/lib/libmruby.a -lm #{js_arguments} #{optimization_argument} #{closure_argument} #{debug_argument}"
121
121
  #if build.build_mode == 'production'
122
122
  # sh "java -jar #{PROJECT_DIRECTORY}/emsdk/emscripten/incoming/third_party/closure-compiler/compiler.jar --js #{build.absolute_build_directory}/output.js --js_output_file #{build.absolute_output}"
123
123
  #else
@@ -1,64 +1,51 @@
1
1
  #include "esruby.hpp"
2
2
 
3
- ESRuby::ESRuby()
3
+ mrb_state* ESRuby::_mrb = nullptr;
4
+
5
+ void ESRuby::start()
4
6
  {
7
+ if (_mrb)
8
+ {
9
+ printf("Error: ESRuby already started\n");
10
+ throw std::runtime_error("Error: ESRuby already started");
11
+ }
5
12
  _mrb = mrb_open();
6
13
  if (!_mrb)
14
+ {
15
+ printf("error opening new mrb state\n");
7
16
  throw std::runtime_error("error opening new mrb state");
8
- _print_level = 1;
17
+ }
18
+ mrb_load_irep(_mrb, app);
19
+ // print error if any
20
+ if (_mrb->exc)
21
+ {
22
+ mrb_p(_mrb, mrb_obj_value(_mrb->exc));
23
+ _mrb->exc = 0;
24
+ throw std::runtime_error("ruby error encountered");
25
+ }
9
26
  }
10
27
 
11
- ESRuby::~ESRuby()
28
+ void ESRuby::stop()
12
29
  {
30
+ if (!_mrb)
31
+ {
32
+ printf("Error: ESRuby not active\n");
33
+ throw std::runtime_error("Error: ESRuby not active");
34
+ }
13
35
  mrb_close(_mrb);
14
- }
15
-
16
- int ESRuby::get_print_level()
17
- {
18
- return _print_level;
19
- }
20
-
21
- void ESRuby::run()
22
- {
23
- mrb_value result = mrb_load_irep(_mrb, app);
24
-
25
- // print levels:
26
- switch(_print_level)
36
+ // print error if any
37
+ if (_mrb->exc)
27
38
  {
28
- case 0: // do not print anything
29
- break;
30
- case 1: // print errors only
31
- if (_mrb->exc)
32
- {
33
- mrb_p(_mrb, mrb_obj_value(_mrb->exc));
34
- _mrb->exc = 0;
35
- }
36
- break;
37
- case 2: // print errors and results
38
- if (_mrb->exc)
39
- {
40
- mrb_p(_mrb, mrb_obj_value(_mrb->exc));
41
- _mrb->exc = 0;
42
- }
43
- mrb_p(_mrb, result);
44
- break;
39
+ mrb_p(_mrb, mrb_obj_value(_mrb->exc));
40
+ _mrb->exc = 0;
41
+ throw std::runtime_error("ruby error encountered");
45
42
  }
46
43
  }
47
44
 
48
- void ESRuby::set_print_level(int new_print_level)
49
- {
50
- if (new_print_level >= 0 && new_print_level <= 2)
51
- _print_level = new_print_level;
52
- else
53
- throw std::runtime_error("print level not valid");
54
- }
55
-
56
45
  EMSCRIPTEN_BINDINGS(esruby)
57
46
  {
58
- emscripten::class_<ESRuby>("Webruby")
59
- .constructor<>()
60
- .function("get_print_level", &ESRuby::get_print_level)
61
- .function("run", &ESRuby::run)
62
- .function("set_print_level", &ESRuby::set_print_level)
47
+ emscripten::class_<ESRuby>("ESRuby")
48
+ .class_function("start", &ESRuby::start)
49
+ .class_function("stop", &ESRuby::stop)
63
50
  ;
64
51
  }
@@ -26,16 +26,12 @@ class ESRuby
26
26
 
27
27
  public:
28
28
 
29
- ESRuby();
30
- ~ESRuby();
31
- int get_print_level();
32
- void run();
33
- void set_print_level(int new_print_level);
29
+ static void start();
30
+ static void stop();
34
31
 
35
- protected:
32
+ private:
36
33
 
37
- mrb_state* _mrb;
38
- int _print_level;
34
+ static mrb_state* _mrb;
39
35
 
40
36
  };
41
37
 
@@ -1,45 +1,17 @@
1
- ESRuby = class
1
+ class ESRuby
2
2
  {
3
- constructor()
3
+
4
+ static start()
4
5
  {
5
- if (ESRuby.instance)
6
- return ESRuby.instance;
7
-
6
+ Module.ESRuby.start();
8
7
  }
9
8
 
10
- // Default print level is errors only
11
- this.print_level = 1;
12
- if (typeof opts.print_level === "number" && opts.print_level >= 0)
13
- {
14
- this.print_level = opts.print_level;
15
- }
16
- this.mrb = _mrb_open();
17
- _esruby_internal_setup(this.mrb);
18
- };
19
-
20
- ESRUBY.prototype.close = function()
21
- {
22
- _mrb_close(this.mrb);
23
- };
24
-
25
- ESRUBY.prototype.run = function()
26
- {
27
- _esruby_internal_run(this.mrb, this.print_level);
28
- };
29
-
30
- ESRUBY.prototype.set_print_level = function(level)
31
- {
32
- if (level >= 0) this.print_level = level;
33
- };
34
-
35
-
36
- if (typeof window === 'object')
37
- {
38
- window['ESRUBY'] = ESRUBY;
39
- }
40
- else
41
- {
42
- global['ESRUBY'] = ESRUBY;
43
- }
9
+ static stop()
10
+ {
11
+ Module.ESRuby.stop();
44
12
  }
45
- ) ();
13
+
14
+ }
15
+
16
+ window.addEventListener("load", ESRuby.start);
17
+ window.addEventListener("unload", ESRuby.stop);
@@ -27,8 +27,6 @@ ESRuby::Build.new do |conf|
27
27
  #conf.ldflags << "--memory-init-file 0"
28
28
 
29
29
  # JavaScript calling interface
30
- #conf.gem :git => 'git://github.com/xxuejie/mruby-js.git', :branch => 'master'
31
-
32
30
  # conf.add_gem 'gems/esruby-bind'
33
31
 
34
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Fors
@@ -44,7 +44,6 @@ files:
44
44
  - resources/build_config.eruby
45
45
  - resources/cpp/esruby.cpp
46
46
  - resources/cpp/esruby.hpp
47
- - resources/cpp/main.cpp
48
47
  - resources/js/esruby.js
49
48
  - resources/mruby/AUTHORS
50
49
  - resources/mruby/CONTRIBUTING.md
@@ -442,7 +441,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
442
441
  version: '0'
443
442
  requirements: []
444
443
  rubyforge_project:
445
- rubygems_version: 2.4.8
444
+ rubygems_version: 2.6.11
446
445
  signing_key:
447
446
  specification_version: 4
448
447
  summary: Ruby running in the browser
@@ -1,9 +0,0 @@
1
- #include "esruby.hpp"
2
-
3
-
4
- int main()
5
- {
6
- ESRuby* esruby = new ESRuby;
7
- esruby->run();
8
- return 0;
9
- }