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

Closed
wants to merge 1 commit into 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 size: large A large pull request with more than 100 changes. pr: haxe PR modifies game code. labels Oct 26, 2024
@lemz1 lemz1 marked this pull request as draft October 26, 2024 18:52
@AbnormalPoof
Copy link
Collaborator

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)

@lemz1 lemz1 force-pushed the polymod-abstract branch 2 times, most recently from 1ebf2ed to e9a1ee4 Compare October 30, 2024 20:01
@EliteMasterEric
Copy link
Member

I'm probably going to reject this as I already have a work in progress for this for Polymod.

@lemz1
Copy link
Contributor Author

lemz1 commented Nov 4, 2024

I already have a work in progress for this for Polymod.

Im kind of interested in the implementation, is it actual support for abstracts or is it something similar to mine, meaning something like the wrappers im using.

Having actual support for abstracts would be fire.

@EliteMasterEric EliteMasterEric added the status: pending triage Awaiting review. label Jan 17, 2025
@Hundrec Hundrec added the type: enhancement Involves an enhancement or new feature. label Jan 22, 2025
@AbnormalPoof AbnormalPoof added the topic: mods Related to the creation or use of mods. label Jan 23, 2025
@EliteMasterEric
Copy link
Member

Im kind of interested in the implementation, is it actual support for abstracts or is it something similar to mine, meaning something like the wrappers im using.

If you look at the compiled game code, the wrapper actually exists internally. For example, flixel.util._FlxColor.FlxColor_Impl_. I have code that is a work in progress that uses a macro to retrieve this internal class and access its functions. Sadly, this internal class does not provide access to static variables on C++ builds specifically due to a bug.

@lemz1
Copy link
Contributor Author

lemz1 commented Jan 30, 2025

Im kind of interested in the implementation, is it actual support for abstracts or is it something similar to mine, meaning something like the wrappers im using.

If you look at the compiled game code, the wrapper actually exists internally. For example, flixel.util._FlxColor.FlxColor_Impl_. I have code that is a work in progress that uses a macro to retrieve this internal class and access its functions. Sadly, this internal class does not provide access to static variables on C++ builds specifically due to a bug.

Oh, so the static variables not existing were a bug. I was going crazy when I tried using the "Impl" classes.
But if I think about it, there still might be a way to get the statics.
Maybe using the class expression or something like that?

I mean my current implementation does get the static variables, but I completely forgot how I did that.

@EliteMasterEric
Copy link
Member

Oh, so the static variables not existing were a bug. I was going crazy when I tried using the "Impl" classes.

The static variables "exist", but they aren't accessible via reflection (that's the bug).

I think I was going to look into a hybrid solution, where I use reflection for the methods and a macro for the fields; that, or create a PR to HXCPP that properly adds the static variables to the reflection table.

@lemz1
Copy link
Contributor Author

lemz1 commented Jan 30, 2025

Do you have a branch of polymod implementing the abstracts. I believe it makes more sense if I try out things, using your implementation.
So I could create a pull request. Or are you already finished?

@charlesisfeline
Copy link

Do you have a branch of polymod implementing the abstracts. I believe it makes more sense if I try out things, using your implementation. So I could create a pull request. Or are you already finished?

yeah its right in the experiment/static-fields branch, ig

@EliteMasterEric
Copy link
Member

EliteMasterEric commented Jan 30, 2025

Do you have a branch of polymod implementing the abstracts. I believe it makes more sense if I try out things, using your implementation. So I could create a pull request. Or are you already finished?

yeah its right in the experiment/static-fields branch, ig

Correct. This branch also has some other experimental changes such as allowing static fields and methods which can be accessed from other modules, as well as other changes to help fix some issues with querying assets in Lime asset libraries.

@lemz1 lemz1 closed this Jan 31, 2025
@AbnormalPoof AbnormalPoof added status: rejected Issue did not pass review or PR cannot be approved. and removed type: enhancement Involves an enhancement or new feature. status: pending triage Awaiting review. topic: mods Related to the creation or use of mods. size: large A large pull request with more than 100 changes. pr: haxe PR modifies game code. labels Jan 31, 2025
@lemz1
Copy link
Contributor Author

lemz1 commented Jan 31, 2025

I've opened a pull request in the polymod repository, which adds support for reading static member variables.

larsiusprime/polymod#189

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: rejected Issue did not pass review or PR cannot be approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants