Skip to content

Commit

Permalink
fix: initialize bug on C# HeapsIO#47
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubuns committed Jun 1, 2020
1 parent e8ea39d commit 9ce35bd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 3 additions & 1 deletion haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"version" : "1.5.0",
"releasenote" : "",
"contributors" : ["ncannasse"],
"dependencies" : {}
"dependencies" : {
"compiletime" : "2.8.0"
}
}
31 changes: 30 additions & 1 deletion hxbitmini/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,14 @@ class Macros {
pos : pos,
access : [AStatic],
meta : noCompletion,
kind : FVar(macro : Int, macro @:privateAccess hxbitmini.Serializer.registerClass($p{clName})),
kind : FVar(macro : Int),
});
fields.push({
name : "initCLID",
pos : pos,
access : access.concat([AStatic]),
meta : noCompletion,
kind : FFun({ args : [], ret : null , expr : macro __clid = @:privateAccess hxbitmini.Serializer.registerClass($p{clName}) }),
});
fields.push({
name : "getCLID",
Expand Down Expand Up @@ -903,6 +910,28 @@ class Macros {
}
}

public static function buildSerializer() {
var fields = Context.getBuildFields();
var pos = Context.currentPos();
var noCompletion = [{ name : ":noCompletion", pos : pos }];

fields.push({
name : "initCLIDS",
pos : pos,
access : [AStatic, APrivate],
meta : noCompletion,
kind : FFun({ args : [], ret : null , expr : macro {
var serializables = CompileTime.getAllClasses(Serializable);
for( cl in serializables ) {
var fl : Dynamic = Reflect.field(cl, "initCLID");
Reflect.callMethod(cl, fl, []);
}
} }),
});

return fields;
}

#end

}
6 changes: 5 additions & 1 deletion hxbitmini/Serializer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package hxbitmini;

#if !macro

@:build(hxbitmini.Macros.buildSerializer())
class Serializer {

static var SEQ = 0;
Expand Down Expand Up @@ -105,7 +106,10 @@ class Serializer {
var knownStructs : Array<StructSerializable>;

public function new() {
if( CLIDS == null ) initClassIDS();
if( CLIDS == null ) {
initCLIDS();
initClassIDS();
}
}

public function begin() {
Expand Down

0 comments on commit 9ce35bd

Please sign in to comment.