Runtime evaluation: Difference between revisions

(autohotkey example)
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
 
 
!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:
<lang AutoHotkey>DllCall(A_AhkPath "\addScript","Str","MsgBox hello world"script,"Uchar",10,"Cdecl UInt")
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}}==
Anonymous user