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

Allowing to add metadata to the Main entry point #4597

Closed
chipshort opened this issue Oct 20, 2015 · 1 comment · Fixed by #11551
Closed

Allowing to add metadata to the Main entry point #4597

chipshort opened this issue Oct 20, 2015 · 1 comment · Fixed by #11551
Assignees
Labels
platform-cs Everything related to c#
Milestone

Comments

@chipshort
Copy link

I experienced this with the C# target, but it might fit for others as well:
I wanted to add [System.STAThread] to the main entry point of my project, but this is not possible, because it is hardcoded into the compiler code. I think it would be better if the compiler could check for an existing "Main" function or to add some other option to change the entry point class.
I had to work around this by writing a script that edits hxcs_build.txt's "main" section to point to the following Haxe class:

class MainHook
{
    @:meta(System.STAThread)
    public static function Main() : Void
    {
        cs.Boot.init();
        untyped CloudShelter.main();
    }
}

and start haxelib run hxcs hxcs_build.txt manually.
I'm sorry if there already is a better way of handling this, I did not find any information about it.

@andyli andyli added the platform-cs Everything related to c# label Oct 20, 2015
@Simn Simn modified the milestone: 3.4 Feb 23, 2016
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Backlog Apr 17, 2018
@judah-caruso
Copy link

I found an alternative to above that's worked for me so far. Even though this thread is ancient, I'm putting this here for others looking for a fix. Also want to reiterate that there's probably a better way to do this.

Adding @:classCode("[System.STAThread]\n") above your main class definition generates the expected code.

@:classCode("[System.STAThread]\n")
class Program {
    // ...
    public static function main() {
        // ...
    }
}

will generate:

[System.STAThread]
public static void Main(){
    global::cs.Boot.init();
    global::Program.main();
}

Note: This is not a very stable alternative as we're banking on the fact that Main() is generated/inserted first. If this changes, this 'fix' would no longer work. However, this gets around having to create a shim entrypoint and build manually with a modified hxcs_build.txt.

@Simn Simn modified the milestones: Backlog, Later Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-cs Everything related to c#
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants