<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Выполнение записанных математических операций]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=13022</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=13022&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Выполнение записанных математических операций».]]></description>
		<lastBuildDate>Sat, 23 Sep 2017 17:24:05 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119528#p119528</link>
			<description><![CDATA[<div class="quotebox"><cite>serzh82saratov пишет:</cite><blockquote><p>А если A_AhkPath нет?</p></blockquote></div><p>Тогда не выйдет. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 23 Sep 2017 17:24:05 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119528#p119528</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119525#p119525</link>
			<description><![CDATA[<p>О как, а мне почему-то казалось, что в строке может содержаться ahk специфичный код.</p>]]></description>
			<author><![CDATA[null@example.com (stealzy)]]></author>
			<pubDate>Sat, 23 Sep 2017 14:41:25 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119525#p119525</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119524#p119524</link>
			<description><![CDATA[<p>А если A_AhkPath нет?</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sat, 23 Sep 2017 14:35:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119524#p119524</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119520#p119520</link>
			<description><![CDATA[<p>Выражения в строке проще всего считать через WScript.Shell:<br /></p><div class="codebox"><pre><code>MsgBox, % CalculateExpr(&quot;5 + 5&quot;)

CalculateExpr(expr)  {
   shell := ComObjCreate(&quot;WScript.Shell&quot;)
   exec := shell.Exec(A_AhkPath . &quot; /ErrorStdOut *&quot;)
   exec.StdIn.Write(&quot;#NoTrayIcon`nFileAppend % (&quot; expr &quot;), *&quot;)
   exec.StdIn.Close()
   return exec.StdOut.ReadAll()
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 23 Sep 2017 12:26:54 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119520#p119520</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119518#p119518</link>
			<description><![CDATA[<p>Вообще да, исполнять однотипный код из строки не имеет смысла. А если код сильно разный, то стандартными средствами не получится.</p>]]></description>
			<author><![CDATA[null@example.com (ypppu)]]></author>
			<pubDate>Sat, 23 Sep 2017 11:42:49 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119518#p119518</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119517#p119517</link>
			<description><![CDATA[<div class="quotebox"><cite>ypppu пишет:</cite><blockquote><p>Здесь каким-то чудом делим передыдущую строку кода на две части.</p></blockquote></div><p>Чудо не в делении строки, а в выполнении строки как кода.<br />&quot;a*b*2-5&quot; мы получим как строку, и коду:<br /></p><div class="codebox"><pre><code>cod := a*b*2-5</code></pre></div><p>взятся будет просто неоткуда.</p>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sat, 23 Sep 2017 11:08:31 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119517#p119517</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119516#p119516</link>
			<description><![CDATA[<div class="codebox"><pre><code>
JS := new ActiveScript(&quot;JScript&quot;)

a := 3
b := 7
str := &quot;x:=a*b*2-5&quot;

RegExMatch(str, &quot;\s*(.*?)\s*:=(.*)&quot;, s), pos := 1, exp := s2
While pos := RegExMatch(s2, &quot;(\w+)&quot;, p, pos), pos += StrLen(p) 
	(p1 + 0 = &quot;&quot;) &amp;&amp; exp := StrReplace(exp, p1, %p1%, , 1) 
try %s1% := JS.eval(exp)

MsgBox % x
Return



/*
 *  ActiveScript for AutoHotkey v1.1
 *
 *  Provides an interface to Active Scripting languages like VBScript and JScript,
 *  without relying on Microsoft&#039;s ScriptControl, which is not available to 64-bit
 *  programs.
 *
 *  License: Use, modify and redistribute without limitation, but at your own risk.
 */
class ActiveScript extends ActiveScript._base
{
    __New(Language)
    {
        if this._script := ComObjCreate(Language, ActiveScript.IID)
            this._scriptParse := ComObjQuery(this._script, ActiveScript.IID_Parse)
        if !this._scriptParse
            throw Exception(&quot;Invalid language&quot;, -1, Language)
        this._site := new ActiveScriptSite(this)
        this._SetScriptSite(this._site.ptr)
        this._InitNew()
        this._objects := {}
        this.Error := &quot;&quot;
        this._dsp := this._GetScriptDispatch()  ; Must be done last.
        try
            if this.ScriptEngine() = &quot;JScript&quot;
                this.SetJScript58()
    }

    SetJScript58()
    {
        static IID_IActiveScriptProperty := &quot;{4954E0D0-FBC7-11D1-8410-006008C3FBFC}&quot;
        if !prop := ComObjQuery(this._script, IID_IActiveScriptProperty)
            return false
        VarSetCapacity(var, 24, 0), NumPut(2, NumPut(3, var, &quot;short&quot;) + 6)
        hr := DllCall(NumGet(NumGet(prop+0)+4*A_PtrSize), &quot;ptr&quot;, prop, &quot;uint&quot;, 0x4000
            , &quot;ptr&quot;, 0, &quot;ptr&quot;, &amp;var), ObjRelease(prop)
        return hr &gt;= 0
    }
    
    Eval(Code)
    {
        pvar := NumGet(ComObjValue(arr:=ComObjArray(0xC,1)) + 8+A_PtrSize)
        this._ParseScriptText(Code, 0x20, pvar)  ; SCRIPTTEXT_ISEXPRESSION := 0x20
        return arr[0]
    }
    
    Exec(Code)
    {
        this._ParseScriptText(Code, 0x42, 0)  ; SCRIPTTEXT_ISVISIBLE := 2, SCRIPTTEXT_ISPERSISTENT := 0x40
        this._SetScriptState(2)  ; SCRIPTSTATE_CONNECTED := 2
    }
    
    AddObject(Name, DispObj, AddMembers := false)
    {
        static a, supports_dispatch ; Test for built-in IDispatch support.
            := a := ((a:=ComObjArray(0xC,1))[0]:=[42]) &amp;&amp; a[0][1]=42
        if IsObject(DispObj) &amp;&amp; !(supports_dispatch || ComObjType(DispObj))
            throw Exception(&quot;Adding a non-COM object requires AutoHotkey v1.1.17+&quot;, -1)
        this._objects[Name] := DispObj
        this._AddNamedItem(Name, AddMembers ? 8 : 2)  ; SCRIPTITEM_ISVISIBLE := 2, SCRIPTITEM_GLOBALMEMBERS := 8
    }
    
    _GetObjectUnk(Name)
    {
        return !IsObject(dsp := this._objects[Name]) ? dsp  ; Pointer
            : ComObjValue(dsp) ? ComObjValue(dsp)  ; ComObject
            : &amp;dsp  ; AutoHotkey object
    }
    
    class _base
    {
        __Call(Method, Params*)
        {
            if ObjHasKey(this, &quot;_dsp&quot;)
                try
                    return (this._dsp)[Method](Params*)
                catch e
                    throw Exception(e.Message, -1, e.Extra)
        }
        
        __Get(Property, Params*)
        {
            if ObjHasKey(this, &quot;_dsp&quot;)
                try
                    return (this._dsp)[Property, Params*]
                catch e
                    throw Exception(e.Message, -1, e.Extra)
        }
        
        __Set(Property, Params*)
        {
            if ObjHasKey(this, &quot;_dsp&quot;)
            {
                Value := Params.Pop()
                try
                    return (this._dsp)[Property, Params*] := Value
                catch e
                    throw Exception(e.Message, -1, e.Extra)
            }
        }
    }
    
    _SetScriptSite(Site)
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+3*A_PtrSize), &quot;ptr&quot;, p, &quot;ptr&quot;, Site)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::SetScriptSite&quot;)
    }
    
    _SetScriptState(State)
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+5*A_PtrSize), &quot;ptr&quot;, p, &quot;int&quot;, State)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::SetScriptState&quot;)
    }
    
    _AddNamedItem(Name, Flags)
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+8*A_PtrSize), &quot;ptr&quot;, p, &quot;wstr&quot;, Name, &quot;uint&quot;, Flags)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::AddNamedItem&quot;)
    }
    
    _GetScriptDispatch()
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+10*A_PtrSize), &quot;ptr&quot;, p, &quot;ptr&quot;, 0, &quot;ptr*&quot;, pdsp)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::GetScriptDispatch&quot;)
        return ComObject(9, pdsp, 1)
    }
    
    _InitNew()
    {
        hr := DllCall(NumGet(NumGet((p:=this._scriptParse)+0)+3*A_PtrSize), &quot;ptr&quot;, p)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScriptParse::InitNew&quot;)
    }
    
    _ParseScriptText(Code, Flags, pvarResult)
    {
        VarSetCapacity(excp, 8 * A_PtrSize, 0)
        hr := DllCall(NumGet(NumGet((p:=this._scriptParse)+0)+5*A_PtrSize), &quot;ptr&quot;, p
            , &quot;wstr&quot;, Code, &quot;ptr&quot;, 0, &quot;ptr&quot;, 0, &quot;ptr&quot;, 0, &quot;uptr&quot;, 0, &quot;uint&quot;, 1
            , &quot;uint&quot;, Flags, &quot;ptr&quot;, pvarResult, &quot;ptr&quot;, 0)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScriptParse::ParseScriptText&quot;)
    }
    
    _HRFail(hr, what)
    {
        if e := this.Error
        {
            this.Error := &quot;&quot;
            throw Exception(&quot;`nError code:`t&quot; this._HRFormat(e.HRESULT)
                . &quot;`nSource:`t`t&quot; e.Source &quot;`nDescription:`t&quot; e.Description
                . &quot;`nLine:`t`t&quot; e.Line &quot;`nColumn:`t`t&quot; e.Column
                . &quot;`nLine text:`t`t&quot; e.LineText, -3)
        }
        throw Exception(what &quot; failed with code &quot; this._HRFormat(hr), -2)
    }
    
    _HRFormat(hr)
    {
        return Format(&quot;0x{1:X}&quot;, hr &amp; 0xFFFFFFFF)
    }
    
    _OnScriptError(err) ; IActiveScriptError err
    {
        VarSetCapacity(excp, 8 * A_PtrSize, 0)
        DllCall(NumGet(NumGet(err+0)+3*A_PtrSize), &quot;ptr&quot;, err, &quot;ptr&quot;, &amp;excp) ; GetExceptionInfo
        DllCall(NumGet(NumGet(err+0)+4*A_PtrSize), &quot;ptr&quot;, err, &quot;uint*&quot;, srcctx, &quot;uint*&quot;, srcline, &quot;int*&quot;, srccol) ; GetSourcePosition
        DllCall(NumGet(NumGet(err+0)+5*A_PtrSize), &quot;ptr&quot;, err, &quot;ptr*&quot;, pbstrcode) ; GetSourceLineText
        code := StrGet(pbstrcode, &quot;UTF-16&quot;), DllCall(&quot;OleAut32\SysFreeString&quot;, &quot;ptr&quot;, pbstrcode)
        if fn := NumGet(excp, 6 * A_PtrSize) ; pfnDeferredFillIn
            DllCall(fn, &quot;ptr&quot;, &amp;excp)
        wcode := NumGet(excp, 0, &quot;ushort&quot;)
        hr := wcode ? 0x80040200 + wcode : NumGet(excp, 7 * A_PtrSize, &quot;uint&quot;)
        this.Error := {HRESULT: hr, Line: srcline, Column: srccol, LineText: code}
        static Infos := &quot;Source,Description,HelpFile&quot;
        Loop Parse, % Infos, `,
            if pbstr := NumGet(excp, A_Index * A_PtrSize)
                this.Error[A_LoopField] := StrGet(pbstr, &quot;UTF-16&quot;), DllCall(&quot;OleAut32\SysFreeString&quot;, &quot;ptr&quot;, pbstr)
        return 0x80004001 ; E_NOTIMPL (let Exec/Eval get a fail result)
    }
    
    __Delete()
    {
        if this._script
        {
            DllCall(NumGet(NumGet((p:=this._script)+0)+7*A_PtrSize), &quot;ptr&quot;, p)  ; Close
            ObjRelease(this._script)
        }
        if this._scriptParse
            ObjRelease(this._scriptParse)
    }
    
    static IID := &quot;{BB1A2AE1-A4F9-11cf-8F20-00805F2CD064}&quot;
    static IID_Parse := A_PtrSize=8 ? &quot;{C7EF7658-E1EE-480E-97EA-D52CB4D76D17}&quot; : &quot;{BB1A2AE2-A4F9-11cf-8F20-00805F2CD064}&quot;
}

class ActiveScriptSite
{
    __New(Script)
    {
        ObjSetCapacity(this, &quot;_site&quot;, 3 * A_PtrSize)
        NumPut(&amp;Script
        , NumPut(ActiveScriptSite._vftable(&quot;_vft_w&quot;, &quot;31122&quot;, 0x100)
        , NumPut(ActiveScriptSite._vftable(&quot;_vft&quot;, &quot;31125232211&quot;, 0)
            , this.ptr := ObjGetAddress(this, &quot;_site&quot;))))
    }
    
    _vftable(Name, PrmCounts, EIBase)
    {
        if p := ObjGetAddress(this, Name)
            return p
        ObjSetCapacity(this, Name, StrLen(PrmCounts) * A_PtrSize)
        p := ObjGetAddress(this, Name)
        Loop Parse, % PrmCounts
        {
            cb := RegisterCallback(&quot;_ActiveScriptSite&quot;, &quot;F&quot;, A_LoopField, A_Index + EIBase)
            NumPut(cb, p + (A_Index-1) * A_PtrSize)
        }
        return p
    }
}

_ActiveScriptSite(this, a1:=0, a2:=0, a3:=0, a4:=0, a5:=0)
{
    Method := A_EventInfo &amp; 0xFF
    if A_EventInfo &gt;= 0x100  ; IActiveScriptSiteWindow
    {
        if Method = 4  ; GetWindow
        {
            NumPut(0, a1+0) ; *phwnd := 0
            return 0 ; S_OK
        }
        if Method = 5  ; EnableModeless
        {
            return 0 ; S_OK
        }
        this -= A_PtrSize     ; Cast to IActiveScriptSite
    }
    ;else: IActiveScriptSite
    if Method = 1  ; QueryInterface
    {
        iid := _AS_GUIDToString(a1)
        if (iid = &quot;{00000000-0000-0000-C000-000000000046}&quot;  ; IUnknown
         || iid = &quot;{DB01A1E3-A42B-11cf-8F20-00805F2CD064}&quot;) ; IActiveScriptSite
        {
            NumPut(this, a2+0)
            return 0 ; S_OK
        }
        if (iid = &quot;{D10F6761-83E9-11cf-8F20-00805F2CD064}&quot;) ; IActiveScriptSiteWindow
        {
            NumPut(this + A_PtrSize, a2+0)
            return 0 ; S_OK
        }
        NumPut(0, a2+0)
        return 0x80004002 ; E_NOINTERFACE
    }
    if Method = 5  ; GetItemInfo
    {
        a1 := StrGet(a1, &quot;UTF-16&quot;)
        , (a3 &amp;&amp; NumPut(0, a3+0))  ; *ppiunkItem := NULL
        , (a4 &amp;&amp; NumPut(0, a4+0))  ; *ppti := NULL
        if (a2 &amp; 1) ; SCRIPTINFO_IUNKNOWN
        {
            if !(unk := Object(NumGet(this + A_PtrSize*2))._GetObjectUnk(a1))
                return 0x8002802B ; TYPE_E_ELEMENTNOTFOUND
            ObjAddRef(unk), NumPut(unk, a3+0)
        }
        return 0 ; S_OK
    }
    if Method = 9  ; OnScriptError
        return Object(NumGet(this + A_PtrSize*2))._OnScriptError(a1)
    
    ; AddRef and Release don&#039;t do anything because we want to avoid circular references.
    ; The site and IActiveScript are both released when the AHK script releases its last
    ; reference to the ActiveScript object.
    
    ; All of the other methods don&#039;t require implementations.
    return 0x80004001 ; E_NOTIMPL
}

_AS_GUIDToString(pGUID)
{
    VarSetCapacity(String, 38*2)
    DllCall(&quot;ole32\StringFromGUID2&quot;, &quot;ptr&quot;, pGUID, &quot;str&quot;, String, &quot;int&quot;, 39)
    return String
}  
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (serzh82saratov)]]></author>
			<pubDate>Sat, 23 Sep 2017 11:04:47 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119516#p119516</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119512#p119512</link>
			<description><![CDATA[<p>Смотря что называть обыкновенным кодом.<br /></p><div class="codebox"><pre><code>a := 3
b := 7
str:=&quot;x:=a*b*2-5&quot;


;
; Здесь каким-то чудом делим передыдущую строку кода на две части.
  var := &quot;x&quot;
  cod := a*b*2-5
;
;

%var% := cod

MsgBox, %x%</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (ypppu)]]></author>
			<pubDate>Sat, 23 Sep 2017 07:17:32 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119512#p119512</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119506#p119506</link>
			<description><![CDATA[<p>Можно с помощью ActiveScript:<br /><a href="http://forum.script-coding.com/viewtopic.php?pid=103274#p103274">http://forum.script-coding.com/viewtopi … 74#p103274</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 22 Sep 2017 23:32:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119506#p119506</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119504#p119504</link>
			<description><![CDATA[<p>Непосредственно такое возможно в AHK_H.<br />В основной версии нет eval, только через создание файла или в pipe канале.</p>]]></description>
			<author><![CDATA[null@example.com (stealzy)]]></author>
			<pubDate>Fri, 22 Sep 2017 19:04:50 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119504#p119504</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Выполнение записанных математических операций]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=119502#p119502</link>
			<description><![CDATA[<p>Доброе время суток форумчане!<br />Вот что меня интересует:<br />У меня есть строка с обыкновенным кодом,но она находиться в переменной, например:<br /></p><div class="codebox"><pre><code>str:=&quot;x:=a*b*2-5&quot;</code></pre></div><p>Мне нужно &quot;запустить&quot; эту строку, как если бы это было написано не в переменной.<br /></p><div class="codebox"><pre><code>x:=a*b*2-5</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (shahlik002)]]></author>
			<pubDate>Fri, 22 Sep 2017 18:49:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=119502#p119502</guid>
		</item>
	</channel>
</rss>
