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

Async plugins #2071

Open
NiLSPACE opened this issue May 19, 2015 · 2 comments
Open

Async plugins #2071

NiLSPACE opened this issue May 19, 2015 · 2 comments

Comments

@NiLSPACE
Copy link
Member

NiLSPACE commented May 19, 2015

We discussed this in the forum as well: http://forum.mc-server.org/showthread.php?tid=1830

The plugins could have a big advantage if they could create threads preferably in the same Lua state.

An example where this could be used: In WorldEdit you could read an large area, and do something in a different thread in that area. Afterwards the area could be written back into the world.

The usage could look like this:

-- CreateSphere is a function that creates a sphere in a cBlockArea
-- BA is a blockarea that was read in before
-- DstBlock is the block to make the sphere out of.

local EditSes = cThread(CreateSphere)
EditSes:SetOnFinish(
  function(... --[[ All the values returned]] )
     --[[ Write the (possibly returned) blockarea back in the world, and send a message to the player ]] 
  end
)
EditSes:Start(BA, DstBlock)
@NiLSPACE
Copy link
Member Author

Wouldn't it be possible to add this by creating a new class that overrides cIsThread?
It could look like this:

class cLuaThread : public cIsThread
{
public:
    cLuaThread(cLuaState S) 
        : super(AString("Lua" + static_cast<char>(g_NumLuaThreads++))),
        m_LuaState(S)
    {
        m_Function.RefStack(m_LuaState, 1);
    }

    typedef cIsThread super;
    cLuaState::cRef m_Function;
    cLuaState m_LuaState;

protected:
    virtual void Execute(void) override
    {
        m_LuaState.Call(m_Function);
    }
};

@worktycho
Copy link
Member

Where are you planning on getting the luaState from? That's the actual problem, because we can't use the plugins existing LuaState as it is not thread safe.

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

No branches or pull requests

2 participants