Runtime evaluation: Difference between revisions
Content added Content deleted
(autohotkey example) |
(→{{header|AutoHotkey}}: eval) |
||
Line 22: | Line 22: | ||
{{works with | AutoHotkey_H}} |
{{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. |
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 |
|||
⚫ | |||
msgbox % eval("3 + 4") |
|||
msgbox % eval("4 + 4") |
|||
return |
return |
||
!q::exitapp ; hotkey needed to make script persistent so it doesn't |
|||
eval(expression) |
|||
; exit before eval is executed</lang> |
|||
{ |
|||
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}}== |
=={{header|BASIC}}== |