From 68572515dca59c27b39da4fac25ab54063324976 Mon Sep 17 00:00:00 2001 From: arngo <27396817+arngo@users.noreply.github.com> Date: Thu, 13 Jan 2022 22:44:53 -0500 Subject: implement require by merging all required files into one file before compiling to bytecode --- Rakefile | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index ee2e353..d9d6a64 100644 --- a/Rakefile +++ b/Rakefile @@ -9,11 +9,30 @@ namespace :build do system('env MRUBY_CONFIG=build_config/felflame_linux.rb rake') end end - desc 'Compile the game to bytecode' - task :bytecode do + #desc 'Export to single file' + task :single_file do + result = '' + main = File.read('game/main.rb') + tmp = main.lines(chomp: true).select do |line| + line.include? 'require ' + end + tmp.each do |file| + file.delete_prefix!('require ') + result += "#{File.read("game/#{file[1, file.length - 2]}")}\n" + end + + result += main.lines.reject do |line| + line.include? 'require ' + end.join + + Dir.mkdir("build/temp") unless File.exists?("build/temp") + File.write('build/temp/main.rb', result) + end + #desc 'Compile the game to bytecode' + task :bytecode => :single_file do Dir.mkdir("build/temp") unless File.exists?("build/temp") Dir.chdir("build/temp") do - system("../../mruby/bin/mrbc -Bbytecode -obytecode.h ../../game.rb") + system("../../mruby/bin/mrbc -Bbytecode -obytecode.h main.rb") end end desc 'Build the game for web' -- cgit v1.2.3