COMMUNITY

How to install haxe for PHP, Python, Java, C++, OpenFL?

haxe-php
haxe-python
haxe-java
haxe-cpp

(Robin) #1

Hello everyone!

I am in the process of building guides to help users get started with Haxe. The C# guide is ready here : Getting started with Haxe for C#

As experts in your respective platforms, I need your help in building these guides!

Reply with info on how you setup your platform, your OS, and any other steps that were needed to get a haxe app for platform X compiling and running.

Platforms I’m looking for : PHP, Python, Java, C++, OpenFL.

Thanks!


(Aleksandr Kuzmenko) #2

PHP

  1. Install PHP 7.0+ http://php.net/manual/en/install.php ;
  2. Build a Haxe project with -php bin;
  3. Run in the command line: $ php bin/index.php. Or on a web server by putting generated files to the document root and accessing index.php via browser.

(Robin) #3

For PHP, are the distros like WAMP/XAMPP or the LAMP Stack on linux also supported?

Also, can I write code for frameworks like CakePHP?

Can I use external PHP libraries in Haxe?


(Randy Maxwell) #4

PYTHON

Haxe requires Python 3.x The latest as of now (Feb 22, 2019) is Python 3.7.2
Because of Security fixes and new Python features Python 3.6 or later is recommended.

Take a little time to read the page as there may be some errata for your OS or for problems if you also want to embed the Python interpreter within your application.

Using Python on Windows Tips
I install on Windows and install Python 64 bit for all Users.
Python install does not change any Registry values.
Python install adds the installed Python directory to the Path environment variable.

If you need to Uninstall on Windows
delete the directory where Python was installed such as:
C:\Program Files\Python37
To Uninstall you also need to edit the Path setting and remove the reference to the Python37 directory.

After install open Cmd.exe window (or your favorite shell) and type
python

you should see something like:

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> prompt is from the Python interpreter and shows it is ready for you to type in commands or run a .py program (typically called a Python script).

Install Haxe. Python support is already part of Haxe.

Using Haxe to compile to Python
Haxe puts all of your Haxe sources and also sources for any Haxe libraries
into a single Python .py file.

haxe -lib haxe-strings -cp src -python C:/Programming/Haxe/My_Project/Python_OUT/main.py -main Main

Important Note:
Please notice that a Python_OUT directory is used to hold the main.py file.
If you use Haxe to build to multiple languages such as Python, JavaScript and so on:
Having Haxe output each language in a separate directory allows for easier management.

Running Python Programs
If you used a separate directory, the below will work.

cd Python_OUT
python main.py

Debugging Python Programs
IDLE Debugger is included with Python (UI is more of a Text than Graphical window appearance)
PyScripter on Windows is a full IDE that works nicely with a more modern GUI.
Visual Studio 2017 Community Edition
Visual Studio Code
Eclipse (not sure how up to date the Python plugin is)


(Randy Maxwell) #5

JAVA

Haxe requires Java 6 (not sure) The latest as of now (Feb 22, 2019) is Java 8 update 201
Because of Security fixes and new Java features Java 8 or later is recommended.

Select the Java build that fits your platform and OS.
For desktop platforms:
Please install the Java Runtime Environment (JRE) and the Software Development Kit (SDK).
The Java SDK includes the javac compiler that converts .java files into a .jar file.

Android for example has Java already installed.
Android Studio would be recommended there.
NOT SURE if Haxe can generate .java code that will run on an Android platform.

Make your choices when running the Java installer.

After install open Cmd.exe window (or your favorite shell) and type
java

You will see several short descriptions of command line options for Java. Or type
java -showversion

and you will see (example from Windows 64 bit)

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

Followed by several short descriptions of command line options for Java.

Install Haxe and Java support library hxjava

Using Haxe to compile to Java
Haxe puts all of your Haxe sources and also sources for any Haxe libraries
changed to various .java files
into a src subdirectory of a directory you give.

Example, change to fit your needs.
haxe -lib haxe-strings -cp src -java C:/Programming/Haxe/My_Project/Java_OUT -main Main

Important Note:
Please notice that a Java_OUT directory is used to hold the src directory of the java files.
If you use Haxe to build to multiple languages such as Java, JavaScript and so on:
Having Haxe output each language in a separate directory allows for easier management.

Running Java Programs
If you used a separate directory, the below will work.

cd Java_OUT
java -jar Main.jar

Debugging Java Programs
IntelliJ Community Edition 2018.3
Netbeans
Eclipse

Somewhat biased article

ERRATA:

INCORRECTLY states that only JRE is needed.
javac is needed to built a .jar file
The SDK has javac and not the JRE

http://old.haxe.org/doc/start/java
Has mostly better information with some good Tips on how to fix problems of install and setup.


(Aleksandr Kuzmenko) #6

Any PHP7+ installation with multibyte string extension is supported.

Interop with PHP code is as easy as calling php.Syntax.code("echo {0}", exprToPrint) (php.Syntax api)

It’s also easy to create externs. Here is an of a Haxe project, which is using Zend\Json via externs: https://gist.github.com/RealyUniqueName/e0c6a3c051c790c0cfae58eeebdd7fae


(John Gabriele) #7

Hi, RMax. Thanks for the Python instructions.

I’m curious, what is the reason for specifying the use of the haxe-strings library? (Note: I’m on Debian GNU/Linux using Haxe 4.0.0-rc.1+1fdd3d5, and Python 3.7.2+.) Or are you just including an example of how to include a haxe lib in a given build?

Incidentally, I noticed a warning when compiling to Python. Given a simple hello-world Main.hx file:

class Main {
    public static function main() {
        trace("Hi, World!");
    }
}

When I build it, I get the following warning:

$ haxe -cp src -main Main -python Python-OUT/main.py
/home/john/opt/haxe/std/python/NativeIterable.hx:48: characters 2-9 : Warning : private structure fields are deprecated

(Randy Maxwell) #8

@uvtc, @Haxe Team, All,

@Haxe Team
I get the same Warning on Windows. And also on Python 3.6.4
I am guessing this is a somewhat recent change to Haxe (within last few months) that may have triggered this Python Warning.

haxe-strings library was included in the example as a half way mistake by me :slight_smile:
haxe-strings was essential before Haxe 4 added full support for Unicode to allow the 4GL project to correctly use UTF8 internally and for output.
But I think it is important to show the use of a Library as part of the example.
So that was the half way that was a fairly good idea. As part of taking my first input it would be better to use a different Haxe library as the example perhaps.


(John Gabriele) #9

Ah, thanks for the background info!


(Valentin Lemière) #10

That’s not a python warning, it happens when you compile your haxe code, see https://github.com/HaxeFoundation/haxe/issues/7436


(Robin) #11

Thank you everyone for participating in this effort! (especially @RMax and @RealyUniqueName)

I’ll work on prototypes for these and keep you updated…


(Kevin Leung) #12

Travix is a library that helps setting up Haxe targets in Travis CI. It basically helps installing all the required software to run a Haxe target (e.g. c++ / php / lua). For example, this code includes the step to setup an environment to run Lua output from Haxe. So I guess this library should be a good reference for you.


(Robin) #13

@Simn @nadako @waneck

Can everyone please check these PRs so they can be merged quickly?


(Randy Maxwell) #14

I could see the raw HTML source but not what the rendered HTML looked like in a browser.
Because of that: A warning about Python output.
Python goes into 1 source file. There was discussion about bin but because I could not see rendered page the directions MAY have Haxe put Python output into a file named bin. Which would lead to some confusion and be against standard naming .py file extension for Python sources.

Feedback for improving the process:
Have a way for anyone reviewing HTML sources to have a graceful way to view them when rendered. I admit I am mostly a newbie of HTML / JS / CSS so perhaps I missed something obvious to you all.

Perhaps more importantly:
Go through description and follow steps as if you were just learning about Haxe and wanted to try Java or Python. Following steps as closely as possible! Hopefully this will help to catch any misleading or missing details.

Thanks to Robin and the Haxe Team.


(Robin) #15

Hi @RMax

You can view the final pages here: