actix-lua icon indicating copy to clipboard operation
actix-lua copied to clipboard

Access to the vm outside the handler

Open Arnaz87 opened this issue 7 years ago • 2 comments

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.

Arnaz87 avatar Oct 10 '18 17:10 Arnaz87

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 avatar Oct 10 '18 18:10 poga

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.

poga avatar Oct 10 '18 18:10 poga