-1

Ocra is a ruby gem "transforming" ruby files source code to a .exe file, so any user without ruby installed can launch the program with that generated file.

I'm creating a game editor, so I need a way to create an executable when the user wants to.

  • I have ocra installed on my computer
  • An user don't have ruby or ocra installed on their computer
  • I created a .exe with "ocra program.rbw" command for my program .exe
  • But in my source code, I got the line exec("ocra game.rbw") that can't work in the user's computer because he doesn't have ocra gem installed. Exept that line, all is working well.

Well, here is my question, how can I use ocra command without telling the user to install that gem ? A kind of require (require 'ocra' is not working), or another way to create an executable.

Nat
  • 119
  • 5
  • 1
    OCRA always needs to be installed on the machine that invokes it. Plus it is only available for windows. Please motivate your use of `exec("ocra ...")` – can't you do without? – Raffael Dec 26 '15 at 22:28
  • My program is a game editor. The user can set a game source code that needs to be interpreted by my program. I need my program to create a .exe file for the user's game too. – Nat Dec 26 '15 at 22:40
  • 1
    If you want to create an exe from ruby source code, then it is fair to require ocra to be installed. I don't see a way around it, sorry. There are options that do not involve compiling another exe, though. You might ship an exe along with configuration files that contain the ruby code written by the game editor user. Your game can use the `eval` method to interpret that code. Would that be a viable option? – Raffael Dec 26 '15 at 22:53
  • I see what you mean, it could be a way to dodge exe creation. But isn't that kind of... dirty ? xD Anyway I'm gonna try this, and tell if it's viable. – Nat Dec 26 '15 at 23:03

1 Answers1

0

Thanks to Raffael's answer, it's working like that :

Forget the idea of using exec("ocra game.rbw") into the program. With my computer with ocra installed, I created a basic game.exe with game.rbw that will be interpreted differently thanks to eval. The idea is that instead of creating a new .exe for each different project, we will set it thanks to source code interpretation.

If you had something like that into game.rbw :

Dir.entries("SourceCode").each do |code|
    require_relative "SourceCode/" + code if code.include?(".rb")
end

Replace it by :

Dir.entries("SourceCode").each do |code|
    eval(File.open("SourceCode/" + code, "r:UTF-8").readlines.join("\n")) if code.include?(".rb") 
end

If you set a part of your source code, next time launching your game.exe would be interpreted differently.

Nat
  • 119
  • 5