Skip to content
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

[FEATURE] Abstracts In Hscript #3777

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

lemz1
Copy link
Contributor

@lemz1 lemz1 commented Oct 26, 2024

DESCRIPTION

This pr aims to make it possible to import abstract classes or enums.
The macro creates "wrappers" around the actual abstract.

NOTE

Currently these packages/classes are not supported:

  • thx.Set (Template issue, specifically not being able to cast Dynamic to some other type)
  • cpp.* (some issue with cpp.Function.fromStaticFunction)
  • lime.* (Somehow duplicate fields, could not determinte type for parameter T)
  • openfl.* (Somehow duplicate fields, could not determinte type for parameter T)

EXPLANATION

For example flixel.util.FlxColor:
We create a class polymod.abstracts.flixel.util.FlxColor_.
This class has all static fields of flixel.util.FlxColor, and just calls the respective fields from the actual flixel.util.FlxColor class. We then create an alias for flixel.util.FlxColor and make it point to polymod.abstracts.flixel.util.FlxColor_.
We also create a public static function called create, which will just call the constructor of the flixel.util.FlxColor.

EXAMPLES

import funkin.play.song.Song;
import flixel.util.FlxColor;
import funkin.PathsFunction;
import flixel.util.FlxTypedSignal;

class ExampleSong extends Song
{
	function new()
	{
		super('exampleSong');
		
		trace(FlxColor.fromInt(0xffff0000)); // -65536
		trace(PathsFunction.INST); // INST
		var signal = FlxTypedSignal.create();
		signal.add(() -> { // the lambda can also take in a parameter, which is of type Dynamic
		    trace('DISPATCHED');
		});
		signal.dispatch();
	}
}

TODO

  • Abstract functions
  • Abstract variables
  • Fix some issues when there is no from/to
  • Create aliases for all specified abstracts (we specify abstracts using an array containing packages and/or classnames)
  • Bit more testing (FlxSignal)
  • Try to make it work with pretty much all abstract. (Gonna need to place Dynamics everywhere)
  • (Optional) Get operators to work implicitly if possible

@github-actions github-actions bot added large A large pull request with more than 100 changes haxe Issue/PR modifies game code labels Oct 26, 2024
@lemz1 lemz1 marked this pull request as draft October 26, 2024 18:52
@AbnormalPoof
Copy link
Contributor

Does this work for abstract classes like FlxSignal? Would love to use that class in HScript!

@lemz1
Copy link
Contributor Author

lemz1 commented Oct 27, 2024

Does this work for abstract classes like FlxSignal? Would love to use that class in HScript!

For now it probably won't work, but i want to add support for it

Currently atleast all the funkin abstracts and FlxColor work

@lemz1 lemz1 marked this pull request as ready for review October 27, 2024 21:59
@charlesisfeline
Copy link

image

@lemz1
Copy link
Contributor Author

lemz1 commented Oct 28, 2024

image

Do you get this error using the latest version of this branch?
Also if you have changed stuff yourself, can you tell what you changed?

@charlesisfeline
Copy link

image

if you have changed stuff yourself, can you tell what you changed?

not much to polymodmacro in terms of functionality

@lemz1
Copy link
Contributor Author

lemz1 commented Oct 28, 2024

image

if you have changed stuff yourself, can you tell what you changed?

not much to polymodmacro in terms of functionality

The error Void should be Array<haxe.macro.Field> gives me an assumption:
Does PolymodHandler have a @:build attribute? If yes, remove it. (or better yet, just remove my branch and re-add it, because maybe github made some mistakes when you updated the branch in your fork)

@charlesisfeline
Copy link

charlesisfeline commented Oct 28, 2024

The error Void should be Array<haxe.macro.Field> gives me an assumption: Does PolymodHandler have a @:build attribute? If yes, remove it.

i already removed it

@lemz1
Copy link
Contributor Author

lemz1 commented Oct 28, 2024

i already removed it

can you give me your source code?
i believe it will be easier for me to fix, if i have your code.

@charlesisfeline
Copy link

oh btw i got this now
[ERROR] (unknown position)

 | Type name polymod.abstracts.funkin.data.song.SongTimeFormat is redefined from module polymod.abstracts.funkin.data.song.SongData (ed6580333f122e0f68c312851416b0fe)

@charlesisfeline
Copy link

can you give me your source code? i believe it will be easier for me to fix, if i have your code.

just gonna leave out the file here ig

@lemz1
Copy link
Contributor Author

lemz1 commented Oct 28, 2024

I found the issue:

            for (abstractCls in abstractClasses)
            {
              for (abstractCls in sortedAbstractClasses)
              {

this should only loop through sortedAbstractClass, so you need to remove for (abstractCls in abstractClasses)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
haxe Issue/PR modifies game code large A large pull request with more than 100 changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants