poga / actix-lua Goto Github PK
View Code? Open in Web Editor NEWSafe Lua Scripting Environment for Actix
License: MIT License
Safe Lua Scripting Environment for Actix
License: MIT License
Currently, there areunwrap
everywhere. Some of them are needed. Some of them should be refactored into proper Result
. We should have a cleaner big pictures about errors propagation.
Also need to document about how to deal with lua errors such as syntax error, error()
...etc.
Since we're exposing underlying Lua
with the build_with_vm
builder method. In order to prevent user provides a Lua
vm built by different version of rlua
, I believe we should also export the rlua actix-lua
is using?
SyncArbiter
allows us to put blocking statements to separated threads.
LuaActor
is implemented with AsyncContext
. In order to start an actor with SyncArbiter
, it has to with SyncContext
.
However, SyncContext
does not provides rich APIs from AsyncContext
, therefore it's not really compatible between these two implementation.
Maybe we can provide an alternative implementation such as SyncLuaActor
?
rlua
provide an unsafe method new_with_debug
for loading debug library into lua state.
debug.traceback
is an common requirement for 3rd-party Lua libraries. We can also provide an unsafe new_with_debug
method for LuaActorBuilder
to build a LuaActor
with the debug library.
I want to make a repl, but I'd need access to the internal vm to execute code. I saw pull #9 and it gives access to the vm on initialization, but it doesn't work for a repl.
One possibility would be to somehow make the LuaActor use another's vm, in with_vm
instead of passing a reference of the vm to the function, make the function return a reference of a vm, so that the owner of the actor is also the owner of the vm, I don't know if that's even possible though.
Another would be to create a LuaMessage variant with a function which receives a reference to the vm.
I like the second most but I don't really like either that much.
Would you please make a Lua webserver demo?
rlua
0.16 is released. It has a soundness fix and breaking changes around lua.context()
. We should upgrade to it.
Is your feature request related to a problem? Please describe.
Lua is only one good scripting language. Others, especially native Rust ones would be good to support.
Describe the solution you'd like
Make each language a plugin or feature, perhaps.
Describe alternatives you've considered
Forking actix-lua
to make actix-otherlang
, but that would be very limited and stale.
Additional context
Some good looking languages: Ullage, Molten, Rulox, Tox, and SimpleJIT Demo.
Is it possible with actix-web
to handle / filter any method, rather than only on GET requests?
So far, I've tried this to web.lua
and can match any GET request:
diff --git a/examples/lua-web/web.lua b/examples/lua-web/web.lua
index 6d04f1b..474d037 100644
--- a/examples/lua-web/web.lua
+++ b/examples/lua-web/web.lua
@@ -10,15 +10,12 @@ local ret
print(ctx.msg)
-r:match('GET', '/hello', function (params)
- print("get!!!")
- local html = liluat.render(tmpl, {title="hello world", verb="Hello "})
+local html = liluat.render(tmpl, {title="hello world", verb="Hello "})
- print(html)
+print(html)
- ret = html
-end)
+ret = html
r:execute(ctx.msg.method, '/' .. ctx.msg.path)
but I think this line in main.rs
is too narrow:
.resource("/{path:.*}", |r| r.method(http::Method::GET).with(get))
}).bind("127.0.0.1:8080")
and it looks like App::filter() would allow more flexibility
Is your feature request related to a problem? Please describe.
We're making a framework on top of actix-lua, which has lua bindings for various rust libraries, that's why I need access to the vm from rust before running lua, to set the bindings as globals. We're now starting to actually use the actors functionality and create actors from the lua code, but the child actors don't share globals with the parent actors, and there's where the bindings are.
Describe the solution you'd like
The optimal solution would be just that all actors shared globals, but I guess that's not possible for safety reasons and whatnot. Then the next best solution is to somehow have access to the child actor's vm in rust, as I have already with the main actor, somehow intercept the actor creation process to setup the globals we need.
Describe alternatives you've considered
Pass the libraries as messages. That's ugly IMO and not even possible because of the message types limitation (I don't know why that restriction but that's out of the scope)
Maybe there's another way to pass data to child actors different than messages, or a shared space somewhere (either in lua's or rust's side), or maybe creating a shared space is a better solution than giving access to what I suggested before.
Before 0.4.0
and 0.3.4
, if error()
is called inside the Lua script, it will be consumed silently. Now it will panic with proper stack trace.
It's easiler to debug now. But, sometimes panicking is too destructive. One use-case is a live-reloading environment. We might want to just show the error trace and continue the execution, allows user to have a chance to fix their script without restarting the whole program.
This is mostly about the last part of the invoke
function in actor.rs
. Maybe we should return a Err
instead of just panic!
.
This actix-lua-web framework gist has a more complex example that relies on serde-yaml and tera. Does it make sense?
A helpful addition to the examples would be something like this PHP script to dump full HTTP request to file (method, HTTP headers and body).
When lua calls rust defined functions with wrong argument types it panics the thread, it doesn't propagate the error for lua or rust to handle it, it straight up panics.
It may happen with any error returned by rust code called from lua handler code, but I don't know, I just saw it happen with wrong typed arguments.
Is your feature request related to a problem? Please describe.
Currently, you can't register LuaActor
to System
or Arbiter
since it does not implement SystemService
. In order to implement SystemService
, LuaActor
must impl Default
.
The problem is, how do we implement Default
for LuaActor
? I think the reason actix requires Default
for services is that it need to restart them when crashed?
Describe the solution you'd like
Figure out how to implement Default
for LuaActor
. Then implement SystemService
, ArbiterService
, and Supervised
for it.
Describe alternatives you've considered
Not sure, need to understand more detail on actix's registry.
what use might actix-rt have for actix-lua? (actix-rt docs)
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.