We're happy to hear that you've found a solution as we continue to investigate this issue. Thank you also for posting the details of your workaround!
↧
New Post: Build issue on VS 2012 and Windows 7 x64
↧
New Post: got it all compiled, i got it to run BUT
isn't there a way that you do not have to have all the dlls in the same directory as the executable for v8 to run? Could you create a x86 only clearscript.dll with reference to clearscriptv8-32.dll? Would clearscriptv8-32.dll find v8-ia32.dll if it was in the same directory or at least if you have the path in the environment variable path?
I am totally gassed about this project and was real excited when I read it is targeting the 4.0 framework. I got everything to compile using vs10 except for the clearscriptv8-XX.dll because of the atomic stuff you got in there. Is there any way possible to rewrite that part so I can compile it in vs10 express? I did get vs12 installed without any hassle this time but am a little concerned as a commercial developer if I can distribute or not with stuff compiled in vs12. Seems a little absurd with a project with such a liberal license being hampered.
I'LL BE BACK WITH FEEDBACK!!! This project is just so perfect for my needs I couldn't of spec'd it out myself and gotten more on target. I can keep my legacy customers scripting in vbscript and force my new customers to experience turbocharged javascript.
I am totally gassed about this project and was real excited when I read it is targeting the 4.0 framework. I got everything to compile using vs10 except for the clearscriptv8-XX.dll because of the atomic stuff you got in there. Is there any way possible to rewrite that part so I can compile it in vs10 express? I did get vs12 installed without any hassle this time but am a little concerned as a commercial developer if I can distribute or not with stuff compiled in vs12. Seems a little absurd with a project with such a liberal license being hampered.
I'LL BE BACK WITH FEEDBACK!!! This project is just so perfect for my needs I couldn't of spec'd it out myself and gotten more on target. I can keep my legacy customers scripting in vbscript and force my new customers to experience turbocharged javascript.
↧
↧
New Post: An example to share vb6 script control vs clearscript
In my current VB6 app I use scripting to plug in classes that the scripting can maniplate and also call functions within my plugged in classes to effect change and act as events in my main app. This is a bit of test code that shows the same capacity in clearscript.
VB6 EXAMPLE
SIMPLE CLASS VBStest
public A as Long
publc B as Long
Set SC = New ScriptControl
SC.AllowUI = False
SC.Language = "VBScript"
SC.Reset
Set TEST1 = New VBStest
TEST1.A = 1000
TEST1.B = 2000
SC.AddObject "TEST1", TEST1, True
newCode = "Public Sub addtoTEST1A(inval)" & _
T1 = new VBStest;
T1.A = 3000
T1.B = 4000
TEST1 = T1;
SC.RUN "addtoTEST1A(" & 5000 & ")"
' TEST1.A is now 8000
VB6 EXAMPLE
SIMPLE CLASS VBStest
public A as Long
publc B as Long
Set SC = New ScriptControl
SC.AllowUI = False
SC.Language = "VBScript"
SC.Reset
Set TEST1 = New VBStest
TEST1.A = 1000
TEST1.B = 2000
SC.AddObject "TEST1", TEST1, True
newCode = "Public Sub addtoTEST1A(inval)" & _
" TEST1.A = TEST1.A + inval" & _
"End Sub"
SC.AddCode newCodeT1 = new VBStest;
T1.A = 3000
T1.B = 4000
TEST1 = T1;
SC.RUN "addtoTEST1A(" & 5000 & ")"
' TEST1.A is now 8000
CLEARSCRIPT
public class V8test
{
public int A = 0;
public int B = 0;
}
public void testV8()
{
V8ScriptEngine V8JS = new V8ScriptEngine();
string newCode = @" var TEST1;
function setTEST1(inval)
{
TEST1 = inval;
}
function addtoTEST1A(inval)
{
TEST1.A += inval;
}
"; V8JS.Execute(newCode);
V8test T1 = new V8test();
T1.A = 3000;
T1.B = 4000;
// V8JS.Script.TEST1 = T1; did not work at setting to new object
V8JS.Script.setTEST1(T1);
V8JS.Script.TEST1.A += 5000;
// T1.A and V8JS.Script.TEST1.A are same object, value 8000
V8test T2 = new V8test();
T2.A = 1000;
T2.B = 2000;
V8JS.Script.setTEST1(T2);
V8JS.Script.addtoTEST1A(3000);
// T2.A and V8JS.Script.TEST1.A are same object, value 4000
}
↧
New Post: An example to share vb6 script control vs clearscript
Thanks for sharing this sample, notahack! We're concerned about the comment indicating that the
Script
property did not allow you to assign a global property. We're going to see if we can reproduce that.↧
New Post: An example to share vb6 script control vs clearscript
It sure would be easier and more elegant if assigning a new object to a variable as as easy as V8JS.Script.TEST1 = T1;
This also works to assign a new object to a variable but it didn't 'look' right.
T1 = new V8test();
V8JS.AddHostObject("TEST1", T1);
T2 = new V8test();
V8JS.AddHostObject("TEST1", T2);
This also works to assign a new object to a variable but it didn't 'look' right.
T1 = new V8test();
V8JS.AddHostObject("TEST1", T1);
T2 = new V8test();
V8JS.AddHostObject("TEST1", T2);
↧
↧
New Post: An example to share vb6 script control vs clearscript
It sure would be easier and more elegant if assigning a new object to a variable as as easy as V8JS.Script.TEST1 = T1;ClearScript's test code uses this kind of assignment in many places; see the
V8ScriptEngine_Script_Property
test for an example. We've just tested it with your V8test
class and setup code exactly as above and could not reproduce any issue. Does it still fail for you? If so, what are you seeing? Is there an exception?↧
New Post: got it all compiled, i got it to run BUT
Hello notahack!
We'll try to answer your questions one by one.
isn't there a way that you do not have to have all the dlls in the same directory as the executable for v8 to run?
Currently ClearScript attempts to load auxiliary V8 DLLs from the following directories:
Could you create a x86 only clearscript.dll with reference to clearscriptv8-32.dll?
Not without a lot of refactoring. Currently ClearScriptV8-xx.dll depends on ClearScript.dll, not the other way around. This is despite the fact that the latter loads the former. It's similar to a service provider architecture or extension mechanism.
That said, why would you want to do that? If you're trying to minimize DLL count in a 32-bit ClearScript/V8 application, you can simply exclude the 64-bit DLLs.
Would clearscriptv8-32.dll find v8-ia32.dll if it was in the same directory or at least if you have the path in the environment variable path?
Yes, that's how it works today.
I got everything to compile using vs10 except for the clearscriptv8-XX.dll because of the atomic stuff you got in there. Is there any way possible to rewrite that part so I can compile it in vs10 express?
Yes, it would be possible. ClearScriptV8 uses only a handful of the C++11 features that VS2012 implements. Things like atomics and mutexes could be replaced with native Win32 facilities. Our goal however is to use standard C++ features wherever possible in order to gradually enhance ClearScript's portability.
I did get vs12 installed without any hassle this time but am a little concerned as a commercial developer if I can distribute or not with stuff compiled in vs12. Seems a little absurd with a project with such a liberal license being hampered.
Hampered how? As far as we can tell, VS2010 and VS2012 can both be used for commercial development, and both provide redistributable C++ libraries. Why are you more concerned about using VS2012 than VS2010?
Cheers!
We'll try to answer your questions one by one.
isn't there a way that you do not have to have all the dlls in the same directory as the executable for v8 to run?
Currently ClearScript attempts to load auxiliary V8 DLLs from the following directories:
- The directory from which ClearScript.dll was loaded.
- AppDomain.CurrentDomain.BaseDirectory.
- The directories specified by AppDomain.CurrentDomain.RelativeSearchPath.
-
The directories specified by the PATH environment variable (v8-ia32.dll and v8-x64.dll only).
Could you create a x86 only clearscript.dll with reference to clearscriptv8-32.dll?
Not without a lot of refactoring. Currently ClearScriptV8-xx.dll depends on ClearScript.dll, not the other way around. This is despite the fact that the latter loads the former. It's similar to a service provider architecture or extension mechanism.
That said, why would you want to do that? If you're trying to minimize DLL count in a 32-bit ClearScript/V8 application, you can simply exclude the 64-bit DLLs.
Would clearscriptv8-32.dll find v8-ia32.dll if it was in the same directory or at least if you have the path in the environment variable path?
Yes, that's how it works today.
I got everything to compile using vs10 except for the clearscriptv8-XX.dll because of the atomic stuff you got in there. Is there any way possible to rewrite that part so I can compile it in vs10 express?
Yes, it would be possible. ClearScriptV8 uses only a handful of the C++11 features that VS2012 implements. Things like atomics and mutexes could be replaced with native Win32 facilities. Our goal however is to use standard C++ features wherever possible in order to gradually enhance ClearScript's portability.
I did get vs12 installed without any hassle this time but am a little concerned as a commercial developer if I can distribute or not with stuff compiled in vs12. Seems a little absurd with a project with such a liberal license being hampered.
Hampered how? As far as we can tell, VS2010 and VS2012 can both be used for commercial development, and both provide redistributable C++ libraries. Why are you more concerned about using VS2012 than VS2010?
Cheers!
↧
New Post: An example to share vb6 script control vs clearscript
nope assigning an object to a createdobject or assigning a new object to the object passed in does not work for me.
V8ScriptEngine V8JS = new V8ScriptEngine("FRED");
string newCode = @"
var TEST1;
function setTEST1(inval)
{
TEST1 = inval;
}
function addtoTEST1A(inval)
{
TEST1.A += inval;
}
"; V8JS.Execute(newCode);
V8test T1 = new V8test();
T1.A = 3000;
T1.B = 4000;
V8JS.AddHostObject("TEST1", T1);
V8JS.Script.TEST1.A += 5000;
// T1.A and V8JS.Script.TEST1.A are same object, value 8000
V8test T2 = new V8test();
T2.A = 1000;
T2.B = 2000;
// does not work
V8JS.Script.TEST1 = T2;
// does not work either
T1 = T2;
V8JS.Script.addtoTEST1A(2000);
// V8JS.Script.TEST1.A = 10000
// T1.A = 10000
// T2.A = 1000
// ergo V8JS.Script.TEST1 = T2 does not work
int a = 0;
}
public class V8test
{
public int A = 0;
public int B = 0;
}
↧
New Post: got it all compiled, i got it to run BUT
You are a pretty good guy. If anybody bad mouths you send them to me, I'll set em straight.
I worked pretty much all day in integrating this into my project. When I installed 2012 express there was a message that said it was for evaluation only and there was a prompt if it was going to be used for commercial purposes. 2010 express did not have any of those chillers in it's license.
Currently ClearScript attempts to load auxiliary V8 DLLs from the following directories:
I have a console project that I browse to the directory and add a reference to clearscript.dll.
The console program will not run unless all the clearscript dlls are in its bin/release directory.
That is why I thought all the clearscript dlls have to be in the same directory as the executable.
Another problem I am having is I put strong keys in all my dlls and while I can put one in clearscript.dll without any problem, I don't know how to put one in the clearscriptV8 c++ dlls. I assume the compiled v8 dlls don't matter as far as strong keys.
I worked pretty much all day in integrating this into my project. When I installed 2012 express there was a message that said it was for evaluation only and there was a prompt if it was going to be used for commercial purposes. 2010 express did not have any of those chillers in it's license.
Currently ClearScript attempts to load auxiliary V8 DLLs from the following directories:
The directory from which ClearScript.dll was loaded.
(doesn't seem to work in my case. This would be ideal. Actually it has to be this way since exes and processes that will consume the scripting dlls will not be in the same directory )AppDomain.CurrentDomain.BaseDirectory.
The directories specified by AppDomain.CurrentDomain.RelativeSearchPath.
The directories specified by the PATH environment variable (v8-ia32.dll and v8-x64.dll only).
Currently I have a directory I put all my application dlls in. I also have this directory in my path variable. All the necessary clearscript dlls are there.I have a console project that I browse to the directory and add a reference to clearscript.dll.
The console program will not run unless all the clearscript dlls are in its bin/release directory.
That is why I thought all the clearscript dlls have to be in the same directory as the executable.
Another problem I am having is I put strong keys in all my dlls and while I can put one in clearscript.dll without any problem, I don't know how to put one in the clearscriptV8 c++ dlls. I assume the compiled v8 dlls don't matter as far as strong keys.
↧
↧
New Post: got it all compiled, i got it to run BUT
I am in a state of bliss because I got clearscript to work in my project.
My final hurdle was since my dll that would reference clearscript.dll was strong keyed clearscript.dll, clearscriptv8-32.dll,clearscriptv8-64.dll had to have strong keys as well. Maybe this is old hat to everyone but I like sharing what I have learned.
I started Windows SDK 7.1 command prompt
sn -k mystrongname.snk
sn -p mystrongname.snk mystrongnamepublic.txt
sn -tp mystrongnamepublic.snk > mystrongnamepublic.txt
the contents of mystrongnamepublic.txt is thus
Microsoft (R) .NET Framework Strong Name Utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Public key is
0024000004800000940000000602000000240000525341310004000001000100816740d2ecda21
4ef0568d2a000642792de393b2d94e5380dbbaea167ab0672352838a51b28b3dffe148d500201b
bf7e134d422849bec7f658906a82934cdc6954253ba406696623a52d16552c9efad560566e4bd3
489ed85ef0f824fa66130b2c348aaf04d4626b4161bff82074d4ec353a4c27509f6947351817f3
85c4fb9e
Public key token is e4292199104c45ec
next I took the 5 public key string lines and made it into 1 string
start the clearscript c# project
go to properties, signing
check Sign the assembly
click the drop down, select browse, select mystrongname.snk
save the project
in explorer goto the Clearscript\Properties folder.
open AssemblyInfo.tt in notepad.
change all InternalsVisibleTo lines by pasting in ,PublicKey= and your key string.
[assembly: InternalsVisibleTo("ClearScriptV8-32,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b3dd479cfbede9face9ce4e1d294cb3b234c9ae9d912301bb44f3089289cc42b13f3e67f7dfd99be9eb716cb4db5b4ebc9bed2047ddca8d53b81cda35edc67b2c79f51107a516d32b7dbd02dba767a1574c36e1deb9b63adec681f7bdb74f46344933e75198df2b0df8d4a589700fb2b9bfb8162a3613dd5c43c5dc88a56cda0")]
do the same to AssemblyInfo.cs
ONTO THE ClearscriptV8 C++ DLL!!!
I am just going to example the 32 project but do it to the 64 the same way.
copy mystrongname.snk into clearscript\v8\clearscriptv8\32 folder
start the project
access the property page
select configuration properties\linker\advanced
select the dropdown for key file, browse and select mystrongname.snk
compile the c++ project
open the c# project and compile.
VOILA!!! pure happiness once again.
Sir Clearscript I now understand where my assembly location problems arised. VS has a habit of copying assemblies a project exe references to the project's bin directory instead of leaving them where they were. Once I had all the support dlls in that same directory all was gold. When I added a reference to clearscript.dll in my dll it ran fine as long as all the support dlls were in the directory clearscript.dll was in. So that is good, exactly as expected and needed.
My final hurdle was since my dll that would reference clearscript.dll was strong keyed clearscript.dll, clearscriptv8-32.dll,clearscriptv8-64.dll had to have strong keys as well. Maybe this is old hat to everyone but I like sharing what I have learned.
I started Windows SDK 7.1 command prompt
sn -k mystrongname.snk
sn -p mystrongname.snk mystrongnamepublic.txt
sn -tp mystrongnamepublic.snk > mystrongnamepublic.txt
the contents of mystrongnamepublic.txt is thus
Microsoft (R) .NET Framework Strong Name Utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Public key is
0024000004800000940000000602000000240000525341310004000001000100816740d2ecda21
4ef0568d2a000642792de393b2d94e5380dbbaea167ab0672352838a51b28b3dffe148d500201b
bf7e134d422849bec7f658906a82934cdc6954253ba406696623a52d16552c9efad560566e4bd3
489ed85ef0f824fa66130b2c348aaf04d4626b4161bff82074d4ec353a4c27509f6947351817f3
85c4fb9e
Public key token is e4292199104c45ec
next I took the 5 public key string lines and made it into 1 string
start the clearscript c# project
go to properties, signing
check Sign the assembly
click the drop down, select browse, select mystrongname.snk
save the project
in explorer goto the Clearscript\Properties folder.
open AssemblyInfo.tt in notepad.
change all InternalsVisibleTo lines by pasting in ,PublicKey= and your key string.
[assembly: InternalsVisibleTo("ClearScriptV8-32,PublicKey=0024000004800000940000000602000000240000525341310004000001000100b3dd479cfbede9face9ce4e1d294cb3b234c9ae9d912301bb44f3089289cc42b13f3e67f7dfd99be9eb716cb4db5b4ebc9bed2047ddca8d53b81cda35edc67b2c79f51107a516d32b7dbd02dba767a1574c36e1deb9b63adec681f7bdb74f46344933e75198df2b0df8d4a589700fb2b9bfb8162a3613dd5c43c5dc88a56cda0")]
do the same to AssemblyInfo.cs
ONTO THE ClearscriptV8 C++ DLL!!!
I am just going to example the 32 project but do it to the 64 the same way.
copy mystrongname.snk into clearscript\v8\clearscriptv8\32 folder
start the project
access the property page
select configuration properties\linker\advanced
select the dropdown for key file, browse and select mystrongname.snk
compile the c++ project
open the c# project and compile.
VOILA!!! pure happiness once again.
Sir Clearscript I now understand where my assembly location problems arised. VS has a habit of copying assemblies a project exe references to the project's bin directory instead of leaving them where they were. Once I had all the support dlls in that same directory all was gold. When I added a reference to clearscript.dll in my dll it ran fine as long as all the support dlls were in the directory clearscript.dll was in. So that is good, exactly as expected and needed.
↧
New Post: An example to share vb6 script control vs clearscript
The code above initially calls
On the other hand, properties created via
AddHostObject()
to create the "TEST1" global property. What you may not realize - most likely because of insufficient documentation on our part - is that AddHostobject()
creates a read-only global property. Subsequent reassignment is quietly ignored. This is by design - to prevent script code from clobbering the host's API, and to achieve compatibility with ClearScript's original JScript/VBScript behavior.On the other hand, properties created via
Script
can be reassigned normally. Instead of:V8JS.AddHostObject("TEST1", T1);
please try:V8JS.Script.TEST1 = T1;
Cheers!↧
Created Issue: V8Update fails on PCs with Traditional Chinese system locale [13]
The V8 build fails apparently because some V8 source files cannot be converted to the Traditional Chinese ANSI code page.
↧
New Post: An example to share vb6 script control vs clearscript
SHAZAM!! A little knowledge goes a long way.
I love this project and intend to wring this code out. In my production software I use scripting to process 1000s of documents a day and affect workflow decisions throughout the application.
I love this project and intend to wring this code out. In my production software I use scripting to process 1000s of documents a day and affect workflow decisions throughout the application.
↧
↧
New Post: Error Handling and Error Info?
I saw Issue 12 and that you added error handling and information but I can not see how that info is available through any of the c# objects exposed.
In the vb6 script control there is an error property with these properties.
Clear (a method)
Column
Description
HelpContext
HelpFile
Line
Number
Source
Text
If the VB Script Control fails to execute code it doesn't throw an exception or misbehave. I do check the Error.Number afterwards and if in a test mode display the code with a pointer to the line and column to the end user. I assume (we all know what happens to me when I do that) that Clearscript basically calls the same COM code for the windows engine that the VB6 control does it would be easy to implement the error property?
V8 seems to expose pretty much the same error info.
http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
Overall if I had error info I would be set. Your team has gone to stellar level to make it easy to use and carefree. Thank you.
What would be nice is the mother of all usage examples heavily commented. Interested in how to use the new initiation and memory management settings too.
edit : Nosing around I found the ClearScript.ScriptEngineException object. Will experiment to see what that is all about.
In the vb6 script control there is an error property with these properties.
Clear (a method)
Column
Description
HelpContext
HelpFile
Line
Number
Source
Text
If the VB Script Control fails to execute code it doesn't throw an exception or misbehave. I do check the Error.Number afterwards and if in a test mode display the code with a pointer to the line and column to the end user. I assume (we all know what happens to me when I do that) that Clearscript basically calls the same COM code for the windows engine that the VB6 control does it would be easy to implement the error property?
V8 seems to expose pretty much the same error info.
http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
Overall if I had error info I would be set. Your team has gone to stellar level to make it easy to use and carefree. Thank you.
What would be nice is the mother of all usage examples heavily commented. Interested in how to use the new initiation and memory management settings too.
edit : Nosing around I found the ClearScript.ScriptEngineException object. Will experiment to see what that is all about.
↧
New Post: got it all compiled, i got it to run BUT
When I installed 2012 express there was a message that said it was for evaluation only and there was a prompt if it was going to be used for commercial purposes. 2010 express did not have any of those chillers in it's license.
Visual Studio 2012 Express can be evaluated for up to 30 days, but you can get a free perpetual license by registering it. See the download page.
As for commercial development, the Visual Studio 2012 and MSDN Licensing Whitepaper contains the following (with our emphasis):
Visual Studio Express 2012 Products
A number of free development tools are also available, including Visual Studio Express 2012 for Windows 8, Visual Studio Express 2012 for Web, Visual Studio Express 2012 for Windows Desktop, and Visual Studio Express 2012 for Windows Phone 8. These tools provide a subset of the functionality available in Visual Studio Professional 2012 and are specific to writing applications targeting these platforms. Each of these Visual Studio Express 2012 products is licensed per user and subject to the use terms included with the product. Visual Studio Express can be used to build production applications.
Also check out the product-specific EULA that's displayed at installation time.
By the way, we're glad you found solutions to the issues you were having, and we'd like to thank you very much for sharing the details!
↧
New Post: Error Handling and Error Info?
Sounds like you've already found it.
ScriptEngineException.ErrorDetails
contains engine-specific error properties such as source location, script stack trace, etc. ClearScript currently exposes this information as a single formatted string because the underlying script engines are not consistent in terms of what information they make available in various error scenarios. Please let us know if your application requires access to individual error properties.↧
Updated Release: ClearScript 5.3 (May 21, 2013)
5.3.5
5.3.4
5.3.3
5.3.2
5.3.1
5.3.0
- Fixed invocation of base interface methods on derived interface targets (Issue #14).
- Fixed V8 and ClearScript builds on certain non-English locales (Issue #13).
- Added boxed enum reference canonicalization (Issue #15).
- PropertyBag enhancements.
- Lots of minor host integration fixes.
- Updates for breaking V8 API changes.
- Several new tests.
- Tested with V8 3.20.12.
5.3.4
- Fixed script interruption crash in V8ScriptEngine.
- Added a test for the fix.
5.3.3
- Improved V8 error handling (Issue #12).
- Lowered .NET Framework target to v4.0.
- Added several tests.
- Tested with V8 3.19.18.
5.3.2
- Updates for breaking V8 API changes.
- V8Update now fetches a tested revision by default.
- Tested with V8 3.19.9.
5.3.1
- Fixed JScriptEngine dynamic binding bug (Issue #9).
5.3.0
- Enhancements for V8 users:
- V8ScriptEngine now supports script compilation and re-execution.
- New V8Runtime class allows engines to share resources and compiled scripts.
- New experimental APIs for restricting and querying V8 memory usage.
- Improved V8 loading algorithm for simplified deployment.
- V8Update can now fetch a V8 version that is known to work with ClearScript.
- New method: ScriptEngine.CollectGarbage().
- Host item caching improves performance and reduces memory usage.
- Several new tests.
↧
↧
Updated Wiki: Home
8/2/2013: Version 5.3.5 released. More...
Description
ClearScript is a library that makes it easy to add scripting to your .NET applications. It currently supports JavaScript (via V8 and JScript) and VBScript.Features
- Simple usage; create a script engine, add your objects and/or types, run scripts
- Support for several script engines: Google's V8, Microsoft's JScript and VBScript
- Exposed resources require no modification, decoration, or special coding of any kind
- Scripts get simple access to most of the features of exposed objects and types:
- Methods, properties, fields, events
- (Objects) Indexers, extension methods, conversion operators, explicitly implemented interfaces
- (Types) Constructors, nested types
- Full support for generic types and methods, including C#-like type inference and explicit type arguments
- Scripts can invoke methods with output parameters, optional parameters, and parameter arrays
- Script delegates enable callbacks into script code
- Support for exposing all the types defined in one or more assemblies in one step
- Optional support for importing types and assemblies from script code
- The host can invoke script functions and access script objects directly
- Full support for script debugging
Examples
using System; using Microsoft.ClearScript; using Microsoft.ClearScript.V8; // create a script engineusing (var engine = new V8ScriptEngine()) { // expose a host type engine.AddHostType("Console", typeof(Console)); engine.Execute("Console.WriteLine('{0} is an interesting number.', Math.PI)"); // expose a host object engine.AddHostObject("random", new Random()); engine.Execute("Console.WriteLine(random.NextDouble())"); // expose entire assemblies engine.AddHostObject("lib", new HostTypeCollection("mscorlib", "System.Core")); engine.Execute("Console.WriteLine(lib.System.DateTime.Now)"); // create a host object from script engine.Execute(@" birthday = new lib.System.DateTime(2007, 5, 22); Console.WriteLine(birthday.ToLongDateString()); "); // use a generic class from script engine.Execute(@" Dictionary = lib.System.Collections.Generic.Dictionary; dict = new (Dictionary(lib.System.String, lib.System.Int32))(); dict.Add('foo', 123); "); // call a host method with an output parameter engine.AddHostObject("host", new HostFunctions()); engine.Execute(@" intVar = host.newVar(lib.System.Int32); found = dict.TryGetValue('foo', intVar.out); Console.WriteLine('{0} {1}', found, intVar); "); // create and populate a host array engine.Execute(@" numbers = host.newArr(lib.System.Int32, 20); for (var i = 0; i < numbers.Length; i++) { numbers[i] = i; } Console.WriteLine(lib.System.String.Join(', ', numbers)); "); // create a script delegate engine.Execute(@" Filter = lib.System.Func(lib.System.Int32, lib.System.Boolean); oddFilter = new Filter(function(value) { return (value & 1) ? true : false; }); "); // use LINQ from script engine.Execute(@" oddNumbers = numbers.Where(oddFilter); Console.WriteLine(lib.System.String.Join(', ', oddNumbers)); "); // call a script function engine.Execute("function print(x) { Console.WriteLine(x); }"); engine.Script.print(DateTime.Now.DayOfWeek); // examine a script object engine.Execute("person = { name: 'Fred', age: 5 }"); Console.WriteLine(engine.Script.person.name); }
↧
Edited Feature: .NET enum members do not support script-native equality comparison [15]
.NET enum members cannot be compared natively in script code; `Object.Equals()` must be used instead. Strictly speaking, this isn't a bug; script-native equality comparison is effectively comparison by (boxed) reference. However, it just doesn't seem right that `(DayOfWeek.Monday == DayOfWeek.Monday)` evaluates to `false`. In addition, without script-native comparison support, .NET enum members cannot be used in script `switch` statements, and that's worth fixing.
↧
Commented Feature: .NET enum members do not support script-native equality comparison [15]
.NET enum members cannot be compared natively in script code; `Object.Equals()` must be used instead. Strictly speaking, this isn't a bug; script-native equality comparison is effectively comparison by (boxed) reference. However, it just doesn't seem right that `(DayOfWeek.Monday == DayOfWeek.Monday)` evaluates to `false`. In addition, without script-native comparison support, .NET enum members cannot be used in script `switch` statements, and that's worth fixing.
Comments: Fixed in [Version 5.3.5](https://clearscript.codeplex.com/SourceControl/changeset/f961ab5a428cd1b6ffa92c9c4c7c35a9f3322a2c).
Comments: Fixed in [Version 5.3.5](https://clearscript.codeplex.com/SourceControl/changeset/f961ab5a428cd1b6ffa92c9c4c7c35a9f3322a2c).
↧