Anonymous user
Runtime evaluation: Difference between revisions
→{{header|AutoHotkey}}: eval
(autohotkey example) |
(→{{header|AutoHotkey}}: eval) |
||
Line 22:
{{works with | AutoHotkey_H}}
function [http://www.autohotkey.net/~HotKeyIt/AutoHotkey/addScript.htm addScript] can be used to dynamically add lines of code to a running script.
<lang AutoHotkey>; requires AutoHotkey_H or AutoHotkey.dll
<lang AutoHotkey>DllCall(A_AhkPath "\addScript","Str","MsgBox hello world","Uchar",1,"Cdecl UInt")▼
msgbox % eval("3 + 4")
msgbox % eval("4 + 4")
return
eval(expression)
{
global script
script =
(
expression(){
return %expression%
}
)
renameFunction("expression", "") ; remove any previous expressions
gosub load ; cannot use addScript inside a function yet
exp := "expression"
return %exp%()
}
load:
▲
return
renameFunction(funcName, newname){
static
x%newname% := newname ; store newname in a static variable so its memory is not freed
strput(newname, &x%newname%, strlen(newname) + 1)
if fnp := FindFunc(funcName)
numput(&x%newname%, fnp+0, 0, "uint")
}</lang>
=={{header|BASIC}}==
|