Skip to content

Instantly share code, notes, and snippets.

@cambiata
Last active October 10, 2016 14:24
Show Gist options
  • Save cambiata/94517a63af126c5ec89adeb6c1e838da to your computer and use it in GitHub Desktop.
Save cambiata/94517a63af126c5ec89adeb6c1e838da to your computer and use it in GitHub Desktop.

Let's do some cppia

Note! Created a repo to replace this gist: https://github.com/cambiata/Haxe-Cppia-Basics Easier to testrun, fork and pr! Thanks, @PDeveloper!

This is a simple testproject created for the single purpose of learning how to use cppia, the scripable "cpp subtarget" for Haxe, created by Hugh Sanderson.

Info about cppia can be found in Hugh's WWX2015 talk (cppia part starts around 15:45).

Please note that this is WORK IN PROGRESS, and that I haven't yet found out to create a working cppia host..! Please step in with discussion and contributions!

A cppia script is a "instructions assembly" script that can be run by inside a cppia host, and gives you Neko JIT runtime speed at near-zero compilation time. It also lets add performance critical code to the host, wich gives you full cpp runtime speed for those parts.

script.hxml

The script.hxml file below should be compiled as follows:

> haxe script.hxml

Please note the -D cppia compilation flag that tells the compiler to output a cppia script (bin/script.cppia) instead of a standard cpp executable.

The bin/script.cppia can be tested by using the cppia host included with the standard haxelib hxcpp installation, as follows:

> cd bin

> haxelib run hxcpp script.cppia

This should output the following:

> Main.hx:4: Hello from cppia SCRIPT

host.hxml

The host.hxml file below should be compiled as follows:

> haxe host.hxml

Please note the -D scriptable compilation flag that tells the compiler to include what's needed to act like a cppia host (bin/Main.exe).

##Problem!

The line Main.hx:9 is my attempt to load and run the script.cppia into the Main.exe host. Unfortunately, it doesn't work. The only thing that happens is that some kind of loop is kicked of wich prints out the host line 7 multiple times:

> Main.hx:7: Hello from cppia HOST!

> Main.hx:7: Hello from cppia HOST!

> Main.hx:7: Hello from cppia HOST!

etc. without sign that the script code is ever run.

-cp src
-main Main
-cpp bin
-D scriptable
class Main {
static function main() {
#if cppia // Code run by the cppia script
trace("Hello from cppia SCRIPT!");
#elseif scriptable // Code run by the cppia host
trace("Hello from cppia HOST!");
var scriptname = './script.cppia';
cpp.cppia.Host.runFile(scriptname); // <- doesn't work
#end
}
}
-cp src
-main Main
-cpp bin/script.cppia
-D cppia
@PDeveloper
Copy link

Can you make a repo of the project? Would make it easier to run it and fix + pull request back!

@cambiata
Copy link
Author

Thank, you, @PDeveloper! Sure, I'll create a repo!

@cambiata
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment