Hi all,
I got quit an important issue to address.
I hope this gets a bit of attention because I'm planning to use this technic all over the place.
I'm trying to create js modules and loading them dynamically.
The problem I got is when 2 different Modules recite in the same package the last loaded Module redefines the the package of the current existing Module.
I 'll give an example.
I got class modules.Module1 and modules.Module2, both have the @:expose metadata.
Module1 is accessing Module2 by an extern class.
The js code looks like this:
<body>
<script type="text/javascript" src="Module2.js"></script>
<script type="text/javascript" src="Module1.js"></script>
</body>
I highlighted the imported part in red.
modules.Module2
(function ($hx_exports) { "use strict";$hx_exports.modules = $hx_exports.modules || {};var modules = {};modules.Module2 = $hx_exports.modules.Module2 = function() {};modules.Module2.main = function() {};modules.Module2.prototype = { fromModule2: function() { return "fromModule2"; }};modules.Module2.main();})(typeof window != "undefined" ? window : exports);
(function ($hx_exports) { "use strict";$hx_exports.modules = $hx_exports.modules || {};var modules = {};modules.Module1 = $hx_exports.modules.Module1 = function() {};modules.Module1.main = function() { var module1 = new modules.Module1(); var module2 = new modules.Module2(); console.log(module1.fromModule1()); console.log(module2.fromModule2());};modules.Module1.prototype = { fromModule1: function() { return "fromModule1"; }};modules.Module1.main();})(typeof window != "undefined" ? window : exports);
What happens is that Module1 redefines the package modules whereby it cannot longer access modules.Modules2
My browser gives me this error:
TypeError: modules.Module2 is not a constructor
var module2 = new modules.Module2();
So my question is how can this be fixed?
Is there an already existing fix?
And so not is this gonna be fixed in the future versions of the haxe js compiler?
Adrian
package modules;
import externs.Module2;
@:exposeclass Module1 { public static function main() : Void { var module1 = new Module1(); var module2 = new Module2(); trace( module1.fromModule1() ); trace( module2.fromModule2() ); } public function new(){} public function fromModule1() : String { return "fromModule1"; }}
package modules;
@:exposeclass Module2 { public static function main(){} public function new(){} public function fromModule2() : String { return "fromModule2"; }}
package externs;
@:expose@:native("modules.Module2")
extern class Module2 { public function new(); public function fromModule2() : String;}
--
You received this message because you are subscribed to the Google Groups "Haxe" group.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
--
Mockey
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.
-main modules.Module1
--macro exclude('modules.Module2')
--macro addMetadata('@:native("window.modules.Module2")','modules.Module2')
--next
modules.Module2
--macro addMetadata('@:expose','modules.Module2')
-cp src/--macro Build.main()--nextbuildscript.hxml
package ;
import modules.Modules;import modules.Module1;import modules.Module2;
class Build
{ public static function main() : Void {
var builder = new Builder( Build ); var mod1 = builder.create.jsProject( Module1 ); var mod2 = builder.create.jsProject( Module2 ); mod2.useMainFunction = false; mod1.setModules( Modules.Module1() ); mod2.setModules( Modules.Module2() ); builder.addProject( mod1 ); builder.addProject( mod2 ); builder.build(); //builder.print(); }}
Hi guys,
I did some work on my modular approach recently.
And I must say that I got almost everything working now.
I also uploaded my library to github.
Called it Zcale becasue the projects are scalable to any size with the use modules.
I got my hxml builder that for example generates this:
https://github.com/adrianmm44/zcale/blob/master/tests/core/ModulesTester/src/Build.hx
into:
https://github.com/adrianmm44/zcale/blob/master/tests/core/ModulesTester/buildscript.hxml
I got a Modules class that defines the modules and knows which modules are used each module:
https://github.com/adrianmm44/zcale/blob/master/tests/core/ModulesTester/src/Modules.hx
And then I got my core classes that are needed for startup and the most basic needs:
https://github.com/adrianmm44/zcale/tree/master/zcale/core
This is the class I use for my compiler macros:
https://github.com/adrianmm44/zcale/blob/master/zcale/macros/CompileMacros.hx
Now…
Compiler.exclude( source ) does what it says it does. It excludes the defined classes or package …but… not the native haxe classes that are used by those classes. So if for example if I exclude ScriptLoader that uses haxe.Http, it excludes ScriptLoader but not haxe.Http.
So I'm wondering right now how to solve this.
Firstly do you guys know if this is correct behavior of haxe? Or is this a bug?
Secondly do you know if there is an easy way to fix this?
Otherwise I was thinking of using Context.onGenerate and checking which class is used by which class to check whether it's allowed to compile or not but I think that's quite a complex task and I'm not sure if that's even possible.
Any thought about on this?
Adrian
Hi.
--