Skip to content

Instantly share code, notes, and snippets.

@andyli
Created June 13, 2010 08:50
Show Gist options
  • Save andyli/436483 to your computer and use it in GitHub Desktop.
Save andyli/436483 to your computer and use it in GitHub Desktop.
To illustrate a hxcpp bug.
#include <hxcpp.h>
#ifndef INCLUDED_A
#include <A.h>
#endif
#ifndef INCLUDED_Main
#include <Main.h>
#endif
#ifndef INCLUDED_haxe_Log
#include <haxe/Log.h>
#endif
Void Main_obj::__construct()
{
return null();
}
Main_obj::~Main_obj() { }
Dynamic Main_obj::__CreateEmpty() { return new Main_obj; }
hx::ObjectPtr< Main_obj > Main_obj::__new()
{ hx::ObjectPtr< Main_obj > result = new Main_obj();
result->__construct();
return result;}
Dynamic Main_obj::__Create(hx::DynamicArray inArgs)
{ hx::ObjectPtr< Main_obj > result = new Main_obj();
result->__construct();
return result;}
Void Main_obj::main( ){
{
__SAFE_POINT
HX_BEGIN_LOCAL_FUNC0(_Function_1_1)
Void run(){
{
__SAFE_POINT
struct _Function_2_1{
inline static Dynamic Block( ){
hx::Anon __result = hx::Anon_obj::Create();
__result->Add(HX_STRING(L"fileName",8) , HX_STRING(L"Main.hx",7));
__result->Add(HX_STRING(L"lineNumber",10) , 11);
__result->Add(HX_STRING(L"className",9) , HX_STRING(L"Main",4));
__result->Add(HX_STRING(L"methodName",10) , HX_STRING(L"main",4));
return __result;
}
};
::haxe::Log_obj::trace(HX_STRING(L"f2",2),_Function_2_1::Block());
}
return null();
}
HX_END_LOCAL_FUNC0((void))
HX_BEGIN_LOCAL_FUNC0(_Function_1_2)
Void run(){
{
__SAFE_POINT
struct _Function_2_1{
inline static Dynamic Block( ){
hx::Anon __result = hx::Anon_obj::Create();
__result->Add(HX_STRING(L"fileName",8) , HX_STRING(L"Main.hx",7));
__result->Add(HX_STRING(L"lineNumber",10) , 10);
__result->Add(HX_STRING(L"className",9) , HX_STRING(L"Main",4));
__result->Add(HX_STRING(L"methodName",10) , HX_STRING(L"main",4));
return __result;
}
};
::haxe::Log_obj::trace(HX_STRING(L"f1",2),_Function_2_1::Block());
}
return null();
}
HX_END_LOCAL_FUNC0((void))
::A_obj::__new()->callFunction( Dynamic(new _Function_1_1()))->callFunction( Dynamic(new _Function_1_2()));
}
return null();
}
STATIC_HX_DEFINE_DYNAMIC_FUNC0(Main_obj,main,(void))
Main_obj::Main_obj()
{
}
void Main_obj::__Mark()
{
}
Dynamic Main_obj::__Field(const ::String &inName)
{
switch(inName.length) {
case 4:
if (!memcmp(inName.__s,L"main",sizeof(wchar_t)*4) ) { return main_dyn(); }
}
return super::__Field(inName);
}
Dynamic Main_obj::__SetField(const ::String &inName,const Dynamic &inValue)
{
return super::__SetField(inName,inValue);
}
void Main_obj::__GetFields(Array< ::String> &outFields)
{
super::__GetFields(outFields);
};
static ::String sStaticFields[] = {
HX_STRING(L"main",4),
String(null()) };
static ::String sMemberFields[] = {
String(null()) };
static void sMarkStatics() {
};
Class Main_obj::__mClass;
void Main_obj::__register()
{
Static(__mClass) = hx::RegisterClass(HX_STRING(L"Main",4), hx::TCanCast< Main_obj> ,sStaticFields,sMemberFields,
&__CreateEmpty, &__Create,
&super::__SGetClass(), 0, sMarkStatics);
}
void Main_obj::__boot()
{
}
class A {
public function new() {}
public function callFunction(func:Void->Void):A { func(); return this; }
}
class Main{
static function main() {
new A()
.callFunction(function(){trace("f1");})
.callFunction(function(){trace("f2");});
}
}
@andyli
Copy link
Author

andyli commented Aug 4, 2010

The following code will produce correct output, tested on windows with msvc 2005:

class A {
    public function new() {}
    public function callFunction(func:Void->Void):A { func(); return this; }
}

class Main{

    static function main() {
        var f1 = function() { trace("f1"); };
        var f2 = function() { trace("f2"); };
        new A()
            .callFunction(f1)
            .callFunction(f2);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment