Question

I'm started programming not too long ago. I use a little of Python, Lua, and Ruby. Is it possible to compile all three scripts into one executable using py2exe, py2app, or py2deb?

If not, which one should I use for game development, and if anyone has any type of resources to study off of, I really would mind learning more.

Was it helpful?

Solution

Combining them all into one executable is hard. Combining them into one application, not so hard.

Let's take py2app as an example. It builds an OS X application bundle—a directory full of files. There's a complete Python interpreter with a custom standard library in the Frameworks subdirectory. And your application's Python source code (and/or .pyc bytecode) and all of your data files are in the Resources subdirectory. Finally, in the MacOS subdirectory, there are two things: a standard python stub executable, which runs Python with your custom standard library, and another stub executable with the name of your app, which runs Python with your custom standard library and executes your main script.

Imagine you had an identical tool for Ruby and Lua.

You could very easily build an application bundle that puts each framework in the Frameworks directory, puts all your source code in all three languages, and all of your data files, into the Resources directory, and puts all three stub executables in the MacOS directory. Whichever one of your scripts is the main program, you'd keep just the stub executable for that one.

As long as your scripts know how to find the python, lua, and ruby stub executables to launch other scripts (which you can do by, e.g., modifying the PATH in the environment at the start of your main script), everything works.

And there's an even simpler solution: py2app (and ruby2app and lua2app) up each application separately, and then just package the complete applications inside the bundle (e.g., in an Applications directory under the Library directory) and just run them that way. The down side is that if you have 20 different Python scripts, you're going to end up with 20 complete Python installations, which gets to be a pretty big download.

But you can go half-way in between: merge all the Python apps into one bundle, all the Ruby apps into another, and all the Lua apps into another.

The problem with doing this in practice are that you don't actually have an identical tool for Ruby and Lua; you have different tools, which build different structures. And you don't have an identical tool for Windows (py2exe builds a very differently-shaped structure, and uses very different configuration settings). So you need to understand (up to) the cartesian product of N*M different structures if you have N languages and M platforms.

And you really do need all the separate tools. py2app can't be used on Ruby or Lua code, or Windows code, because it needs to understand Python modules—including Python C extension modules, which it has to understand at the Mach-O level as well as at the Python API level—in order to figure out the dependencies and get the right files, and figure out the right places to put them in the bundle so the interpreter can find them, and so on.

Still, it's definitely doable—I've worked on two projects that bundled up multiple scripts written in two or three different scripting languages in exactly the way I described above.

OTHER TIPS

  1. No. It might be possible to use the JVM versions of the languages to create JVM classes, then JAR them up. I have never used any of them besides jRuby.

  2. Why use three similar scripting languages at the same time? It's like eating pasta with mashed potatoes and bread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top