Activate luapad in current buffer
Closed this issue · 8 comments
Hi there, I've been using luapad for few days now, and I got to say, it saved tone of reloads and print statements. And also it helping understand my code better.
I wonder if its possible to have luapad activated in current buffer/file. I found having to copy things back and forth between luapad buffer and the buffer I'm working on is a bit annoying.
Thanks!!
Hi! I'm glad it comes in handy.
The first versions worked this way, but I found a few potential problems with this approach:
The whole script / plugin can be too big to run for real time evaluation and it might trigger infinite loop prevention mechanism. Also it can be quite dangerous. Imagine that if someone will try experiment with unknown script which makes a lot o file operations on the system, and he's starting to change some variables not knowing that they are used in targeting files to remove.
But if you have ideas on how I can adapt luapad to your flow, I'm open to suggestions. :)
I agree it is dangerous as well as can have a huge performance impact. However, for me personally when developing I always encapsulated my code in functions, perhaps only when testing I would write a statement or two outside the function.
By the way I found LuaPad evaluating some code such as print statements and print it value within function, which can both dangerous and unnecessary.
Perhaps skipping the functions body could a great idea and efficient enough to make toggling live evaluations in current buffer both safe and efficient.
Thus, a command such as LuapadToggleCurrentBuf
with totally skipping functions body will be extremely useful, at least for me.
Thanks
It's more about evaluating only what you know. And you always know everything you had to put there yourself.
By the way I found LuaPad evaluating some code such as print statements and print it value within function, which can both dangerous and unnecessary.
It's for sure not unnecessary, because I use it :)
And why do you think it can be dangerous?
Perhaps skipping the functions body could a great idea and efficient enough to make toggling live evaluations in current buffer both safe and efficient.
I think you may have a wrong idea of how this plugin works internally. It evaluates code in new clean scope with overwritten print function. If I disable parsing function bodies, then luapad will do practically... nothing. There will be no functions to run other than those from the global scope.
You can achieve "not parsing function bodies" by requiring module with those function in luapad. Of course, in this case you will have to remember about reloading them manually when you make any changes to them.
I will consider adding the option to evaluate existing buffers.
Thanks a lot for clarifying the misconceptions I had, perhaps I will rely on requiring and testing my function until this feature is avalanche. Thanks again.
Quick Update:
By the way I found LuaPad evaluating some code such as print statements and print it value within function, which can both dangerous and unnecessary.
I thought I didn't like the fact that print statement, the result of evaluating a function get printed inside the function rather then the under the function call. But wow that is so useful for debugging a function, and trying things out within for example a for loop.
@rafcamlet I'm becoming more and more depended on your amazing plugin thank you!!
The ability to activate luapad in existing buffer has been added in v0.2
❤️ . I know I asked this before but how to stop evaluation in insert mode? and only when I exist insert mode it evaluates?
@rafcamlet thanks for this good plugin.
Should we define hotkey for the these API ? or had better provide cmd for these API.
-- Creates a new luapad instance and attaches it to the current buffer.
-- Optionally, you can pass a context table to it, the elements of which will be
-- available during the evaluation as "global" variables.
require('luapad').attach({
context = { return_4 = function() return 4 end }
})
-- Detaches current luapad instance from buffer, which just means turning it off. :)
require('luapad').detach()
-- Toggles luapad in current buffer.
require('luapad').toggle({
context = { return_4 = function() return 4 end }
})