Comments (12)
Why you need to share globals between actors? Actor is suppose to be an encapsulation. I think it's a big misuse of actor model if you need to share states between multiple actors.
In actix-lua
, every actor is an isolated Lua VM. It's intentionally designed as it is.
Communicate by passing messages is one of the fundamental characteristic of Actor model. You need to rethink your architecture if it becomes an obstacle.
from actix-lua.
Also, this issue looks like a XY problem. What's the problem you're actually trying to solve?
from actix-lua.
I already explained what i'm trying to achieve in the first paragraph, it's a lua framework, I don't need to share state, just the framework libraries. The easiest way is to share globals, but I mentioned some alternative solutions, and by explaining specifically what i'm trying to achieve maybe you can help me with it.
from actix-lua.
IMO Sharing libraries is essentially sharing states.
The first paragraph is exactly why I think it's a XY problem. If all you want is to share context with a Lua script, you can create a sandbox with Lua loadfile
and setup an ENV
for the loaded chunk. Or even simpler you can just require the script and it automatically share the same scope.
What's the goal you want to achieve via creating a new LuaActor
at runtime?
from actix-lua.
The framework is not intended for rust users but for lua users, and I want lua users to be able to create actors, which they can with ctx.new_actor
, but that actor doesn't share the libraries of the main actor. The libraries are written in rust, so a lua script to setup the environment doesn't cut it. I need either access to the child actor's vm from rust, or a way to pass libraries from the first actor to the second, and the libraries are composed of lua and rust functions, which cannot pass through messages because it panics with not yet implemented
from actix-lua.
That's the kind of libraries I need access to from lua, that can't be set up by a lua script because the implementation of the functions is rust code. I need to either run this code again on each child actor, or have those functions shared between actors somehow.
This is how I setup the environment for the first actor, this is create_vm, some of it can be lua but most of it can't.
from actix-lua.
Another possible solution could be to complete the message variants, to make it possible to pass functions, user types, and everything else, so that we can pass the bindings from the main actor to the children. How good of a solution is it compared to "access to the children vm", and how feasible is it?
from actix-lua.
I understand that you don't like sharing state and that it's missing the point of the actors, I suggested it at the beginning but that's not what I need, it was a possible mechanism to solve my problem which you reject it and I get it.
In my project there is some stuff I do to a lua environment that can't be done in lua itself, with the with_vm
function in the builder I can do that kind of stuff in the main actor, but it's a big limitation if the child actors cannot be modified the same way, for example what if some lua code needs the lua debug library? just a script setup.lua
doesn't allow one to deliver it, it can only be done from rust.
My current idea is, instead of giving to the builder a single custom vm, give it a callback function that actix-lua will invoke to get a vm machine for each actor it creates. That ensures each actor is on its own different environment and, while it allows users to have shared state, they have to go out of their way to do that because rust has strong requirements to let a user do that, and it's a big benefit for the cost of giving some responsibility to the user, which again, users are expected to by default let actix-lua create on it's own the vms, overriding that behaviour is doing it the hard way.
from actix-lua.
Instead of
LuaActorBuilder::new().build_with_vm(Lua::new())
do
LuaActorBuilder::new().build_with_vm_callback(|| { Lua::new() })
from actix-lua.
This is the callback I intend to give to actix-lua (needs a bit of cleanup and move the lua execution to on_started)
from actix-lua.
actix-lua
and actix
are not designed to spawn short-lived actors at runtime. (see actix/actix#77). Therefore, ctx.new_actor
is a badly designed API (since it encourage people to spawn random actors at runtime). It's going to be removed in the near future.
On the other hand, actix-lua
is low-level. Instead of expose it to the users directly, you should wrap it with a domain-specified interface for your user.
from actix-lua.
To avoid further confusion, ctx.new_actor
is removed by 06003ae.
from actix-lua.
Related Issues (18)
- Allow registering LuaActor to actix register HOT 3
- Use `LuaActor` with `SyncArbiter`
- Access to the vm outside the handler HOT 2
- Option to not panic when `error()` is called in Lua script HOT 8
- Add unsafe `new_with_debug` method to LuaActorBuilder HOT 6
- Actix web demo HOT 3
- re-export `rlua`
- Typed functions panic on wrong argument types HOT 19
- Upgrade to rlua 0.16 HOT 2
- Add support for more scripting languages HOT 6
- Actix Runtime relevance HOT 2
- LuaJIT HOT 1
- better error handling HOT 2
- actix-lua-web framework HOT 5
- Please add a Gitter chatroom HOT 1
- lua-web: match any request method HOT 1
- Debug example HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from actix-lua.