在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):poga/actix-lua开源软件地址(OpenSource Url):https://github.com/poga/actix-lua开源编程语言(OpenSource Language):Rust 95.6%开源软件介绍(OpenSource Introduction):actix-luaA safe scripting environment for actix with the Lua Programming Language:
For more info about the "safety", check rlua's README. SynopsisA basic Lua actor extern crate actix_lua;
use actix_lua::{LuaActorBuilder, LuaMessage};
fn main () {
let addr = LuaActorBuilder::new()
.on_handle_with_lua(r#"return ctx.msg + 42"#)
.build()
.unwrap()
.start();
let res = addr.send(LuaMessage:from(100));
// return: 142
} You can send messages to other actor asynchronously with struct Callback;
impl Actor for Callback {
type Context = Context<Self>;
}
impl Handler<LuaMessage> for Callback {
type Result = LuaMessage;
fn handle(&mut self, msg: LuaMessage, _ctx: &mut Context<Self>) -> Self::Result {
LuaMessage::String("hello".to_string())
}
}
let mut actor = LuaActorBuilder::new()
// create a new LuaActor from a lua script when the actor is started.
// send message to the newly created actor with `ctx.send`, block and wait for its response.
.on_started_with_lua(
r#"
local result = ctx.send("callback, "Hello")
print(result) -- print "hello"
"#).build()
.unwrap();
actor.add_recipients("callback", Callback.start().recipient());
actor.start(); InstallAdd [dependencies]
actix-lua = "0.7" ExampleCheck examples directory. There's also a write-up about analyzing streaming data with actix-lua. link Lua ActorUse MessageIn actor model, actors communicate with messages.
Lua APINote: Avoid declaring global variables in your Lua script. It might conflict with future
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论