Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Haxe without a main entry point

Tags:

haxe

I am trying to compile a Haxe class without defining an entry point by using a build hxml file.

My folder structure looks like the following:

root
|
 ___src
     |___Test.hx
|
 ___build.hxml

Test.hx has the following contents:

package foo;

class BarLib 
{
      public function new()  {}

      public function test() {
            return "Hello from BarLib!";
      }
}

build.hxml looks like this:

-cp src 
--macro "include('foo')"
-js test.js

I then run haxe build.hxml from the root folder which creates the file test.js, but its contents is pretty much empty:

// Generated by Haxe 3.3.0
(function () { "use strict";
})();

It seems not to be able to locate the package foo.

What am I doing wrong?

like image 393
codetemplar Avatar asked Feb 06 '23 17:02

codetemplar


1 Answers

You declare Test.hx to be part of the foo package, however, it's placed in a folder named src. If you move it to src/foo, Haxe produces the following output:

// Generated by Haxe 3.3.0
(function () { "use strict";
var foo_BarLib = function() {
};
foo_BarLib.prototype = {
    test: function() {
        return "Hello from BarLib!";
    }
};
})();

It's also a bit unusual to have a file named Test.hx that doesn't actually define a type named Test. BarLib.hx might be a better name.

like image 180
Gama11 Avatar answered Apr 05 '23 21:04

Gama11