Quantcast
Channel: ClearScript
Viewing all 2297 articles
Browse latest View live

New Post: More Build Issues

$
0
0
Hello reubenbond!

We currently have no plans to release ClearScript in binary form. Please see our comments in this thread.

That said, there's nothing stopping someone else from doing so :-)

Updated Wiki: Home

$
0
0
InfoIcon.jpg5/21/2013: ClearScript 5.3 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.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);
}

New Post: Cross-platform

$
0
0
Thanks both, and also congratulations to jamesnw.
I will give a look to V8.NET asap, it could be what we need.
I looked at VroomJS too, but it does not compile with recent V8 API (3.17), probably it need a bit reworking after last API changes...

Well, thank you and good work to all.

New Post: Cross-platform

$
0
0
VroomJS only seems to compile for mono, and has Linux libraries (links libv8.so). It also doesn't seem to support compiling the V8 source as 64-bit.

New Post: Cross-platform

$
0
0
I did not tried to compile 64 bit version, another problem.
I tried to substitute libvroomjs.cproj project with a libvroomjs.vcxproj using same C++ sources. The .NET project should be linked with v8-xx.dll, but before this I should solve the V8 API change (and some other minor) problem(s).
For the moment I cannot investigate more, perhaps in a next future.

Updated Wiki: Home

$
0
0
InfoIcon.jpg5/21/2013: ClearScript 5.3 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);
}

Created Unassigned: Get an exception on engine.Script.print(DateTime.Now.DayOfWeek); [9]

$
0
0
public class StudentInfo
{
public string Name
{ get; set; }

public int Age
{ get; set; }
}

public static void Main()
{


using (var engine = new JScriptEngine("abcaasfgggg", WindowsScriptEngineFlags.EnableDebugging))
//using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
{

//engine.AddHostObject("host", new ExtendedHostFunctions());
//engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
engine.AllowReflection = true;
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.AddHostType("StudentInfo", typeof(StudentInfo));
engine.Execute(@"Console.WriteLine('{0} is an interesting number.', Math.PI);

var studentInfo = new StudentInfo();
studentInfo.Name=""aaa"";
studentInfo.Age = 546;
function print(x) { Console.WriteLine(x); }

");
// call a script function


var kk1 = engine.Script.studentInfo;
engine.Script.print(DateTime.Now.DayOfWeek);
//Get an exception on here. when change engine to V8 that works.


}
}

Edited Unassigned: Get an exception on engine.Script.print(DateTime.Now.DayOfWeek); [9]

$
0
0
```
public class StudentInfo
{
public string Name
{ get; set; }

public int Age
{ get; set; }
}

public static void Main()
{


using (var engine = new JScriptEngine("abcaasfgggg", WindowsScriptEngineFlags.EnableDebugging))
//using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
{

//engine.AddHostObject("host", new ExtendedHostFunctions());
//engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
engine.AllowReflection = true;
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.AddHostType("StudentInfo", typeof(StudentInfo));
engine.Execute(@"Console.WriteLine('{0} is an interesting number.', Math.PI);

var studentInfo = new StudentInfo();
studentInfo.Name=""aaa"";
studentInfo.Age = 546;
function print(x) { Console.WriteLine(x); }

");
// call a script function


var kk1 = engine.Script.studentInfo;
engine.Script.print(DateTime.Now.DayOfWeek);
//Get an exception on here. when change engine to V8 that works.


}
}
```

Commented Unassigned: Get an exception on engine.Script.print(DateTime.Now.DayOfWeek); [9]

$
0
0
```
public class StudentInfo
{
public string Name
{ get; set; }

public int Age
{ get; set; }
}

public static void Main()
{


using (var engine = new JScriptEngine("abcaasfgggg", WindowsScriptEngineFlags.EnableDebugging))
//using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
{

//engine.AddHostObject("host", new ExtendedHostFunctions());
//engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
engine.AllowReflection = true;
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.AddHostType("StudentInfo", typeof(StudentInfo));
engine.Execute(@"Console.WriteLine('{0} is an interesting number.', Math.PI);

var studentInfo = new StudentInfo();
studentInfo.Name=""aaa"";
studentInfo.Age = 546;
function print(x) { Console.WriteLine(x); }

");
// call a script function


var kk1 = engine.Script.studentInfo;
engine.Script.print(DateTime.Now.DayOfWeek);
//Get an exception on here. when change engine to V8 that works.


}
}
```
Comments: We have reproduced this issue and are investigating the root cause. The trigger appears to be that your program sets up two global properties whose names differ only in case: "StudentInfo" and "studentInfo". You can work around the bug by renaming one of them. This issue appears to be specific to JScriptEngine.

Edited Issue: Get an exception on engine.Script.print(DateTime.Now.DayOfWeek); [9]

$
0
0
```
public class StudentInfo
{
public string Name
{ get; set; }

public int Age
{ get; set; }
}

public static void Main()
{


using (var engine = new JScriptEngine("abcaasfgggg", WindowsScriptEngineFlags.EnableDebugging))
//using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
{

//engine.AddHostObject("host", new ExtendedHostFunctions());
//engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
engine.AllowReflection = true;
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.AddHostType("StudentInfo", typeof(StudentInfo));
engine.Execute(@"Console.WriteLine('{0} is an interesting number.', Math.PI);

var studentInfo = new StudentInfo();
studentInfo.Name=""aaa"";
studentInfo.Age = 546;
function print(x) { Console.WriteLine(x); }

");
// call a script function


var kk1 = engine.Script.studentInfo;
engine.Script.print(DateTime.Now.DayOfWeek);
//Get an exception on here. when change engine to V8 that works.


}
}
```

Released: ClearScript 5.3 (May 21, 2013)

$
0
0
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 Release: ClearScript 5.3 (May 21, 2013)

$
0
0
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: Announcements

$
0
0

5/31/2013: Version 5.3.1 released.

View the release notes and download the source code here.

5/21/2013: ClearScript 5.3 released.

View the release notes and download the source code here.

5/15/2013: Version 5.2.2 released.

View the release notes and download the source code here. This release addresses the build issue reported yesterday and can be used with the latest V8 version. Here's how to update your copy of V8:
C:\ClearScript> set V8REV=
C:\ClearScript> V8Update

5/14/2013: ClearScript build failure due to API deprecation in V8 3.19.1.

We are aware of a ClearScript build issue with the latest version of V8. Until this issue is resolved we recommend that you explicitly use V8 3.19.0:
C:\ClearScript> set V8REV=14604
C:\ClearScript> V8Update

5/2/2013: Version 5.2.1 released.

View the release notes and download the source code here.

4/18/2013: V8Update failure resolved by V8 3.18.1.

The V8Update issue reported yesterday has been fixed by a new version of V8 released today. Here's how to update to the latest V8 version:
C:\ClearScript> set V8REV=
C:\ClearScript> V8Update

4/17/2013: V8Update failure with V8 3.18.0.

We are aware of a V8Update issue with the latest version of V8. Until this issue is resolved we recommend that you explicitly use V8 3.17.16:
C:\ClearScript> set V8REV=14138
C:\ClearScript> V8Update

3/27/2013: ClearScript 5.2 released.

View the release notes and download the source code here.

3/8/2013: Version 5.1.3 released.

View the release notes and download the source code here.

3/4/2013: V8Update failure resolved by V8 3.17.7.

The V8Update issue reported earlier has been fixed by a new version of V8 released today. Here's how to update to the latest V8 version:
C:\ClearScript> set V8REV=
C:\ClearScript> V8Update

3/4/2013: V8Update failure with V8 3.17.6.

We are aware of a V8Update issue with the latest version of V8. The issue affects the "Building 64-bit V8" step. The V8 team appears to have already submitted a fix, but the fix has not yet been merged into the trunk. In the meantime, we recommend that you explicitly use V8 3.17.5:
C:\ClearScript> set V8REV=13745
C:\ClearScript> V8Update

Updated Wiki: Home

$
0
0
InfoIcon.jpg5/31/2013: Version 5.3.1 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);
}

Commented Issue: Get an exception on engine.Script.print(DateTime.Now.DayOfWeek); [9]

$
0
0
```
public class StudentInfo
{
public string Name
{ get; set; }

public int Age
{ get; set; }
}

public static void Main()
{


using (var engine = new JScriptEngine("abcaasfgggg", WindowsScriptEngineFlags.EnableDebugging))
//using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
{

//engine.AddHostObject("host", new ExtendedHostFunctions());
//engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
engine.AllowReflection = true;
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.AddHostType("StudentInfo", typeof(StudentInfo));
engine.Execute(@"Console.WriteLine('{0} is an interesting number.', Math.PI);

var studentInfo = new StudentInfo();
studentInfo.Name=""aaa"";
studentInfo.Age = 546;
function print(x) { Console.WriteLine(x); }

");
// call a script function


var kk1 = engine.Script.studentInfo;
engine.Script.print(DateTime.Now.DayOfWeek);
//Get an exception on here. when change engine to V8 that works.


}
}
```
Comments: Fixed in [Version 5.3.1](https://clearscript.codeplex.com/SourceControl/changeset/db89da65e8bc78cc0a53a4a3035cf9f42350d127).

Edited Issue: Get an exception on engine.Script.print(DateTime.Now.DayOfWeek); [9]

$
0
0
```
public class StudentInfo
{
public string Name
{ get; set; }

public int Age
{ get; set; }
}

public static void Main()
{


using (var engine = new JScriptEngine("abcaasfgggg", WindowsScriptEngineFlags.EnableDebugging))
//using (var engine = new V8ScriptEngine(typeof(ClearScriptConsole).Name, V8ScriptEngineFlags.EnableDebugging))
{

//engine.AddHostObject("host", new ExtendedHostFunctions());
//engine.AddHostObject("lib", HostItemFlags.GlobalMembers, new HostTypeCollection("mscorlib", "System", "System.Core", "ClearScript"));
engine.AllowReflection = true;
// expose a host type
engine.AddHostType("Console", typeof(Console));
engine.AddHostType("StudentInfo", typeof(StudentInfo));
engine.Execute(@"Console.WriteLine('{0} is an interesting number.', Math.PI);

var studentInfo = new StudentInfo();
studentInfo.Name=""aaa"";
studentInfo.Age = 546;
function print(x) { Console.WriteLine(x); }

");
// call a script function


var kk1 = engine.Script.studentInfo;
engine.Script.print(DateTime.Now.DayOfWeek);
//Get an exception on here. when change engine to V8 that works.


}
}
```

Created Unassigned: can this work inside a winRT "metro" C# application? [10]

$
0
0
can this work inside a winRT "metro" C# application?

Commented Unassigned: can this work inside a winRT "metro" C# application? [10]

$
0
0
can this work inside a winRT "metro" C# application?
Comments: Hello! Thanks for your question. Because ClearScript relies on components that use COM registration (JScript/VBScript) and just-in-time compilation (Google V8), it is not compatible with WinRT. A pure .NET interpreter such as [Jint](https://jint.codeplex.com/) might be closer to what you're looking for. By the way, please use the [Discussions](https://clearscript.codeplex.com/discussions) area for asking questions. Thank you!

Edited Unassigned: can this work inside a winRT "metro" C# application? [10]

$
0
0
can this work inside a winRT "metro" C# application?

Closed Unassigned: can this work inside a winRT "metro" C# application? [10]

$
0
0
can this work inside a winRT "metro" C# application?
Viewing all 2297 articles
Browse latest View live




Latest Images