Repository navigation
Wildcard import support #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Jamextreme140
merged 3 commits into
CodenameCrew:codename-dev
from
hackx2:wildcard-import-impl
Nov 22, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package hscript.macros; | ||
|
|
||
| #if !hscriptNoWildcardImports | ||
| import haxe.ds.StringMap; | ||
| import haxe.rtti.Meta; | ||
|
|
||
| #if macro | ||
| import haxe.macro.Context; | ||
| import haxe.macro.Expr; | ||
| #end | ||
|
|
||
| using StringTools; | ||
|
|
||
| /** @author hackx2 **/ | ||
| @:keep | ||
| final class WildcardMacro { // uses rtti to store type names | ||
| static final INDEX_META_NAME= "__indexed_types"; | ||
| static final SEPARATOR = '~'; | ||
| #if macro | ||
| static var __has_gen = false; | ||
| #end | ||
|
|
||
| public static macro function getTypes() { | ||
| #if macro | ||
| if(!__has_gen) { | ||
| __has_gen = true; | ||
| Context.onGenerate(_ -> { | ||
| switch Context.getType('hscript.macros.WildcardMacro') { | ||
| case TInst(t, _): | ||
| final meta = t.get().meta; | ||
| if(!meta.has(INDEX_META_NAME)) { | ||
| final arr:Array<Expr> = [ | ||
| macro $v { | ||
| [ | ||
| for(i in Context.getAllModuleTypes()) { | ||
| final typeName = switch i { | ||
| case TClassDecl(cls): | ||
| cls.toString(); | ||
| case TEnumDecl(enum_): | ||
| enum_.toString(); | ||
| case _: null; | ||
| } | ||
|
|
||
| if(typeName != null && !typeName.endsWith('_Fields_') && !typeName.endsWith('_Impl_') && !typeName.endsWith(ClassExtendMacro.CLASS_SUFFIX)) { | ||
| typeName; | ||
| } | ||
| } | ||
| ].join(SEPARATOR) | ||
| } | ||
| ]; | ||
|
|
||
| meta.add(INDEX_META_NAME, arr,Context.currentPos()); | ||
| } | ||
| case _: // nothin | ||
| } | ||
| }); | ||
| } | ||
| #end | ||
|
|
||
| return macro { | ||
| final types = new haxe.ds.StringMap<Array<String>>(); | ||
|
|
||
| final rttiType = haxe.rtti.Meta.getType(hscript.macros.WildcardMacro); | ||
| final raw:Dynamic = Reflect.field(rttiType, $v{INDEX_META_NAME}); | ||
|
|
||
| if(raw != null) { | ||
| for (t in (raw[0] : String).split($v{SEPARATOR})) { | ||
| final dot = t.lastIndexOf('.'); | ||
| final pack = dot == -1 ? '' : t.substr(0, dot); | ||
| final name = t.substr(dot + 1); | ||
|
|
||
| final type_pack = types.get(pack); | ||
| if (type_pack == null) types.set(pack, [name]) else type_pack.push(name); | ||
| } | ||
| } | ||
|
|
||
| types; | ||
| } | ||
| } | ||
| } | ||
| #end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package hscript.utils; | ||
|
|
||
| #if !hscriptNoWildcardImports | ||
| import haxe.ds.StringMap; | ||
| import hscript.macros.WildcardMacro; | ||
|
|
||
| class TypeListRegistry { | ||
| static var list(default, null):StringMap<Array<String>>; | ||
| public static function get(pkg:String) { | ||
| final map = list ??= WildcardMacro.getTypes(); | ||
| return map != null ? map.get(pkg) : null; | ||
| } | ||
| } | ||
| #end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request has already been merged, but I have noticed that
importFailedCallbackis not used here (or anywhere in the pull request), the variable does use only 2 parameters beingArray<String>, Null<String>, so it could be changed to include anisWildCard:Boolparameter so that it could fit here (or just make another callback though that's a bit much).Adding the resolver here would allow for wildcard scripted packages, and making it more consistent with what you'd expect
importFailedCallbackto do.This is all really just my thoughts and opinions, as someone who has been messing around with hscript for the last 2 years, so take what I say with a grain of salt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#36 & CodenameCrew/CodenameEngine#1210