poga / actix-lua

Safe Lua Scripting Environment for Actix
MIT License
121 stars 13 forks source link

Access to the vm outside the handler #16

Open Arnaz87 opened 5 years ago

Arnaz87 commented 5 years ago

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.

poga commented 5 years ago

Have you tried https://github.com/hoelzro/lua-repl? It requires debug lib, so you need to create a Lua VM with rlua::Lua::new_with_debug, which is unsafe.

I'm not sure if you can make a repl without debug. nvm, you can

poga commented 5 years ago

Or you can have a simple REPL with something like this:

print("input>")
local exp = io.read()
local ret = assert(load("return " .. exp))()
if ret then
     print("ret " .. ret)
end

Making a REPL from the Rust side will be... complicated. I think.