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

[cpp] extern class with default args generates null args #3955

Open
james4k opened this issue Mar 3, 2015 · 2 comments
Open

[cpp] extern class with default args generates null args #3955

james4k opened this issue Mar 3, 2015 · 2 comments
Assignees
Labels
platform-cpp Everything related to CPP / C++
Milestone

Comments

@james4k
Copy link
Contributor

james4k commented Mar 3, 2015

Extern classes with default args seem to generate null() for unspecified args in the generated C++.

As an example, for the function signature

public function func(a:Int, b:Int = 1, c:cpp.Float32 = 1.0):Void;

and a function call

e.func(10);

Haxe will generate the C++ of

e->func((int)10,null(),null());

Full example, though the actual C++ will not build:

package;

extern class ExternClass {

    public function func(a:Int, b:Int = 1, c:cpp.Float32 = 1.0):Void;

}

class Main {

    public static function main() {
    }

    public function test(e:ExternClass):Void {

        e.func(10);

    }

}
@james4k james4k changed the title [cpp] extern class with default args always generates null args [cpp] extern class with default args generates null args Mar 3, 2015
@Simn Simn modified the milestone: 3.3 Mar 24, 2015
@Simn Simn modified the milestones: 3.3.0-rc1, 3.4 Feb 23, 2016
@Simn Simn added the platform-cpp Everything related to CPP / C++ label Apr 4, 2016
@hughsando
Copy link
Member

So I think overload is probably the best way to do this, because it will respect the c++ defaults given in the header file (plus it works now)

@:structAccess
extern class ExternClass {

    @:native("ExternClass()")
    public static var init:ExternClass;

    @:overload(function(a:Int):Void{})
    @:overload(function(a:Int,b:Int):Void{})
    public function func(a:Int, b:Int, c:cpp.Float32):Void;

}


@:cppFileCode("
struct ExternClass {
   void func(int a, int b = 12, float c = 15.0)
   {
      printf("FUNC %d %d %f\\n",a,b,c);
   }
};
")
class Test {

    public static function main() {
       var e:ExternClass = ExternClass.init;
        e.func(10);
    }
}

Otherwise, I think the information might be gone before it gets to hxcpp

@james4k
Copy link
Contributor Author

james4k commented Apr 8, 2016

Thanks, this will work well enough for my case.

If a fix for this is planned for later, perhaps the Haxe compiler should throw an error here in the meantime.

james4k added a commit to james4k/lime that referenced this issue Apr 8, 2016
Finally made ConsoleRenderContext an extern class, thanks to a workaround to
default args not working. @:overload is used in combination with the actual
default args specified in the C++ headers.

See HaxeFoundation/haxe#3955.
james4k added a commit to openfl/lime that referenced this issue Apr 20, 2016
Finally made ConsoleRenderContext an extern class, thanks to a workaround to
default args not working. @:overload is used in combination with the actual
default args specified in the C++ headers.

See HaxeFoundation/haxe#3955.
@Simn Simn modified the milestones: 3.4, 4.0 Jan 9, 2017
@Simn Simn modified the milestones: Release 4.0, Design Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-cpp Everything related to CPP / C++
Projects
None yet
Development

No branches or pull requests

3 participants