• This repository has been archived on 10/Mar/2023
  • Stars
    star
    124
  • Rank 286,722 (Top 6 %)
  • Language
    Rust
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Safe Lua Scripting Environment for Actix

actix-lua

Build Status Latest Version API Documentation

A safe scripting environment for actix with the Lua Programming Language:

  • Each LuaActor is an isolated Lua VM.
  • Communicate between actors with predefined message types: String, Integer, Number, Boolean, Nil, and Table.
  • Asynchronous send between actors with Lua coroutine.

For more info about the "safety", check rlua's README.

Synopsis

A 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 ctx.send

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();

Install

Add actix-lua to your Cargo.toml:

[dependencies]
actix-lua = "0.7"

Example

Check examples directory.

There's also a write-up about analyzing streaming data with actix-lua. link

Lua Actor

Use LuaActor to integrate Lua scripts to your system with actor model.

Message

In actor model, actors communicate with messages. LuaMessage is the only message type accepted by LuaActor:

  • LuaMessage can be converted to/from primitive types with LuaMessage::from().
  • Lua types(e.g. number, table) will be convert to LuaMessage automatically.

Lua API

Note: Avoid declaring global variables in your Lua script. It might conflict with future actix-lua update and break your program.

ctx.msg

The message sent to Lua actor.

ctx.notify(msg)

Send message msg to self.

ctx.notify_later(msg, seconds)

Send message msg to self after specified period of time.

local result = ctx.send(recipient, msg)

Send message msg to `recipient asynchronously and wait for response.

Equivalent to actix::Recipient.send.

ctx.do_send(recipient, msg)

Send message msg to recipient.

Equivalent to actix::Recipient.do_send.

ctx.terminate()

Terminate actor execution.

License

The MIT License

More Repositories

1

awesome-federated-learning

resources about federated learning and privacy in machine learning
508
star
2

hyperidentity

๐ŸŒ ๐Ÿ†” Decentralized Identity
JavaScript
74
star
3

hyperfeed

decentralized rss publishing
JavaScript
68
star
4

spacer

๐Ÿš€Serverless function platform for Lua
Lua
50
star
5

redis-rating

A Redis module that helps you calculate the real rating from positive/negative rating feedback.
Rust
19
star
6

rss2mastodon

publish a rss feed to mastodon
JavaScript
17
star
7

redis-percentile

redis module for percentile estimation
Rust
16
star
8

wave_box

Redis-based messaging system
Ruby
14
star
9

yahnc

Yet Another Hacker News Clone with PgBase
JavaScript
13
star
10

hyperdrive-ln

create symbolic link between hyperdrives
JavaScript
13
star
11

sitex

http server with support to Netlify's `_redirect` and `_headers`
Go
12
star
12

KubeScript

web app framework for kubernetes
JavaScript
11
star
13

merkle-generator

generate a merkle tree based on incoming data
Rust
10
star
14

ListRGB

Collaboration with Color
CSS
9
star
15

vscode-hybrid-operator

VSCode theme for the Operator Mono font
8
star
16

netlify-json-api

RESTful JSON API on Netlify
Go
8
star
17

GiderosMicBlow

A simple plugin to detect mic blow on gideros mobile iphone player
Java
8
star
18

godot-dash-docset

Dash docset generator for Godot's API
HTML
7
star
19

vis-chip-8

Visual Chip-8 Emulator
Haxe
7
star
20

jupytermodule

Import jupyter notebooks as python modules
Python
7
star
21

streaming-data-parsing-with-actix-lua

Lua
6
star
22

hyperspark

Decentralized data processing platform
JavaScript
6
star
23

hyperkafka

interplanetary messaging platform
JavaScript
5
star
24

mooontag

Badge generator based on moon's work
CSS
5
star
25

withdat

a collection of dat/hyperdrive usages
4
star
26

dotfiles

dotfiles
Shell
4
star
27

darepad

checklist/walkthrough/tutorial generator with personal progress tracking
LiveScript
4
star
28

lua53-notes

Makefile
4
star
29

object-feed

live-updating distributed javascript object
JavaScript
3
star
30

dat-transform

Lazily-evaluated transformation on Dat archives.
JavaScript
3
star
31

bcdis

Blockchain-based Dictionary Server - a.k.a. Redis on Blockchain.
Go
3
star
32

dat-ipynb-demo

use ipython notebook to analyze data in dat archive
Jupyter Notebook
2
star
33

cranelift-example

Basic examples for Cranelift, a code generator
Rust
2
star
34

hyperdrive-timeseries

timeseries data in hyperdrive
JavaScript
2
star
35

requirejs-livescript-boilerplate

RequireJS + LiveScript + require-ls boilerplate
JavaScript
2
star
36

encrypted-message

send encrypted message between two ed25519 key pair
JavaScript
1
star
37

rats

javascript encoder/decoder for RATS
JavaScript
1
star
38

dat-get

wget for dat
JavaScript
1
star
39

moe-dict-cat-crawler

moe-dict-cat-crawler
Ruby
1
star
40

hackmd-editarea-maxwidth

HTML
1
star
41

markdown-attachment-p2p

add attachment to markdown and share across network
JavaScript
1
star
42

feed-hyperify

a crawler to convert RSS/ATOM feed to hyperfeed
JavaScript
1
star
43

ipynb2md

jupyter notebook(ipynb) to markdown
Jupyter Notebook
1
star
44

aoc2020

JavaScript
1
star
45

spgateway-js

ๆ™บไป˜้€šไฟก็”จๅก API
JavaScript
1
star
46

stdchat

fb messenger to unix universal interface(text stream)
Go
1
star
47

pgrest-schemaless

a schemaless database with firebase API on PgREST
JavaScript
1
star
48

hoehoekuma

JavaScript
1
star
49

godot-tween-test

GAP
1
star
50

typoify.js

create typos in your text
JavaScript
1
star
51

hyperfeed-server

Serve a RSS/ATOM feed as a Hyperfeed
JavaScript
1
star
52

rainbow-template

Tumblr-like template engine
Ruby
1
star
53

hyperdrive-read

fs.read for hyperdrive
JavaScript
1
star