Code Monkey home page Code Monkey logo

flixel-nx-test's Introduction

Switch Haxe sample project

This is a sample project for running Haxe on the Nintendo Switch using devkitA64 and libnx.

Right now the libnx binding only contains what's needed to run the Hello World sample. It's very easy to add more, PRs are welcome :)

Special thanks to Aurel300 for his guidance on how to use ammer.

Dependencies

  • devkitA64 and libnx
  • Haxe (duh)
  • This fork of hxcpp (install using haxelib git), containing the modified toolchain
  • This fork of ammer (install using haxelib git), used to bind external C libraries
  • The Haxe libnx binding (already included in the sample as a subrepo)

How to use

  1. Haxe code goes in haxe_src
  2. Run build_haxe.sh to compile the Haxe code
    • Run clean_haxe.sh to clean that
  3. Run make to link the output of that in an NRO
  4. You need to run BOTH steps (compilation + linking) every time you change the Haxe code
  5. You can change the homebrew name, icon, romfs... by editing the Makefile like any other homebrew

How does it work

  1. build_haxe.sh:
    1. converts the Haxe code into C++ classes
    2. compiles the code into a .a file (libMain.a)
      • this code alone is not executable, it's just an archive containing all the Haxe classes
  2. the standard homebrew Makefile:
    1. compiles wrapper.c, which contains a main function booting the Haxe main class
    2. links libMain.a and wrapper.o into the final NRO

So Haxe is responsible for the compilation step, and the homebrew Makefile is responsible for the linking step. It's important to know if you want to add external libraries.

How to use external C/C++ libraries

You need to add the includes directory to the hxcpp path, and the library to the Makefile.

  1. By editing either directly the toolchain XML file or by adding a custom Build.xml to your project, add the includes directory to the hxcpp path
  2. Use ammer to bind your C functions to an Haxe class
    • If the header name is not the same as the library name (for instance the header for libnx is switch.h, not nx.h), edit build_haxe.sh and add an ammer define like the one libnx has (ammer.lib.xxx.headers)
  3. In the homebrew Makefile, add the library to the LIBS variable as you would for a regular homebrew
    • No need to add it to the includes path, as wrapper.c is the only file left to compile at that point
    • In this file, $(HAXE_LIBMAIN) corresponds to your Haxe code (libMain.a)

flixel-nx-test's People

Watchers

Nat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.