Skip to content

Commit

Permalink
add Coroutine.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Feb 14, 2024
1 parent 0f2e870 commit 11fbe53
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions include/hx/Coroutine.h
@@ -0,0 +1,52 @@
#pragma once

#include <hxcpp.h>

namespace hx
{
struct Coroutine
{
static Dynamic suspend(Dynamic f, Dynamic cont)
{
struct SuspendCaller final : public hx::Object
{
Dynamic f;
Dynamic cont;

SuspendCaller(Dynamic inF, Dynamic inCont) : f(inF), cont(inCont)
{
HX_OBJ_WB_NEW_MARKED_OBJECT(this);
}

Dynamic HX_LOCAL_RUN()
{
return f(cont);
}

Dynamic __run(const Dynamic&, const Dynamic&) override
{
return HX_LOCAL_RUN();
}

Dynamic __Run(const Array<Dynamic>& args) override
{
return HX_LOCAL_RUN();
}

void __Mark(hx::MarkContext* __inCtx) override
{
HX_MARK_MEMBER(__inCtx);
}

#ifdef HXCPP_VISIT_ALLOCS
void __Visit(hx::VisitContext* __inCtx) override
{
HX_VISIT_MEMBER(__inCtx);
}
#endif
};

return new SuspendCaller(f, cont);
}
};
}
1 change: 1 addition & 0 deletions include/hxcpp.h
Expand Up @@ -383,6 +383,7 @@ typedef bool PropertyAccess;
#else
#include <cpp/Int64.h>
#endif
#include <hx/Coroutine.h>

#endif

0 comments on commit 11fbe53

Please sign in to comment.