Module: Webruby
- Defined in:
- lib/webruby/app.rb,
lib/webruby/config.rb,
lib/webruby/utility.rb
Defined Under Namespace
Constant Summary collapse
- COMMON_EXPORTED_FUNCTIONS =
It may appear that mode 0 and mode 1 requires the same set of functions since they both load bytecodes, but due to the fact that mode 0 only loads pre-defined bytecode array, chances are optimizers may perform some tricks to eliminate parts of the source code for mode 0. Hence we still distinguish mode 0 from mode 1 here
['mrb_open', 'mrb_close']
Class Method Summary collapse
- .build_config ⇒ Object
- .build_dir ⇒ Object
- .create_file_if_different(filename) {|f| ... } ⇒ Object
- .entrypoint_file ⇒ Object
- .full_build_config ⇒ Object
- .full_build_dir ⇒ Object
- .gem_js_files ⇒ Object
- .gem_js_flags ⇒ Object
- .gem_test_js_files ⇒ Object
- .gem_test_js_flags ⇒ Object
-
.get_exported_arg(gem_function_file, loading_mode, custom_functions) ⇒ Object
Generate command line option for exported functions, see gen_exported_functions for argument details.
-
.get_exported_functions(gem_function_file, loading_mode, custom_functions) ⇒ Object
Gets a list of all exported functions including following types: * Functions exported by mrbgems * Functions required by loading modes * Functions that are customly added by users.
- .rb_files ⇒ Object
Class Method Details
.build_config ⇒ Object
30 31 32 |
# File 'lib/webruby/utility.rb', line 30 def build_config "#{build_dir}/mruby_build_config.rb" end |
.build_dir ⇒ Object
22 23 24 |
# File 'lib/webruby/utility.rb', line 22 def build_dir Webruby::App.config.build_dir end |
.create_file_if_different(filename) {|f| ... } ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/webruby/utility.rb', line 5 def create_file_if_different(filename) tmp_filename = "#{filename}.tmp" # TODO: add support for case where block is not given, # maybe using monkey patching on File#close? f = File.open(tmp_filename, 'w') yield f f.close if (!File.exists?(filename)) || (!FileUtils.compare_file(filename, tmp_filename)) puts "Creating new file: #{filename}!" FileUtils.cp(tmp_filename, filename) end FileUtils.rm(tmp_filename) end |
.entrypoint_file ⇒ Object
38 39 40 |
# File 'lib/webruby/utility.rb', line 38 def entrypoint_file Webruby::App.config.entrypoint end |
.full_build_config ⇒ Object
34 35 36 |
# File 'lib/webruby/utility.rb', line 34 def full_build_config File.(build_config) end |
.full_build_dir ⇒ Object
26 27 28 |
# File 'lib/webruby/utility.rb', line 26 def full_build_dir File.(build_dir) end |
.gem_js_files ⇒ Object
46 47 48 |
# File 'lib/webruby/utility.rb', line 46 def gem_js_files ["#{build_dir}/gem_library.js", "#{build_dir}/gem_append.js"] end |
.gem_js_flags ⇒ Object
50 51 52 |
# File 'lib/webruby/utility.rb', line 50 def gem_js_flags "--js-library #{build_dir}/gem_library.js --pre-js #{build_dir}/gem_append.js" end |
.gem_test_js_files ⇒ Object
54 55 56 |
# File 'lib/webruby/utility.rb', line 54 def gem_test_js_files ["#{build_dir}/gem_test_library.js", "#{build_dir}/gem_test_append.js"] end |
.gem_test_js_flags ⇒ Object
58 59 60 |
# File 'lib/webruby/utility.rb', line 58 def gem_test_js_flags "--js-library #{build_dir}/gem_test_library.js --pre-js #{build_dir}/gem_test_append.js" end |
.get_exported_arg(gem_function_file, loading_mode, custom_functions) ⇒ Object
Generate command line option for exported functions, see gen_exported_functions for argument details
125 126 127 128 129 130 |
# File 'lib/webruby/utility.rb', line 125 def get_exported_arg(gem_function_file, loading_mode, custom_functions) func_str = get_exported_functions(gem_function_file, loading_mode, custom_functions) .map{|f| "'_#{f}'"}.join ', ' "-s EXPORTED_FUNCTIONS=\"[#{func_str}]\"" end |
.get_exported_functions(gem_function_file, loading_mode, custom_functions) ⇒ Object
Gets a list of all exported functions including following types:
-
Functions exported by mrbgems
-
Functions required by loading modes
-
Functions that are customly added by users
Attributes
-
gem_function_file
- File name of functions exported by mrbgems, this is
generated by scripts/gen_gems_config.rb
-
loading_mode
- Loading mode -
custom_functions
- Array of custom functions added by user
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/webruby/utility.rb', line 104 def get_exported_functions(gem_function_file, loading_mode, custom_functions) loading_mode = loading_mode.to_i functions = File.readlines(gem_function_file).map {|f| f.strip} functions = functions.concat(custom_functions) functions = functions.concat(COMMON_EXPORTED_FUNCTIONS) # WEBRUBY.run is supported by all loading modes functions << 'webruby_internal_run' # WEBRUBY.run_bytecode functions << 'webruby_internal_run_bytecode' if loading_mode > 0 # WEBRUBY.run_source functions << 'webruby_internal_run_source' if loading_mode > 1 functions.uniq end |
.rb_files ⇒ Object
42 43 44 |
# File 'lib/webruby/utility.rb', line 42 def rb_files Dir.glob("#{File.dirname(entrypoint_file)}/**") end |