Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.74 KB

03.creating-cppia-host.md

File metadata and controls

46 lines (33 loc) · 1.74 KB

Creating a cppia host

In the previous section we learned how to create the script.cppia file needed in this example.

A cppia host is a c++ executable compiled with the Haxe c++ target. To create a host, we start with a class file (here we choose the name Host.hx) including a static main function:

// Host.hx
class Host {
  static public function main():Void {
    trace('Hello from cppia HOST');
    var scriptname = './script.cppia';             
    cpp.cppia.Host.runFile(scriptname);  // <- load and execute the .cppia script file 
  }
}

As you can see in the code example above, at runtime our executable will start by tracing a simple "Hello from cppia HOST" message. Then it will load and execute the script.cppia file.

host.hxml

We can compile this file into a cpp executable using the following host.hxml file:

-cp src
-main Host
-cpp bin
-D scriptable

(Please note that we use the -D scriptable directive to tell the compiler to include the functionality needed by a cppia host.)

When we run the following command...

> haxe host.hxml

...the c++ compiler will start the two step compilation process (1. generate the c++ source files, and 2. kick off the c++ compiler to create the executable). The result will be a host executable called bin/Host on Linux/Mac and bin/Host.exe on Windows.

You will notice that an additional file will be created : export_classes.info. This file contains informations about classes and other components included in the host you have just generated.
You can specify a path for this file by using -D dll_export=my/path/export_class.info.

Moreover, when compiling your CPPIA script, you'll want to add its counterpart: -D dll_import=my/path/export_class.info.