veethree is indeed correct, it does loadstring. At first it sets up an environment for the console to use, and adds in all the elements from _G, such that it works like any other script. Then in the main script I put in all the stuff I want it to have extra, variables and such. And I use this separate environment because all my stuff is local, which doesn't translate over to different environments (unlike globals). On top of that, whatever global variables you define (x = 2 for example) will still work on the preceding calls as well. Then it's just a matter of opening the console, registering what you type (which you can do with love.textinput), and running whatever.
Really the only difficult part I suppose would be:
Code: Select all
local func, err = loadstring(code) if func then local success, result = coroutine.resume(coroutine.create(func)) if success then -- everything worked just fine, and if the thingy returned anything, it's 'result' -- (it can also return several values, at which point you need to pack it in a table and such) else -- runtime error, the error is 'result' end else -- compile error, the error is 'err' end
Take note that I never got around to rewriting it. So it's really just a prototype. But it does what I needed it to do, and very easy to use. Just call those functions through their respective love functions, and you're pretty much good to go.