poga / actix-lua

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

Make vm public #9

Closed voidxnull closed 6 years ago

voidxnull commented 6 years ago

Might be pretty useful. Alternatively, a getter method can be implemented instead.

poga commented 6 years ago

Do you have any use cases that requires direct access to the vm?

actix-lua configure its Lua vm with prelude.lua before loading user scripts. People can easily break it if they have direct access to the vm.

I do see the need of customizing the behavior of actix-lua. Maybe in the form of hooks?

voidxnull commented 6 years ago

I have a use case: to create lua bindings for external libraries (crypto, templates, etc.) Using messages to implement bindings seems unnecessarily clunky and non-reusable. Besides, how badly does one need to screw up to replace prefixed globals?

If you think that it's dangerous to make the vm completely public, there is another way to expose it: add a new method LuaActorBuilder::with_vm which accepts a closure and pass the closure to LuaActor::new in LuaActorBuilder::build that can be used for initializing the vm before executing prelude.lua. That way all operations on the vm will be localized. I personally think this is unnecessary, but the decision is yours.

What do you think?

poga commented 6 years ago

My main concern is that by making it public, it encourages people to do whatever they want to the vm, including all the internal APIs. It makes all the internal Lua implementation public, make it hard to change the internal API without introduce breaking changes to the user.

I like the idea of LuaActorBuilder::with_vm👍! It clearly tells the user that "you should only do this when initializing a new actor".

Can you help me implement it? I can do it but you might have to wait.

voidxnull commented 6 years ago

Ok, I'll do it.

voidxnull commented 6 years ago

Done. I had to change the builder methods to take self by value to make it work.

poga commented 6 years ago

Can you add tests for it?

voidxnull commented 6 years ago

Done.

poga commented 6 years ago

merged. Thanks!

poga commented 6 years ago

v0.3.1 released! 🎉

voidxnull commented 6 years ago

Thank you!