ActiveScript - Host VBScript and JScript in-process

Post your working scripts, libraries and tools for AHK v1.1 and older
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: ActiveScript - Host VBScript and JScript in-process

08 May 2023, 01:52

@malcev, because that's what the JsRT engine returns.

Can you tell me why you would expect an Integer result at any time?
MDN wrote:The Number type is a double-precision 64-bit binary format IEEE 754 value.
I suppose the engine chooses to return numbers as VT_I4 when possible.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ActiveScript - Host VBScript and JScript in-process

08 May 2023, 12:15

Can you tell me why you would expect an Integer result at any time?
I am expecting to get string without zeroes at the end as result.
Interesting, that If We use ChakraCore then We get normal string after calling JsNumberToDouble.
https://github.com/chakra-core/ChakraCore/wiki/JsNumberToDouble
I tested with this autoit wrapper
https://www.autoitscript.com/forum/topic/184824-chakracore-udf-executing-javascript-in-autoit/
lexikos
Posts: 9690
Joined: 30 Sep 2013, 04:07
Contact:

Re: ActiveScript - Host VBScript and JScript in-process

09 May 2023, 01:36

Why would you expect to get a string as result? You evaluated a number, so it returned a number. MsgBox is converting it to a string, not the Javascript engine and not JsRT.ahk. The "zeroes at the end" are just the way that AutoHotkey formats floating-point numbers.

Merely calling someone else's wrapper for a library in another language and printing the result will not conclusively tell you about the library itself, or how it should behave in this language. Is the wrapper returning a floating-point number and the language converting it to a string without decimal point? Or is the wrapper returning a string?

If you use JsNumberToDouble correctly, it will give you a floating-point number. To get a string from that, "normal" or otherwise, you must be do something else separate to JsNumberToDouble itself, like concatenation or a conversion function. Default formatting in AutoHotkey will most definitely give you a decimal point, not a "string without zeroes" unless the number happens to have a non-zero digit after the decimal point.

Operating through COM may also cause some differences in behaviour compared to using more direct APIs like JsNumberToDouble (the Edge version of Chakra has both).
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ActiveScript - Host VBScript and JScript in-process

09 May 2023, 09:53

Yes, Thank You!
You absolutely right - on ahk it shows string with zeroes:

Code: Select all

sScript = eval("2147483648");
DllCall("LoadLibrary", "str", "ChakraCore.dll", "ptr")
DllCall("ChakraCore.dll\JsCreateRuntime", "uint", 0, "ptr", 0, "ptr*", hRuntime)
DllCall("ChakraCore.dll\JsCreateContext", "ptr", hRuntime, "ptr*", hContext)
DllCall("ChakraCore.dll\JsSetCurrentContext", "ptr", hContext)
DllCall("ChakraCore.dll\JsRunScript", "wstr", sScript, "uint", 0, "wstr", "", "ptr*", hResult)
DllCall("ChakraCore.dll\JsConvertValueToNumber", "ptr", hResult, "ptr*", tResult)
DllCall("ChakraCore.dll\JsNumberToDouble", "ptr", tResult, "double*", hOutput)
DllCall("ChakraCore.dll\JsSetCurrentContext", "ptr", 0)
DllCall("ChakraCore.dll\JsDisposeRuntime", "ptr", hRuntime)
msgbox % hOutput
Dont You think that it is strange and not correct behaviour how autohotkey formats floating-point numbers to string?
I think ahk should show "1" as result, but not "1.000000" or "1.0" (in ahk v2) in the next code

Code: Select all

a := 0.000
a++
msgbox % a
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: ActiveScript - Host VBScript and JScript in-process

09 May 2023, 15:15

Also if We run this on autohotkey v2 We get that "a" is equal not 1.035 but 1.0349999999999999
I think it looks buggy.

Code: Select all

sScript := "(function(){var obj = {a: 1.035};return obj;})();"
DllCall("LoadLibrary", "str", "ChakraCore.dll", "ptr")
DllCall("ChakraCore.dll\JsCreateRuntime", "uint", 0, "ptr", 0, "ptr*", &hRuntime:=0)
DllCall("ChakraCore.dll\JsCreateContext", "ptr", hRuntime, "ptr*", &hContext:=0)
DllCall("ChakraCore.dll\JsSetCurrentContext", "ptr", hContext)
DllCall("ChakraCore.dll\JsRunScript", "wstr", sScript, "uint", 0, "wstr", "", "ptr*", &hOutput:=0)
DllCall("ChakraCore.dll\JsGetPropertyIdFromName", "wstr", "a", "ptr*", &hPropId:=0)
DllCall("ChakraCore.dll\JsGetProperty", "ptr", hOutput, "ptr", hPropId, "ptr*", &hResult:=0)
DllCall("ChakraCore.dll\JsConvertValueToNumber", "ptr", hResult, "ptr*", &tResult:=0)
DllCall("ChakraCore.dll\JsNumberToDouble", "ptr", tResult, "double*", &hOutput:=0)
DllCall("ChakraCore.dll\JsSetCurrentContext", "ptr", 0)
DllCall("ChakraCore.dll\JsDisposeRuntime", "ptr", hRuntime)
msgbox hOutput
The same is

Code: Select all

a:=1.034
a+=0.001
msgbox a
Other languages like python, js, autoit show 1.035 as result.
Kingron
Posts: 9
Joined: 22 May 2023, 19:47

Re: ActiveScript - Host VBScript and JScript in-process

23 May 2023, 08:11

Here is the simple way to run VBScript & JScript:

Code: Select all

vb := ComObjCreate("MSScriptControl.ScriptControl")
vb.Language := "JSCript"
vb.eval("12*2")
gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: ActiveScript - Host VBScript and JScript in-process

23 May 2023, 08:15

Kingron wrote:
23 May 2023, 08:11
Here is the simple way to run VBScript & JScript:

Code: Select all

vb := ComObjCreate("MSScriptControl.ScriptControl")
vb.Language := "JSCript"
vb.eval("12*2")
Sure, but if you look at the first post of this topic, you'll read:
Provides an interface to Active Scripting languages like VBScript and JScript, without relying on Microsoft's ScriptControl, which is not available to 64-bit programs.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 244 guests