Is it possible to use Eval() to create a function? Say I want to make a way of live-patching an app, by bringing down some code via http and then running it with Eval(). Can I actually create a new function (or overwrite an existing one) using Eval(), as I could in say javascript as below?
This seems to always print “not hello” on the console. Am I not calling eval correctly? I do see in the in the listing that it is showing the “goto hello” as the last command before the stop.
If you look at the result of the Eval, you’ll see:
ERRSTR: "Label/Line Not Found."
FILESPEC: "$LIVECOMPILE"
ERRNO: 14
LINENO: 0
My guess would be that labels are interpreted during the compile, so they’re not available at runtime, when the Eval is being executed. You get the same error if you type “goto Hello” at the debug command prompt.
Apologies for taking a few months to reply and thank you. I finally got back to this little project, and your response was very helpful.
Now a followup question, if you don’t mind:
Can I use this technique to replace a global (non-anonymous) function declared as
Function testFunc()
Return 100
End Function
as opposed to:
testFunc = Function()
Return 100
End Function
Again, this is for a development/debugging tool where I can live-patch code. Since most of this code is, unfortunately, not written by me and is not object oriented, most of the functions are declared as in the first example.
I just tried testing this, and it doesn’t appear to work. It doesn’t generate an error, but it also doesn’t replace the function. So, it looks like you can only replace functions assigned to variables.
Not able to test this at the moment, but wouldn’t the m global variable contain the function no matter how it was defined?
Also, since you mention that this is a dev/debug tool you probably know this, but for anyone else: be extremely careful when doing something like this. For the most part, running outside code is a bad idea.