Skip to first unread message

Christoffer Green

Oct 16, 2019, 6:10:48 AM10/16/19

I have been trying to think of a way to properly integrate scripting inside a CAF system. Let's say Lua via sol3 C++ binding (but could be any scripting engine really).

I imagine a system here you have an actor that can receive a message to launch a script. The script in turn runs inside this actor meaning that if you bind methods to send messages via the script actor then CAF will have problems processing those messages since the actor is stuck processing a single event (LaunchScriptAtom). This leads to a situation where the script waits for a message that never arrives:

Launch script actor->script actor runs script->script calls c++ method->method sends message, waits for reply.

What would be a good way to design this so that an actor can run a script that can in turn participate in message sending? I can imagine it working by simply using blocking calls everywhere (make_function_view or so) but I am more interested in having messages be asynchronous.

I am imagining a script that can do something like this:
textFileFuture = async_load_text_file("/foo.txt") -- textFileFuture is a std::future<std::string>
-- do other stuff
textFile = textFileFuture.get() -- textFile is an std::string

Thank you

Dominik Charousset

Oct 21, 2019, 2:17:55 AM10/21/19
> “

I don’t know how well Lusa/sol3 supports concurrency, but many script interpreters are not safe to call from multiple threads. In any case, I think the primary question is what your use case for the scripting engine is. Building an API around futures and callbacks seems straightforward enough: have one detached actor with the scripting engine and trigger callbacks from messages it receives. Exposing CAF to the scripting layer is more challenging, especially if you want to allow users to spawn new actor from script land.

FWIW, our repository contains a very bare-bone example for integrating with Python [1]. Maybe this gives you a couple new ideas.

Hope that helps,

Reply all
Reply to author
0 new messages